Sonoff tasmota receive MQTT command ON when is restarted. How come?

I have a sonoff SV with tasmota on.
When is powered on, receives an ON (then OFF) command from home assistant MQTT:

00:00:03 DNS: Initialized
00:00:03 HTP: Web server active on GarageDoor-3046.local with IP address 192.168.10.15
00:00:04 MQT: Attempting connection…
00:00:04 MQT: Connected
00:00:04 MQT: tele/GarageDoor/LWT = Online (retained)
00:00:04 MQT: cmnd/GarageDoor/POWER =
00:00:04 MQT: Subscribe to cmnd/GarageDoor/#
00:00:04 MQT: Subscribe to cmnd/GroupGarageDoor/#
00:00:04 MQT: Subscribe to cmnd/DVES_252BE6/#
00:00:04 MQT: tele/GarageDoor/INFO1 = {“Module”:“Sonoff SV”,“Version”:“6.2.1.3”,“FallbackTopic”:“DVES_252BE6”,“GroupTopic”:“GroupGarageDoor”}
00:00:04 MQT: tele/GarageDoor/INFO2 = {“WebServerMode”:“Admin”,“Hostname”:“GarageDoor-3046”,“IPAddress”:“192.168.10.15”}
00:00:04 MQT: tele/GarageDoor/INFO3 = {“RestartReason”:“Power on”}
00:00:04 MQT: stat/GarageDoor/RESULT = {“POWER”:“OFF”}
00:00:04 MQT: stat/GarageDoor/POWER = OFF
00:00:04 MQT: homeassistant/light/GarageDoor_1/config = (retained)
00:00:04 MQT: homeassistant/switch/GarageDoor_1/config = {“name”:“Usa Garaj”,“command_topic”:“cmnd/GarageDoor/POWER”,“state_topic”:“stat/GarageDoor/RESULT”,“value_template”:"{{value_json.POWER}}",“payload_off”:“OFF”,“payload_on”:“ON”,“availability_topic”:“tele/GarageDoor/LWT”,“payload_available”:“Online”,“payload_not_available”:“Offline”} (retained)
00:00:04 MQT: homeassistant/light/GarageDoor_2/config = (retained)
00:00:04 MQT: homeassistant/switch/GarageDoor_2/config = (retained)
00:00:04 MQT: homeassistant/light/GarageDoor_3/config = (retained)
00:00:04 MQT: homeassistant/switch/GarageDoor_3/config = (retained)
00:00:04 MQT: homeassistant/light/GarageDoor_4/config = (retained)
00:00:04 MQT: homeassistant/switch/GarageDoor_4/config = (retained)
00:00:04 MQT: homeassistant/light/GarageDoor_5/config = (retained)
00:00:04 MQT: homeassistant/switch/GarageDoor_5/config = (retained)
00:00:04 MQT: homeassistant/light/GarageDoor_6/config = (retained)
00:00:04 MQT: homeassistant/switch/GarageDoor_6/config = (retained)
00:00:04 MQT: homeassistant/light/GarageDoor_7/config = (retained)
00:00:04 MQT: homeassistant/switch/GarageDoor_7/config = (retained)
00:00:04 MQT: homeassistant/light/GarageDoor_8/config = (retained)
00:00:04 MQT: homeassistant/switch/GarageDoor_8/config = (retained)
00:00:04 SRC: MQTT
00:00:04 RSL: Received Topic cmnd/GarageDoor/POWER, Data Size 2, Data ON
00:00:04 RSL: Group 0, Index 1, Command POWER, Data ON
00:00:04 MQT: stat/GarageDoor/RESULT = {“POWER”:“ON”}
00:00:04 MQT: stat/GarageDoor/POWER = ON
00:00:04 APP: (UTC) Wed Oct 24 10:01:17 2018, (DST) Sun Mar 25 02:00:00 2018, (STD) Sun Oct 28 03:00:00 2018
13:01:18 SRC: PulseTimer
13:01:18 MQT: stat/GarageDoor/RESULT = {“POWER”:“OFF”}
13:01:18 MQT: stat/GarageDoor/POWER = OFF

That:
00:00:04 RSL: Received Topic cmnd/GarageDoor/POWER, Data Size 2, Data ON
00:00:04 RSL: Group 0, Index 1, Command POWER, Data ON
makes the actual Garage door to open.
It happens also if I reboot the raspberry, but not when I restart HASSIO.

I also removed any configuration, automation, script, etc. related to that sonoff.
No luck.
I have no clue why that MQTT command appears.

Please help.

Thank you,
us

I think this is a retain message issue.
See: https://www.home-assistant.io/components/switch.mqtt/#retain

@Pippyn Thank you for your time.
As I said, there is no switch defined/configured with that name in configuration.yaml

So the switch is added by the mqtt discovery? Then you need to make an entry in the customize.yaml and set the retain flag to true.

edit: never mind, gpbenton is probably right

One of these days, I am going to submit this FAQ to the documents. For the moment can you check it out. FYI, the message is retained in the broker database no matter what is configured in the HA configuration files.

When I connect my light/switch it immediately turns on/off

This is normally because the command topic with a payload of ON has been sent with a retain flag true. This causes the MQTT broker to store the message in its database.

Whenever a client connects and subscribes to that topic, such as when the tasmota becomes available, the broker sends the retained message, so your switch turns on.

To clear the message from the mosquitto database, you need to send a message with that topic and a null payload and the retain flag set.

You can do this with mosquitto_pub using

$ mosquitto_pub -t 'cmnd/sonoff-bn-z1-01/POWER1' -n -r

You may also need parameters for the host (-h), password (-P) and user (-u), depending on your setup.

That makes sense. You could also send an empty message (with the retain flag) on the correct topic using a mqtt client on your pc/mac/phone. I my opion that is the easier route…

Yes, any client should be able to do it.

There is also a way to send an appropriate message from the HA MQTT developer tools page. But I’ll have to figure that out again before I write it up. Something else on my list :grinning:

Guys, a big Thank You.
Not only it works, but I understood what’s going on.

Cheers,
us

2 Likes