diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 47ee15b9d..9703b62e8 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -572,7 +572,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) switch (index) { case 3: // mqtt case 15: // pwm_control - case 19: // hass_discovery +// case 19: // hass_discovery restart_flag = 2; case 0: // save_state case 1: // button_restrict @@ -587,6 +587,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) case 16: // ws_clock_reverse case 17: // decimal_text case 18: // light_signal + case 19: // hass_discovery case 20: // not_power_linked case 21: // no_power_on_check bitWrite(Settings.flag.data, index, payload); @@ -595,6 +596,11 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) stop_flash_rotate = payload; SettingsSave(2); } +#ifdef USE_HOME_ASSISTANT + if (19 == index) { // hass_discovery + HAssDiscovery(1); + } +#endif // USE_HOME_ASSISTANT } } else { // SetOption32 .. diff --git a/sonoff/xdrv_07_home_assistant.ino b/sonoff/xdrv_07_home_assistant.ino index 87a07a6f6..3f8e001be 100644 --- a/sonoff/xdrv_07_home_assistant.ino +++ b/sonoff/xdrv_07_home_assistant.ino @@ -183,7 +183,7 @@ void HAssDiscoverButton() } } -void HAssDiscovery() +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) { @@ -193,15 +193,15 @@ void HAssDiscovery() // strncpy_P(Settings.mqtt_fulltopic, PSTR("%prefix%/%topic%/"), sizeof(Settings.mqtt_fulltopic)); // Make MQTT topic as short as possible to make this process posible within MQTT_MAX_PACKET_SIZE } - // Send info about relays and lights - HAssDiscoverRelay(); + if (Settings.flag.hass_discovery || (1 == mode)) { + // Send info about relays and lights + HAssDiscoverRelay(); + // Send info about buttons + HAssDiscoverButton(); + // TODO: Send info about switches - // Send info about buttons - HAssDiscoverButton(); - - // TODO: Send info about switches - - // TODO: Send info about sensors + // TODO: Send info about sensors + } } /*********************************************************************************************\ @@ -217,7 +217,7 @@ boolean Xdrv07(byte function) if (Settings.flag.mqtt_enabled) { switch (function) { case FUNC_MQTT_INIT: - HAssDiscovery(); + HAssDiscovery(0); break; } }