Sonoff-tasmota Basic is switching OFF after switching ON

Hi, I am new to HA. My setup is a RPi3 with Hassbian with Mosquitto MQTT and some Sonoff switches using sonoff-tasmota firmware (v 5.14.0). Try to switch from openHAB to HA (these switches where working under openHAB)

The problem i have is that when i switch on the light from HA, the switch in HA goes off after one second. Following the MQTT-process from the command line, i do not see an mqtt switch off command!

When i installed Mosquitto i checked the working wit two terminal sessions with resp mosquitto_pub and mosquitto_sub commands. This was working.
Second i userd mqtt.publish from the Developer tools window. This is the command i used:
{
“topic”: “tasmota/Sonoff_4S20/cmnd/power”,
“payload”: “ON”
}
This was also working perfectly! The ON command leaves the sonoff on, as it should. The OFF command does the job for switching off. But not from the HA browser window…

The configuration of mosquitto broker in configuration.yaml is:

Mosquitto broker

mqtt:
broker: 192.168.178.56
port: 1883
client_id: home-assistant-1
keepalive: 60
username: ########
password: ########
protocol: 3.1
birth_message:
topic: “tele/hass1/LWT”
payload: “Online”
qos: 1
retain: true
will_message:
topic: “tele/hass1/LWT”
payload: “Offline”
qos: 1
retain: true
(for some reason, the indentation is missing in the posted version, but it is there!)

The configuration of the Sonoff switch is:
switch:

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

I tried this also with retain: true.
Also in the in the Tasmota config to use PowerRetain OFF and ON, which i found somewhere in an other topic. Non of these helped.

Please, is there anyone who can help me with this issue?
Kind regards, Bert

{
“topic”: “tasmota/Sonoff_4S20/cmnd/power”,
“payload”: “ON”
}

is not the same as

I’d start there.

Thank you @forsquirel for your reaction.
Unfortunately that did not make any difference:
image
Gives this result:

And the Sonoff device reacts as it should; It needs an other --OFF command to switch off.

I think it is something in the configuration in HA for the Sonoff device, because bare MQTT commands work as it should. But i can’t see what…
BTW, in configuration.yaml there are capitol letters used…

The button returns to its previous state because it does not receive a status message matching the state_topic: and payload, so HA decides that the switch didn’t happen.

Looking at your trace it looks like the status came back in a message

stat/Sonoff_4S20/POWER ON

so you should have

state_topic: "stat/Sonoff_4S20/POWER"

Hi,

Didnt the tasmota changed the “POWER” to “POWER1” ? I had to change my configuration to use “POWER1” topic after upgrading my sonoffs.

@gpbenton Yes!!! you are absolutely right! That was the fault. I did expect it to be something like this (reading other topics here). But i was blind to see this in the tty session…
However, i do not know quite why the syntax should be like this. I am using the by Theo Arends adviced mqtt topic configuration: tasmota/%topic%/%prefix%/

So i did use this also for the state-topic, as for both power (switch) topics.
But changing only this state_topic to your suggestion, did work (leaving the command_topic and availability_topic as it was).
However, I do not understand why the broker is sending this (stat/Sonoff_4S20/POWER ON) result in the terminal session…

I can’t explain this, and that bothers me a bit.
But i am very happy that it is working now! Thank you very much!
Kind regards, Bert

1 Like

You should remove ‘retain: true’ or make it retain:false. This tends to cause odd behavior for sonoff switches.

Hi I have 2 Sonoff tasmotized deceives added to Home assistant
I am using Mosquito MQTT broker.

Switch 01 is Sonoff basic & works fine from HA panel (No issues)

Switch 02 is Sonoff S26 Smart Socket tasmotised.
Problem with Switch 02:
It automatically swich OFF after a few minitues when activated from HA panel.

In Tasmato web UI console:
“PowerRetain”:“ON”
“PowerOnState”:1
(Both Sonoff’s have same above settings)

Below is my Configuration.yamal for both switches:

Blockquote# Enables the frontend
frontend:
mqtt:
broker: core-mosquitto
username: XXXX
password: XXXXXX

switch 01:
platform: mqtt
name: “Mirror Light”
command_topic: “cmnd/sonoff00/power”
state_topic: “stat/sonoff00/POWER”
qos: 1
payload_on: “ON”
payload_off: “OFF”
retain: false

switch 02:
platform: mqtt
name: “Smart Plug”
command_topic: “cmnd/sonoff01/power”
state_topic: “stat/sonoff01/POWER”
qos: 1
payload_on: “ON”
payload_off: “OFF”
retain: false

If i disable MQTT details in Tasmoto web UI. & control the switch either manually or thru tasmoto UI (ON/OFF) the switch/ socket works like a charm no issues.

Please help to resolve the issue
What am i missing wrong?

Alternatively, if you want to use the legacy “Power” without the “1” postfix, all you need to do is type “SetOption26 0” at the serial console, and it will go back to the legacy configuration

1 Like

I think when I updated I assumed this would happen, updated my configuration and then my switches stopped working. Then I re-read it and I think it was only if the sonoff had more than one switch in it… in any case, I went back to power for both switches and it all worked again.

If that’s the case both Switch Shouldn’t work right?
How Switch 01 working fine but Not Switch 02

Please clarify

I had issues with tasmota sonoff basic switching on by its self or off by its self. I fixed this by switching from the official mqtt to the community mqtt.

I also had an issue with the sonoff basic flicking on off a number of times a day. I fixed this by following drzzs vid to stop ghosting with a cap and resistor.