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.12k stars 4.79k forks source link

MQTT autodiscovery (SO19 1) does not work for binary sensors #10660

Closed Gifford47 closed 3 years ago

Gifford47 commented 3 years ago

PROBLEM DESCRIPTION

The docs (HA Supported Entities) say that the auto discovery function also works for binary sensors, depending on switchmode and setoption114. However, I have connected a PIR to gpio5 on a Wemos D1 Mini and I do not get a homeassistant topic for automatic discovery.

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

- [x] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
[12:55:26] cmnd/tasmota1_dht22/Backlog Rule1; Rule2; Rule3
[12:55:26] stat/tasmota1_dht22/RESULT {"Rule1":"OFF","Once":"OFF","StopOnError":"OFF","Length":0,"Free":511,"Rules":""}
[12:55:26] stat/tasmota1_dht22/RESULT {"Rule2":"OFF","Once":"OFF","StopOnError":"OFF","Length":0,"Free":511,"Rules":""}
[12:55:26] stat/tasmota1_dht22/RESULT {"Rule3":"OFF","Once":"OFF","StopOnError":"OFF","Length":0,"Free":511,"Rules":""}
- [x] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
00:00:00 CFG: Loaded from flash at FA, Count 50
00:00:00 QPC: Count 1
00:00:00 CFG: CR 411/699, Busy 0
00:00:00 SRC: Restart
00:00:00 Project tasmota tasmota1_dht22 Version 9.2.0(tasmota)-2_7_4_9(2020-12-21T15:03:40)
00:00:00 DHT: (v5) Sensors found 1
00:00:00 WIF: Checking connection...
00:00:00 WIF: Attempting connection...
00:00:00 WIF: Connecting to AP1 nodes_land Channel 11 BSSId F2:9F:C2:3A:CD:0A in mode 11n as tasmota1_dht22-4720...
00:00:01 WIF: Checking connection...
00:00:01 WIF: Connected
00:00:02 HTP: Web server active on tasmota1_dht22-4720 with IP address 192.168.1.83
13:07:15 RTC: UTC 2021-01-22T12:07:15, DST 2021-03-28T02:00:00, STD 2021-10-31T03:00:00
13:07:16 MQT: Attempting connection...
13:07:16 MQT: Connected
13:07:16 MQT: tele/tasmota1_dht22/LWT = Online (retained)
13:07:16 MQT: cmnd/tasmota1_dht22/POWER = 
13:07:16 MQT: Subscribe to cmnd/tasmota1_dht22/#
13:07:16 MQT: Subscribe to cmnd/tasmotas/#
13:07:16 MQT: Subscribe to cmnd/DVES_EFF270_fb/#
13:07:16 MQT: Subscribe to homeassistant/status
13:07:16 MQT: tele/tasmota1_dht22/INFO1 = {"Module":"Generic","Version":"9.2.0(tasmota)","FallbackTopic":"cmnd/DVES_EFF270_fb/","GroupTopic":"cmnd/tasmotas/"}
13:07:16 MQT: tele/tasmota1_dht22/INFO2 = {"WebServerMode":"Admin","Hostname":"tasmota1_dht22-4720","IPAddress":"192.168.1.83"}
13:07:16 MQT: tele/tasmota1_dht22/INFO3 = {"RestartReason":"Software/System restart"}
13:07:19 QPC: Reset
13:07:20 MQT: tele/tasmota1_dht22/STATE = {"Time":"2021-01-22T13:07:20","Uptime":"0T00:00:09","UptimeSec":9,"Heap":27,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"Wifi":{"AP":1,"SSId":"nodes_land","BSSId":"F2:9F:C2:3A:CD:0A","Channel":11,"RSSI":84,"Signal":-58,"LinkCount":1,"Downtime":"0T00:00:03"}}
13:07:20 MQT: tele/tasmota1_dht22/SENSOR = {"Time":"2021-01-22T13:07:20","Switch1":"ON","AM2301":{"Temperature":20.6,"Humidity":57.1,"DewPoint":11.8},"TempUnit":"C"}
13:07:21 APP: Boot Count 18
13:07:21 CFG: Saved to flash at F9, Count 51, Bytes 4096
13:07:25 MQT: homeassistant/binary_sensor/EFF270_SW_5/config =  (retained)
13:07:25 MQT: homeassistant/device_automation/EFF270_SW_6_TOGGLE/config =  (retained)
13:07:25 MQT: homeassistant/device_automation/EFF270_SW_6_HOLD/config =  (retained)
13:07:25 MQT: homeassistant/binary_sensor/EFF270_SW_6/config =  (retained)
13:07:25 MQT: homeassistant/device_automation/EFF270_SW_7_TOGGLE/config =  (retained)
13:07:25 MQT: homeassistant/device_automation/EFF270_SW_7_HOLD/config =  (retained)
13:07:25 MQT: homeassistant/binary_sensor/EFF270_SW_7/config =  (retained)
13:07:25 MQT: homeassistant/device_automation/EFF270_SW_8_TOGGLE/config =  (retained)
13:07:25 MQT: homeassistant/device_automation/EFF270_SW_8_HOLD/config =  (retained)
13:07:25 MQT: homeassistant/binary_sensor/EFF270_SW_8/config =  (retained)
13:07:25 MQT: homeassistant/sensor/EFF270_AM2301_Temperature/config = {"name":"tasmota1_dht22 AM2301 Temperature","stat_t":"tele/tasmota1_dht22/SENSOR","avty_t":"tele/tasmota1_dht22/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"EFF270_AM2301_Temperature","dev":{"ids":["EFF270"]},"unit_of_meas":"°C","dev_cla":"temperature","frc_upd":true,"val_tpl":"{{value_json['AM2301']['Temperature']}}"} (retained)
13:07:25 MQT: homeassistant/sensor/EFF270_AM2301_Humidity/config = {"name":"tasmota1_dht22 AM2301 Humidity","stat_t":"tele/tasmota1_dht22/SENSOR","avty_t":"tele/tasmota1_dht22/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"EFF270_AM2301_Humidity","dev":{"ids":["EFF270"]},"unit_of_meas":"%","dev_cla":"humidity","frc_upd":true,"val_tpl":"{{value_json['AM2301']['Humidity']}}"} (retained)
13:07:25 MQT: homeassistant/sensor/EFF270_AM2301_DewPoint/config = {"name":"tasmota1_dht22 AM2301 DewPoint","stat_t":"tele/tasmota1_dht22/SENSOR","avty_t":"tele/tasmota1_dht22/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"EFF270_AM2301_DewPoint","dev":{"ids":["EFF270"]},"unit_of_meas":"°C","ic":"mdi:weather-rainy","frc_upd":true,"val_tpl":"{{value_json['AM2301']['DewPoint']}}"} (retained)
13:07:25 MQT: homeassistant/cover/EFF270_SHT_1/config =  (retained)
13:07:25 MQT: homeassistant/cover/EFF270_SHT_2/config =  (retained)
13:07:25 MQT: homeassistant/cover/EFF270_SHT_3/config =  (retained)
13:07:25 MQT: homeassistant/cover/EFF270_SHT_4/config =  (retained)
13:07:25 MQT: homeassistant/light/EFF270_LI_1/config =  (retained)
13:07:25 MQT: homeassistant/switch/EFF270_RL_1/config =  (retained)
13:07:25 MQT: homeassistant/light/EFF270_LI_2/config =  (retained)
13:07:25 MQT: homeassistant/switch/EFF270_RL_2/config =  (retained)
13:07:25 MQT: homeassistant/light/EFF270_LI_3/config =  (retained)
13:07:25 MQT: homeassistant/switch/EFF270_RL_3/config =  (retained)
13:07:25 MQT: homeassistant/light/EFF270_LI_4/config =  (retained)
13:07:25 MQT: homeassistant/switch/EFF270_RL_4/config =  (retained)
13:07:25 MQT: homeassistant/light/EFF270_LI_5/config =  (retained)
13:07:25 MQT: homeassistant/switch/EFF270_RL_5/config =  (retained)
13:07:25 MQT: homeassistant/light/EFF270_LI_6/config =  (retained)
13:07:25 MQT: homeassistant/switch/EFF270_RL_6/config =  (retained)
13:07:25 MQT: homeassistant/light/EFF270_LI_7/config =  (retained)
13:07:25 MQT: homeassistant/switch/EFF270_RL_7/config =  (retained)
13:07:25 MQT: homeassistant/light/EFF270_LI_8/config =  (retained)
13:07:25 MQT: homeassistant/switch/EFF270_RL_8/config =  (retained)
13:07:25 MQT: homeassistant/sensor/EFF270_status/config = {"name":"tasmota1_dht22 status","stat_t":"tele/tasmota1_dht22/HASS_STATE","avty_t":"tele/tasmota1_dht22/LWT","pl_avail":"Online","pl_not_avail":"Offline","json_attr_t":"tele/tasmota1_dht22/HASS_STATE","unit_of_meas":"%","val_tpl":"{{value_json['RSSI']}}","ic":"mdi:information-outline","uniq_id":"EFF270_status","dev":{"ids":["EFF270"],"name":"tasmota1_dht22","mdl":"Generic","sw":"9.2.0(tasmota)","mf":"Tasmota"}} (retained)
13:07:25 MQT: tasmota/discovery/D8BFC0EFF270/config =  (retained)

TO REPRODUCE

You can configure a switch (160) and use it as binary sensor, using switchmode1 1. Detach switches from relays and send MQTT messages instead SetOption114 1. Also enable setoption19 1 .Restart and look into console to find homeassistant/* switch or binary_sensor auto discovery topic.

EXPECTED BEHAVIOUR

A auto discovery topic should be send to mqtt broker, like: _homeassistant/binarysensor/switch1/config = ...

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

a similar issue was created here: #10578

(Please, remember to close the issue when the problem has been addressed)

ascillato commented 3 years ago

Please, could you be so kind on completing the troubleshooting template in order to have more information so as to properly help you?

Remember to read the Contributing Guideline and Policy. Thanks.


Support Information

See Docs for more information. See Chat for more user experience. See Community for forum. See Code of Conduct

ascillato2 commented 3 years ago

The template is incomplete so I will be guessing. Are you using setoption19 1? If so, that is MQTT DISCOVERY. For Home Assistant NATIVE Discovery (and the ability to use setoption114) you have to use setoption19 0. Your entities will be automatically populated under INTEGRATIONS in Home Assistant.

Gifford47 commented 3 years ago

sorry, i updated the template. yes, i am using setoption19 1. I need the option for openhab3, that the things will be created automatically. but like i described the switch topic is missed ...

ascillato commented 3 years ago

Ok so you are using OpenHab and not Home Assistant!

setoption19 1 is MQTT DISCOVERY that can be used for OpenHab and others setoption19 0 is Home Assistant Discovery.

As the title said Home Assistant, I assume you were using Home Assistant. Ok, let me do some tests.

effelle commented 3 years ago

https://tasmota.github.io/docs/Home-Assistant/#supported-entities_1

To have switches discovered SwitchTopic must be set to a custom name and it will automatically start 
to listen and publish using stat/%topic%/SWITCH<x> (binary sensor) or stat/%topic%/SWITCH<x>T (trigger) topics.
marc-gist commented 3 years ago

https://tasmota.github.io/docs/Home-Assistant/#supported-entities_1

To have switches discovered SwitchTopic must be set to a custom name and it will automatically start 
to listen and publish using stat/%topic%/SWITCH<x> (binary sensor) or stat/%topic%/SWITCH<x>T (trigger) topics.

This isn't working for me. I set a SwitchTopic door, and did so19 (switch is SwitchMode1 15), and still no binary sensor set in HA.

[edit] I am Using HomeAssistant. @ascillato and both so19 1 and so19 0 with native HA integration installed does NOT produce a Switch sensor entity in HA. I prefer to use so19 1 and wait for the tasmota integration to mature. its also easier to control which devices I setup in HA that way.

effelle commented 3 years ago

Switchmode 15 is not supported by the discovery since is an switchmode made just for MQTT messages and the discovery use its customized topic. As a test use another switchmode and please report.

marc-gist commented 3 years ago

Switchmode 15 is not supported by the discovery since is an switchmode made just for MQTT messages and the discovery use its customized topic. As a test use another switchmode and please report.

That worked, set to switchmode1 1, however, setup a device named <tasmota_name>_switch1 Rather than using the SwitchTopic for the name.
Is there a way to name the switch and device type prior to enabling so19?

Gifford47 commented 3 years ago

https://tasmota.github.io/docs/Home-Assistant/#supported-entities_1

To have switches discovered SwitchTopic must be set to a custom name and it will automatically start 
to listen and publish using stat/%topic%/SWITCH<x> (binary sensor) or stat/%topic%/SWITCH<x>T (trigger) topics.

thanks for the answer!

I have now set "switchtopic pir" and a switch channel is now automatically created in openhab. however, the D1 mini does not send a mqtt message as soon as the pir sensor value changes. no MQTT log appears in the tasmota log. I can't create a rule either, because I created the switch topic...

Gifford47 commented 3 years ago

ok, now it works (i resetted the d1 mini and configured it new). to use mqtt autodiscovery with switches in openhab you have to set the following: "switchmode1 1" -> binary sensor (ON/OFF) "switchtopic " -> must be set to a custom value, to use mqtt autodiscovery for switches (acc. to. supported entities) "setoption19 1" -> enable homeassistant auto discovery

I still have one question, though: by using switchtopic, i can no longer use a rule on the Switch#State trigger. however, i would like to "switch on" or "switch off" the switch (in my case the pir sensor) when it is not needed. how can i now use a rule to prevent the switch from sending its status every time?

effelle commented 3 years ago

There is a possible workaround but is a bit of a hit and miss:

on System#Boot do backlog switchtopic pir; delay 200;  switchtopic 2 endon

And then use the switch JUST with a rule using ON SWITCH<x>#STATE=n. Pay attention to the delay value, since the discovery will be updated +/- 10 seconds after a full reboot. Also consider using a rule to manage the switches will introduce a little delay in action.