arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.04k stars 4.78k forks source link

Home Assistant discovery: switch and buttons are not transmitted. #6530

Closed effelle closed 5 years ago

effelle commented 5 years ago

BUG DESCRIPTION

As per Wiki, Home Assistant discovery should create button and switches under /binary_sensor/%s/config automatically, independently by the presence of a relay. Actually the switches and buttons aren't created at all. As a first inspection using some AddLog(LOG_LEVEL_DEBUG), seems void HAssAnnounceButtonSwitch() is never reached even if void HAssAnnounceSwitches(void) and void HAssAnnounceButtons(void) are. A more simple setup like switch1/relay1 will show the same issue: just the relay will be sent to Home Assistant.

REQUESTED INFORMATION

TO REPRODUCE

Setup a device with just swithces and buttons and enable setoption19.

EXPECTED BEHAVIOUR

All the switches and buttons should be created on Home Assistant as binary_sensor.

effelle commented 5 years ago

@ascillato2 Adrian why mark it as a feature request? We have the code to manage button and switches already in place on xdrv_12_home_assistant.ino starting from L298 and the wiki report it as a normal behavior.

effelle commented 5 years ago

@arendst, I've found the issue. Buttons and switches are not created when using the default switchtopic / buttontopic. Just set them with any other value than 0 and the entities will be created as expected:

