I know, this looks like other topics already posted… and I read those (2 or 3 came up in a search). Most state this is HA not getting the MQTT data back stating the switch is on or off. But I do not think this is the case here.
Here is the setup:
- HASSIO on a raspi. 0.98.5
- Several sonoff and ESP8266 devices flashed with tasmota (this one is an ESP8266 in question - 6.6.0(sonoff) core is 2_5_2/2.2.1 - 2 relays on the device, no buttons, switches or sensors defined).
- I have watched the video on retain, and cleared old flags plus used the buttonon,off steps in the video to clear states, and retain is false.
- I have been watching the MQTT traffic with explorer, and it looks correct.
- Switch (POWER2) works. Switch (POWER1) also responds to HA - it will turn on if you ask it from HA, and if you fast-double click the HA switch before it can revert, it will also turn off correctly. But normally it switches on in HA and then reverts after a second, while the switch remains on.
HA states its subscribing to everything i think it should. I have debug MQTT logging enabled. (also found a tasmota using retain and i thought i got em all but… this was a great place to catch that - turn on MQTT debug and restart HA, then see what it subscribes to and if it gets a retained message immediately)
I see the MQTT state is being received by HA for the problem switch. This is the thing that stumps me. If something was not published, I could see HA reverting. But in the logs it shows it DOES get the state:
2019-09-13 11:08:10 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on cmnd/tasmo-2958/power: ON
2019-09-13 11:08:10 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/tasmo-2958/RESULT: b’{“POWER1”:“ON”}’
This is identical to the traffic for the same device, but different switch (which works fine):
2019-09-13 11:09:01 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on cmnd/tasmo-2958/power2: ON
2019-09-13 11:09:02 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/tasmo-2958/RESULT: b’{“POWER2”:“ON”}
Wait… I just noticed something… POWER vs POWER1 vs POWER2 - should that be POWER1 and POWER2? As in POWER does not default to 1? Let me change the device MQTT definition in config to POWER1 instead of just POWER, and restart…
Ah. OK - then when you are doing multiple power relays on one device, make sure you append the number on all of the entries - because even though it is coming to HA, HA is not assuming POWER is the “POWER1” state… which I guess sort of makes sense.
OK - so is this documented somewhere? That you need to add numbers everywhere if you are not using just one relay? I sure missed it. Would be a common mistake if you are used to working with singles all the time and add your first multi-relay device… (this is my 4th ESP8266 custom device, but the first one with more than one relay)
Oh well… so I figured it out, but i’ll post this anyhow in case someone else runs into it. It is not MQTT retention issues at all… it is just something very easy to overlook.