HA light states are wrong after restart the service

HI!

I doing my very first steps with HA, and after first automation ( witch works fine and It’s not related) I discovered when I doing some changes in configuration and restarting the HA service, the light state are wrong - some lights are turned ON however the web shows that all lights is OFF. I using sonoff basic module.
module described :

  • alias: suurtuba laualamp
    platform: mqtt
    name: “suurtuba laualamp”
    state_topic: “stat/suurtuba_laualamp/POWER”
    command_topic: “cmnd/suurtuba_laualamp/POWER”
    payload_on: “ON”
    payload_off: “OFF”
    qos: 0
    retain: true

I tracked the mqtt as well- and same module send after every 5 minutes state information:
tele/suurtuba_laualamp/STATE {"Time":"2017-10-26T09:53:16", "Uptime":36, "Vcc":3.182, "POWER":"OFF", "Wifi":{"AP":1, "SSId":"HAWiFi", "RSSI":78, "APMac":"36:A4:3C:09:DF:63"}}.
But the state on UI (classical default) stays the same (“OFF”)

Your state_topic: and payload: don’t match this message, which is why it doesn’t change state.

To match this message you need something like

   state_topic: tele/suurtuba_laualamp/STATE
   state_value_template: "{{ value_json.POWER}}"

See the example here

Edit:
Actually, reading your post again, it looks like this is a general status message, rather than a response to the command. If your light is working normally, have you set the sonoff to send the state message with the retain flag set? That will cause the mqtt broker to store the state of the last message and send to it HA when it reconnects.

1 Like

HI!
I do not think so, that I made any changes on sonoff, any hint how and where I must set to send the state message with retain flag set ?

Hi @Marvex, take a look here:

1 Like

Wou thanks, PowerRetain 1 is the magic “word” - for the beginners ( like me) one more thing, after you add the PowerRetain 1 from commend lines to your sonoff, You must at least once change the status of switch, then the add command activating or adding necessary lines on state command.

2 Likes