Sonoffs Tasmotized turn on

Hi, I have Home Assistant and some tasmotized sonoffs.

The problem is that JUST 2 of them, when home assistant is restarted, or the sonoff is restarted, they turn on, no matter the state they had before, and not allways.

One of them is configured to stay off on boot, but sometimes, when restarted, it connects to mosquitto and then turn on, eaven if it was off before restart.

I think this is related with LWT, but I’m not shure. Option 10 is off in both of them.

They are configured like this:

  • platform: mqtt
    name: “LamparaLiving”
    command_topic: “cmnd/sonoff09/power”
    state_topic: “stat/sonoff09/POWER”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: false
    availability_topic: “tele/sonoff09/LWT”
    payload_available: “Online”
    payload_not_available: “Offline”

and I already tryed this:

  • platform: mqtt
    name: “LamparaLiving”
    command_topic: “cmnd/sonoff09/power”
    state_topic: “stat/sonoff09/POWER”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: true

Can anybody help me?

See that blue bar on top? Can you follow the instructions to format your code please?
You say you have a few devices, can you share the config for the others?
Also MQTT needs a unique ID for each client, make sure you’ve not got the same client ID on 2 sonoffs

change this line:

command_topic: “cmnd/sonoff09/power”

to

command_topic: “cmnd/sonoff09/POWER”

case matters.

This sounds like a retain flag problem. When a message is sent with the retain flag set, it is stored in the brokers database, and whenever the client connects to the broker (by switching on), that message is re-sent to the client. If the payload is “ON”, that will turn on the switch.

To complicate matters, simply turning the retain: false does not remove the topic from the broker’s database, so the problem continues.

To remove the topic from the broker’s database, you need to send the broker a message with that topic, a null payload and the retain flag set. You can do this with another client, such as mosquitto_pub

mosquitto_pub -t cmnd/sonoff09/power -r -n

You may need to add password, user and host parameters to this, depending on your MQTT setup.