From f4da1d1d869710c83054309c43790e00405b2a36 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Wed, 20 Mar 2019 00:57:26 -0300 Subject: [PATCH] Added HASS_STATE to command STATE The command STATE has a secondary mqtt message in the case that SETOPTION59 is 1 This adds a HASS_STATE mqtt message if HomeAssistant discovery is enabled. This is useful for syncing HomeAssistant with all the states of a Tasmota device when HA is restarted. The actual automation for HA explained in the wiki will also make use of this new message. --- sonoff/sonoff.ino | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 51b89031c..d1cf3adb1 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -615,6 +615,11 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) if (Settings.flag3.hass_tele_on_power) { MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN); } +#ifdef USE_HOME_ASSISTANT + if (Settings.flag.hass_discovery) { + HAssPublishStatus(); + } +#endif // USE_HOME_ASSISTANT } else if (CMND_SLEEP == command_code) { if ((payload >= 0) && (payload < 251)) {