16:01:57 CMD: backlog switchtopic; buttontopic; gpio;
16:01:57 MQT: HA_DEV7/stat/RESULT = {"SwitchTopic":"HA_DEV7"}
16:01:57 MQT: HA_DEV7/stat/RESULT = {"ButtonTopic":"HA_DEV7"}
16:01:57 MQT: HA_DEV7/stat/RESULT = {"GPIO0":{"0":"None"},"GPIO1":{"0":"None"},"GPIO2":{"0":"None"},"GPIO3":{"0":"None"},"GPIO4":{"17":"Button1"},"GPIO5":{"18":"Button2"},"GPIO12":{"9":"Switch1"},"GPIO13":{"10":"Switch2"},"GPIO14":{"11":"Switch3"},"GPIO15":{"0":"None"},"GPIO16":{"0":"None"}}
16:02:01 CMD: setoption19 1
16:02:01 MQT: HA_DEV7/stat/RESULT = {"SetOption19":"ON"}
16:02:01 MQT: homeassistant/light/471078_LI_1/config =  (retained)
16:02:01 MQT: homeassistant/switch/471078_RL_1/config =  (retained)
16:02:01 MQT: homeassistant/light/471078_LI_2/config =  (retained)
16:02:01 MQT: homeassistant/switch/471078_RL_2/config =  (retained)
16:02:01 MQT: homeassistant/light/471078_LI_3/config =  (retained)
16:02:01 MQT: homeassistant/switch/471078_RL_3/config =  (retained)
16:02:01 MQT: homeassistant/light/471078_LI_4/config =  (retained)
16:02:01 MQT: homeassistant/switch/471078_RL_4/config =  (retained)
16:02:01 MQT: homeassistant/light/471078_LI_5/config =  (retained)
16:02:01 MQT: homeassistant/switch/471078_RL_5/config =  (retained)
16:02:01 MQT: homeassistant/light/471078_LI_6/config =  (retained)
16:02:01 MQT: homeassistant/switch/471078_RL_6/config =  (retained)
16:02:01 MQT: homeassistant/light/471078_LI_7/config =  (retained)
16:02:01 MQT: homeassistant/switch/471078_RL_7/config =  (retained)
16:02:01 MQT: homeassistant/light/471078_LI_8/config =  (retained)
16:02:01 MQT: homeassistant/switch/471078_RL_8/config =  (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_BTN_1/config = {"name":"HA_DEV7 BTN","stat_t":"~cmnd/POWER","pl_on":"ON","avty_t":"~tele/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"471078_BTN_1","device":{"identifiers":["471078"],"connections":[["mac","CC:50:E3:47:10:78"]]},"~":"HA_DEV7/","frc_upd":true,"pl_off":"OFF"} (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_BTN_2/config = {"name":"Sonoff2 BTN","stat_t":"~cmnd/POWER","pl_on":"ON","avty_t":"~tele/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"471078_BTN_2","device":{"identifiers":["471078"],"connections":[["mac","CC:50:E3:47:10:78"]]},"~":"HA_DEV7/","frc_upd":true,"pl_off":"OFF"} (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_BTN_3/config =  (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_BTN_4/config =  (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_SW_1/config = {"name":"HA_DEV7 SW","stat_t":"~cmnd/POWER","pl_on":"ON","avty_t":"~tele/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"471078_SW_1","device":{"identifiers":["471078"],"connections":[["mac","CC:50:E3:47:10:78"]]},"~":"HA_DEV7/","frc_upd":true,"pl_off":"OFF"} (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_SW_2/config = {"name":"Sonoff2 SW","stat_t":"~cmnd/POWER","pl_on":"ON","avty_t":"~tele/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"471078_SW_2","device":{"identifiers":["471078"],"connections":[["mac","CC:50:E3:47:10:78"]]},"~":"HA_DEV7/","frc_upd":true,"pl_off":"OFF"} (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_SW_3/config = {"name":"Sonoff3 SW","stat_t":"~cmnd/POWER","pl_on":"ON","avty_t":"~tele/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"471078_SW_3","device":{"identifiers":["471078"],"connections":[["mac","CC:50:E3:47:10:78"]]},"~":"HA_DEV7/","frc_upd":true,"pl_off":"OFF"} (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_SW_4/config =  (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_SW_5/config =  (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_SW_6/config =  (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_SW_7/config =  (retained)
16:02:01 MQT: homeassistant/binary_sensor/471078_SW_8/config =  (retained)
16:02:01 MQT: homeassistant/sensor/471078_status/config = {"name":"HA_DEV7 status","stat_t":"~HASS_STATE","avty_t":"~LWT","pl_avail":"Online","pl_not_avail":"Offline","json_attributes_topic":"~HASS_STATE","unit_of_meas":" ","val_tpl":"{{value_json['RSSI']}}","uniq_id":"471078_status","device":{"identifiers":["471078"],"connections":[["mac","CC:50:E3:47:10:78"]],"name":"HA_DEV7","model":"Generic","sw_version":"6.6.0.14(sonoff)","manufacturer":"Tasmota"},"~":"HA_DEV7/tele/"} (retained))

However, this will create issues with normal behavior.
Now, my question: is there a real interest on HA integration? I know you don't like it much and I can't blame you for that in some way, but we have the possibility to transform it in a fully functional tool for BOTH Home Assistant and OpenHab, since the latter can now identify MQTT device with HA format, even if some adjustment are needed for JsonPath.
I know the code size and ram usage are an issue, then how about start to think to remove it form the main .bins to free space for more interesting stuff and create another firmware sonoff-ha.bin? @meingraham @ascillato2 @Jason2866 @jziolkowski what are your thoughts?

ascillato commented 5 years ago

As there is a important number of users that have Home Assistant as its home automation software, I don't think to be a good idea to disable it by default.

meingraham commented 5 years ago

I think if there are new features that begin to push against the flash and iRAM limits of the ESP82xx, then HA could be considered a "user option". We can consider providing "pre-made" user_config_override.h for HA users to easily compile using Gitpod... or, now that @andrethomas has optimized firmware compilation using PlatfromIO caching on thehackbox, add another branch of binary variants for HA. When 2.6 comes out, there may be an opportunity to have HA variants which are only 2.6. If users want HA on another core, they can compile themselves.

andrethomas commented 5 years ago

It's important to recognise that the firmware capabilities are expanding in different directions at the same time and that the time of having a sonoff.bin "one fits all solution" is not going to be possible in the not so distant future.

To me, its not just about HA vs. Non-HA support but also that we're adding drivers for chips which will never be connected to let's say a tuya based light bulb and as nice as it might be to have an LM75AD I2C temperature sensor inside the bulb it's not going to be a very likely combination.

I don't mind adding additional variants but it should be planned carefully otherwise choosing a binary will need a wizard form of some sort on its own... which of course is not ideal.

effelle commented 5 years ago

I like Mike's idea and Andre has a strong point. Tasmota is growing with an impressive pace.