H801 Tasmota / Home Assistant - States not synchronising on Startup

Hi All

I’m setting up a H801 flashed with Tasmota firmware using Mosquitto MQTT broker on the Raspberry Pi 3 B+ (with hassio 64 bit running - same issue with 32 bit though)

Everything working completely fine other than the states synchronising after Home Assistant reboot.

Example:

  • RGB Light turned OFF on HA (works fine), and tasmota interface updates perfectly
  • Turn off Raspberry Pi (light stays off and only thing in the tasmota H801 console is that the mqtt service is has been disconnected as per below):

18:27:02 MQT: Attempting connection…
18:27:07 MQT: Connect failed to 192.168.0.46:1883, rc -2. Retry in 10 sec

  • Turn light ON using Tasmota interface (I get the following from the console):

18:38:11 MQT: stat/sonoff/RESULT = {“POWER”:“ON”}
18:38:11 MQT: stat/sonoff/POWER = ON (retained)

  • Turn RPi back on - Tasmota sonoff reconnects to the MQTT broker, I get this in the console:

18:40:46 MQT: Attempting connection…
18:40:46 MQT: Connected
18:40:46 MQT: tele/sonoff/LWT = Online (retained)
18:40:46 MQT: cmnd/sonoff/POWER =

HOWEVER, in the Home Assistant UI, the light shows as OFF.

Config file as below:

mqtt:
broker: core-mosquitto
username: ****
password: ****

light:
platform: mqtt
name: “SteRGB2”
state_topic: “stat/sonoff/POWER”
command_topic: “cmnd/sonoff/POWER”
availability_topic: “tele/sonoff/LWT”
rgb_state_topic: “stat/sonoff/Color”
rgb_command_topic: “cmnd/sonoff/Color”
brightness_state_topic: “stat/sonoff/HsbColor3”
brightness_command_topic: “cmnd/sonoff/HsbColor3”
optimistic: false
qos: 1
payload_on: “ON”
payload_off: “OFF”
payload_available: “Online”
payload_not_available: “Offline”
retain: true

I presume that of course because the power off cmnd is being fired without an MQTT broker to retain the message, then this is obviously not being stored.

However I presumed that HA would check the LWT topic on startup and utilise that to sync state as per the device?

Could this be something to do with Mosquitto starting up AFTER Home Assistant on the Pi?

Any help gratefully received

Thanks

This is odd, because nothing in your configuration is sending that message with an empty payload, and with the retain flag set the broker should get updated whenever HA sends that message.

If you just subscribe to that topic using another client, what gets printed out?

Hi mate

Apologies for the late response - have been away. Appreciate you coming back to me though.

If I subscribe to that topic on any client nothing at all prints out. I also tried subscribing to all topics “#” and upon MQTT reconnection, I get a stat POWER On and a tele LWT Online - nothing on cmnd topic at all, and nothing with an empty payload.

It’s bamboozled me for god knows how long, any help appreciated.

Cheers

I had a quick look at the tasmota commands page, and its says that the command message without a payload is a query, to send the current status.

If you can’t see that from the broker, I suspect it is being generated internally by the tasmota code, in order to generate the status message when it reconnects. If this was done, it would solve your status synchronization problem.

The question then becomes why the tasmota code isn’t generating a status at that point. Can you try and send it a command with a null payload (or a question mark), to see if it then sends a status message?

If I send a null payload to…

cmnd/sonoff/POWER

…utilising MQTT.fx client on Windows 10, I get the following topics update:

stat/sonoff/RESULT {“POWER”,“ON”}
tele/sonoff/POWER ON

This also rectifies the state in the HA interface.

So for some reason, when the cmnd is issued when the Tasmota device connects to MQTT broker, nothing shows in the console.

I also entered:

cmnd/sonoff/POWER

…into the Console, and get the same:

stat/sonoff/RESULT {“POWER”,“ON”}
tele/sonoff/POWER ON

…output in the console.

Any ideas?

I don’t have a tasmota, so I don’t know if they can be configured in this respect, but I would expect them to send out something at startup to indicate the current state.

If not, you could configure an automation in HA to send the cmd/sonoff/POWER message when it gets the online message, to make the sonoff send its state back.

Thanks mate - in lieu of a solution, I have done this and works perfectly. Now to try and get the H801 colours to work with the embedded Homekit integration!

1 Like