From eda60b61244cbc9e068bd22be3278f1ca0dc84cb Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 25 Nov 2018 21:27:19 +0100 Subject: [PATCH] Support sending tele/STATUS as state/RESULT --- sonoff/settings.h | 2 +- sonoff/sonoff.ino | 6 +++++- sonoff/xdrv_12_home_assistant.ino | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sonoff/settings.h b/sonoff/settings.h index 553f9eba3..39642e4a9 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -72,7 +72,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t use_wifi_scan : 1; // bit 6 (v6.3.0.10) uint32_t use_wifi_rescan : 1; // bit 7 (v6.3.0.10) uint32_t receive_raw : 1; // bit 8 (v6.3.0.11) - uint32_t spare09 : 1; + uint32_t hass_tele_as_result : 1; // bit 9 uint32_t spare10 : 1; uint32_t spare11 : 1; uint32_t spare12 : 1; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index c86c91d59..f0439f0a2 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1681,7 +1681,11 @@ void PerformEverySecond(void) mqtt_data[0] = '\0'; MqttShowState(); - MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN); + if (Settings.flag3.hass_tele_as_result) { + MqttPublishPrefixTopic_P(STAT, S_RSLT_RESULT, MQTT_TELE_RETAIN); + } else { + MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN); + } mqtt_data[0] = '\0'; if (MqttShowSensor()) { diff --git a/sonoff/xdrv_12_home_assistant.ino b/sonoff/xdrv_12_home_assistant.ino index 4be4377d7..20e03fd99 100644 --- a/sonoff/xdrv_12_home_assistant.ino +++ b/sonoff/xdrv_12_home_assistant.ino @@ -424,8 +424,9 @@ void HAssDiscovery(uint8_t mode) { // Configure Tasmota for default Home Assistant parameters to keep discovery message as short as possible if (Settings.flag.hass_discovery) { - Settings.flag.mqtt_response = 0; // Response always as RESULT and not as uppercase command - Settings.flag.decimal_text = 1; // Respond with decimal color values + Settings.flag.mqtt_response = 0; // Response always as RESULT and not as uppercase command + Settings.flag.decimal_text = 1; // Respond with decimal color values + Settings.flag3.hass_tele_as_result = 1; // send tele/STATE message as stat/RESULT // Settings.light_scheme = 0; // To just control color it needs to be Scheme 0 if (!string_ends_with(Settings.mqtt_fulltopic, "%prefix%/")) strncpy_P(Settings.mqtt_fulltopic, PSTR("%topic%/%prefix%/"), sizeof(Settings.mqtt_fulltopic));