-
-
Notifications
You must be signed in to change notification settings - Fork 28.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tasmota mqtt switch with two state_topic (tele and stat) - wrong HASS state #18703
Comments
This should be fixed in Tasmota, I opened arendst/Tasmota#4450. |
Could you elaborate about the direction of fix? Haveing one topic from Tasmota point of view does not seems to me as the right solution (it is simple) Looking into Tasmota reset sequence, stat topic is sent so option #3 is enough for common cases (state can change only by cmnd topic) but not robust as I would like it to be. Moreover I would be happy to understand why option #2 solve the issue (from HASS perspective) |
@hhaim 2) most likely hides the issue due to a (now fixed) race condition which incorrectly made MQTT devices with same name share entity id The PR I opened on Tasmota sends the periodic updates as stat/s0/RESULT instead of as Tele/s0/STATUS Let's continue the discussion in arendst/Tasmota#4450 |
Yes, 1) would have been a solution, but perhaps unnecessarily complex to support lists of topics. |
@hhaim, @emontnemery: Send tele/STATUS as state/RESULT doesn't solve problem of update in HA or other automation software. Still have to wait up to teleperiod for update. There are two simple options on HA side:
|
@mkh595 You're right, an automation is required to get correct state immediately after restart of HA. Instead of the automation you mention, use this one to get all states, not just relay state: - alias: "Power state on HA start-up"
trigger:
platform: homeassistant
event: start
action:
- service: mqtt.publish
data:
topic: "cmnd/sonoffs/state"
payload: "" |
Yes, this is by the book solution, I've mention it in the question and maybe I wasn't clear enogth "add to HA startup.yaml (from tasmota wiki) service: mqtt.publish The problem is that there are two method (two topics) to reports the state |
RESULT is published only when asked by command But why do you have problem with two methods? Why do you need to use both?
When sonoff is restarted, it always send Btw. if your HA die or blow up, you will not have problem with sync and your boiler? |
Yes, this is exactly the point. @mkh595 If the MQTT broker is restarted, or some MQTT message is simply lost, there is absolutely no guarantee that the states are is sync. By using tele/topic/STATE, you are guaranteed a sync within the teleperiod and whenever there is a status change. |
(a few lines of code). It requires minimal YAML configuration (short topic only) and support both topics/LWT as defaults. It does not require the startup script configuration etc. |
I have the same issue. Restarting MQTT you can loose the state of the relay esp if someone has turned it on/off using "Sonoff Button" or a timer in Tasmota.. |
I can share my custom Tasmota switch and binary sensor if required. |
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. |
I've written a custom switch/sensor/binary sensor for Tasmota. It handles both messages in a clean way see here: You define it like this: https://github.com/hhaim/hass/blob/master/configuration.yaml
The Qos is 1 by default (hass->mqtt broker). Tasmota does not support Qos>0 (from Tasmota -> broker) Even if there is a drop of STATUS packet , the hass will be sync in the next /tele/ mqtt packet. |
BTW this code is not bulletproof. Qos from Tasmota is 0. So you might not get the RESULT in some case. |
I am not very happy with the solution based on forcing telemetry updates in Tasmota devices whenever a state change happens. It seems to work, but I think it is unnatural and innecessarily pollutes the MQTT message log. I believe the custom HA switch by @hhaim is the best way to go: it responds to all relevant standard Tasmota messages and, as a big plus, makes device configuration extremely simple and error-free. @hhaim Thank you for sharing your Tasmota custom components (BTW, your reference to them in your message above is broken). I have been using a modified version of the switch component, which allows for POWER as equivalent of POWER1 in state messages, and also fixes a deprecated MQTT receive-message callback. It's working like a charm. I would be happy to share those changes if you would like to integrate them into your component. |
@gufonero thanks, I am almost blown my boiler with the old method :-) The new links:
|
The same behavior can also be achieved by enabling SetOption59 in every Tasmota device and using state_topic 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 whiletele
topic is sentperiodically
every x sec (e.g. 300 sec).At first, I've used the
stat
topic something like this (from the tasmota wiki)`
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 the
tele` state update.HASS default Mqtt switch does not support more than one topic/template per switch.
Options to solve this:
somthing like this:
`
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:
`
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)
The text was updated successfully, but these errors were encountered: