mirror of https://github.com/arendst/Tasmota.git
Fix HASS button discovery
This commit is contained in:
parent
74f1ad8a1b
commit
0006d44e63
|
@ -424,6 +424,7 @@ bool SendKey(uint32_t key, uint32_t device, uint32_t state)
|
|||
char scommand[CMDSZ];
|
||||
char key_topic[TOPSZ];
|
||||
bool result = false;
|
||||
uint32_t device_save = device;
|
||||
|
||||
char *tmp = (key) ? SettingsText(SET_MQTT_SWITCH_TOPIC) : SettingsText(SET_MQTT_BUTTON_TOPIC);
|
||||
Format(key_topic, tmp, sizeof(key_topic));
|
||||
|
@ -459,7 +460,7 @@ bool SendKey(uint32_t key, uint32_t device, uint32_t state)
|
|||
result = XdrvRulesProcess();
|
||||
}
|
||||
int32_t payload_save = XdrvMailbox.payload;
|
||||
XdrvMailbox.payload = key << 16 | state << 8 | device;
|
||||
XdrvMailbox.payload = device_save << 24 | key << 16 | state << 8 | device;
|
||||
XdrvCall(FUNC_ANY_KEY);
|
||||
XdrvMailbox.payload = payload_save;
|
||||
return result;
|
||||
|
@ -922,6 +923,7 @@ void Every250mSeconds(void)
|
|||
// Replace tasmota.bin.gz with tasmota-minimal.bin.gz
|
||||
// Replace tasmota.xyz.gz with tasmota-minimal.xyz.gz
|
||||
// Replace tasmota.ino.bin with tasmota-minimal.ino.bin
|
||||
// Replace tasmota.ino.bin.gz with tasmota-minimal.ino.bin.gz
|
||||
// Replace http://domus1:80/api/arduino/tasmota.bin with http://domus1:80/api/arduino/tasmota-minimal.bin
|
||||
// Replace http://domus1:80/api/arduino/tasmota.bin.gz with http://domus1:80/api/arduino/tasmota-minimal.bin.gz
|
||||
// Replace http://domus1:80/api/arduino/tasmota-DE.bin.gz with http://domus1:80/api/arduino/tasmota-minimal.bin.gz
|
||||
|
@ -941,7 +943,7 @@ void Every250mSeconds(void)
|
|||
}
|
||||
*/
|
||||
char *ech = strchr(bch, '.'); // Find file type in filename (none, .ino.bin, .ino.bin.gz, .bin, .bin.gz or .gz)
|
||||
if (ech == nullptr) { ech = mqtt_data + strlen(mqtt_data); }
|
||||
if (ech == nullptr) { ech = mqtt_data + strlen(mqtt_data); } // Point to '/0' at end of mqtt_data becoming an empty string
|
||||
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("OTA: File type [%s]"), ech);
|
||||
|
||||
|
|
|
@ -712,6 +712,13 @@ void MqttCheck(void)
|
|||
}
|
||||
}
|
||||
|
||||
bool ButtonTopicActive(void)
|
||||
{
|
||||
char key_topic[TOPSZ];
|
||||
Format(key_topic, SettingsText(SET_MQTT_BUTTON_TOPIC), sizeof(key_topic));
|
||||
return ((strlen(key_topic) != 0) && strcmp(key_topic, "0"));
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Commands
|
||||
\*********************************************************************************************/
|
||||
|
|
|
@ -53,9 +53,9 @@ const char HASS_DISCOVER_BASE[] PROGMEM =
|
|||
"\"pl_not_avail\":\"" D_OFFLINE "\""; // Offline
|
||||
|
||||
const char HASS_DISCOVER_RELAY[] PROGMEM =
|
||||
",\"cmd_t\":\"%s\"," // cmnd/dualr2/POWER2
|
||||
"\"val_tpl\":\"{{value_json.%s}}\"," // POWER2
|
||||
"\"pl_off\":\"%s\"," // OFF
|
||||
",\"cmd_t\":\"%s\"," // cmnd/dualr2/POWER2
|
||||
"\"val_tpl\":\"{{value_json.%s}}\"," // POWER2
|
||||
"\"pl_off\":\"%s\"," // OFF
|
||||
"\"pl_on\":\"%s\""; // ON
|
||||
|
||||
const char HASS_DISCOVER_BUTTON_TOGGLE[] PROGMEM =
|
||||
|
@ -368,7 +368,7 @@ void HAssAnnounceSensor(const char *sensorname, const char *subsensortype, const
|
|||
char unique_id[30];
|
||||
|
||||
mqtt_data[0] = '\0'; // Clear retained message
|
||||
// Clear or Set topic
|
||||
// Clear or Set topic
|
||||
char subname[20];
|
||||
NoAlNumToUnderscore(subname, MultiSubName); //Replace all non alphaumeric characters to '_' to avoid topic name issues
|
||||
snprintf_P(unique_id, sizeof(unique_id), PSTR("%06X_%s_%s"), ESP.getChipId(), sensorname, subname);
|
||||
|
@ -504,7 +504,7 @@ void HAssAnnounceStatusSensor(void)
|
|||
TryResponseAppend_P(HASS_DISCOVER_SENSOR_HASS_STATUS, state_topic);
|
||||
TryResponseAppend_P(HASS_DISCOVER_DEVICE_INFO, unique_id, ESP.getChipId(), WiFi.macAddress().c_str(),
|
||||
SettingsText(SET_FRIENDLYNAME1), ModuleName().c_str(), my_version, my_image);
|
||||
|
||||
|
||||
TryResponseAppend_P(PSTR("}"));
|
||||
}
|
||||
MqttPublish(stopic, true);
|
||||
|
@ -568,9 +568,13 @@ void HAssAnyKey(void)
|
|||
return;
|
||||
} // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
|
||||
|
||||
uint32_t key = (XdrvMailbox.payload >> 16) & 0xFF;
|
||||
uint32_t device = XdrvMailbox.payload & 0xFF;
|
||||
uint32_t state = (XdrvMailbox.payload >> 8) & 0xFF;
|
||||
uint32_t key = (XdrvMailbox.payload >> 16) & 0xFF; // 0 = Button, 1 = Switch
|
||||
uint32_t device = XdrvMailbox.payload & 0xFF; // Device number or 1 if more Buttons than Devices
|
||||
uint32_t state = (XdrvMailbox.payload >> 8) & 0xFF; // 0 = Off, 1 = On, 2 = Toggle
|
||||
|
||||
if (!key && ButtonTopicActive()) { // Button and ButtonTopic is active
|
||||
device = (XdrvMailbox.payload >> 24) & 0xFF; // Button number
|
||||
}
|
||||
|
||||
char scommand[CMDSZ];
|
||||
snprintf_P(scommand, sizeof(scommand), PSTR("%s%d"), (key) ? "SWITCH" : "BUTTON", device);
|
||||
|
|
Loading…
Reference in New Issue