core: Tasmota mqtt switch with two state_topic (tele and stat) - wrong HASS state
I’m not sure if this is a bug or a feature and I would like to get an opinion how to solve this.
The problem:
Tasmota switch has two topics to report a state – without using both, HASS can have a the wrong state after restart or if device had a reset, for a very long time (OFF while the power is ON) only changing the state can fix this. This is a very serious issue in some cases (Boiler case)
More details:
tele/pow0/STATE = {"Time":"2018-11-24T16:59:06","Uptime":"2T22:12:00","Vcc":3.206,"POWER":"ON","Wifi":{"AP":1,"SSId":"fbi-4","RSSI":100,"APMac":"30:B5:C2:96:6D:96"}}
stat/b0/RESULT = {"POWER":"OFF"}
stat topic is sent after command while tele topic is sent periodically every x sec (e.g. 300 sec).
At first, I’ve used the stat topic something like this (from the tasmota wiki)
`
- platform: mqtt
name: “ac1”
state_topic: “stat/s0/RESULT”
value_template: ‘{{ value_json[“POWER1”] }}’
command_topic: “cmnd/s0/POWER1”
availability_topic: “tele/s0/LWT”
qos: 1
payload_on: “ON”
payload_off: “OFF”
payload_available: “Online”
payload_not_available: “Offline”
retain: false
but this does not catch thetele` state update.
HASS default Mqtt switch does not support more than one topic/template per switch.
Options to solve this:
- Add a private mqtt switch that support a list of [topic/template] – does not seem very complicated
- Adding another switch with the same name but with different topic state create a new mqtt object but it seems associated to the same GUI object and API and it get updated
somthing like this:
`
- platform: mqtt name: “ac1” state_topic: “tele/s0/STATE” value_template: ‘{{ value_json[“POWER1”] }}’ command_topic: “cmnd/s0/POWER1” availability_topic: “tele/s0/LWT” qos: 1 payload_on: “ON” payload_off: “OFF” payload_available: “Online” payload_not_available: “Offline” retain: false ` I don’t know why it works but it seems both mqtt objects update the same GUI entity (same name “ac1”)
Questions:
- Is option #2 a valid workaround? will it work on lovelace-ui?
- Is it better to add a new mqtt switch with more than one state_topic?
- add to HA startup.yaml (from tasmota wiki)
`
- service: mqtt.publish data: topic: “cmnd/s0/power1” payload: “” `
This will force the update only at startup The problem with this option that ‘reset’ of tasmota (without the reset from HASS) will keep the state wrong, so I think only option #1 or option #2 are valid (let’s say the device can change the state by itself without command and report it)
- Setting a mqtt retain flag is not a valid answer
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 20 (6 by maintainers)
@gufonero thanks, I am almost blown my boiler with the old method 😃 The new component works fine for 6 months now.
The new links:
If anyone are interested: I have the telemetry period set to 300 seconds (default). After a restart of HA, I don’t want to wait 5 minutes before receiving Wattage update (tele/%topic%/SENSOR). I’ve solved this problem by forcing a restart of all my tasmota devices. Everything is then synced within 10-15 seconds.
My sensor configurations in HA are like this
If anyone have a better solution please post it.