Home Assistant cant read actual status of tasmota sonoff switch

I have fresh installation of Home Assistant and fresh flash of sonoff basic switch:

Sonoff-Tasmota 6.7.1 on sonoff basic (tried sonoff.bin and also sonoff_basic.bin)
Home Assistant 0.101.2 on raspberri PI 4

Here is my config of switch and mqtt in configuration.yaml:

mqtt:
    password: !secret mqtt_password

switch:
    - platform: mqtt
      name: "sonoff6283"
      state_topic: "stat/sonoff-6283/RESULT"
      value_template: '{{ value_json["POWER1"] }}'
      command_topic: "cmnd/sonoff-6283/POWER"
      availability_topic: "tele/sonoff-6283/LWT"
      qos: 1
      payload_on: "ON"
      payload_off: "OFF"
      payload_available: "Online"
      payload_not_available: "Offline"
      retain: true

and here is config of switch

When I click on the switch in main dashboard to turn it on

giP3mE1noJWQhEIRtj5K1iaJRlS.png

switch will power ON but the button after few seconds will have “OFF” status again, but switch is still ON … when I click the button two times and fast, switch will power off

I am receiving the topic to home assistant correctly:

Listen to a topic
Topic to subscribe to
stat/sonoff-6283/RESULT
 
Message 1 received on stat/sonoff-6283/RESULT at 19:24:
{
    "POWER": "OFF"
}
QoS: 1 - Retain: false
Message 0 received on stat/sonoff-6283/RESULT at 19:24:
{
    "POWER": "ON"
}
QoS: 1 - Retain: false

Also I am able to set status via MQTT “Publish a packet” function without problems

But cant see real status of the switch (it all the time appears to be OFF)

Can you help me find the problem please? Hope you understand my issue, if not i can upload a video or something…

Thanks :slight_smile:

EDIT: video with my issue here https://youtu.be/_VzYji69-18

I am a beginner in MQTT, but in hass the sonoff-tasmota devices published changing of their states, after I did this:

Enter the following commands in the web console (tasmota - device):
SetOption19 1 - Enables MQTT discovery\

2 Likes

thanks for idea but if i set this, device is no longer available in home assistant :confused:

Your state topic should not be RESULT. it should be

stat/sonoff-6283/POWER

The payload of RESULT is not on or off, it’s a JSON string.

1 Like

Here’s my standard YAML for just about every TASMOTA switch or light I have:

switch:
  - name: ensuite_fan
    platform: mqtt
    state_topic: stat/EnsuiteFan/POWER
    command_topic: cmnd/EnsuiteFan/POWER
    availability_topic: tele/EnsuiteFan/LWT
    qos: 1
    payload_on: 'ON'
    payload_off: 'OFF'
    payload_available: 'Online'
    payload_not_available: 'Offline'
    retain: false

I noticed you also have retain set to true. You probably don’t want that unless you have a good reason. When you set retain in Home Assistant for an MQTT light or switch, it retains the commands. You usually only want to retain the states.You can get TASMOTA to send retained state messages for power by issuing the command “PowerRetain ON” from the console, or via MQTT with cmnd/topic/PowerRetain ON.

1 Like

If you setoption19 on - that enables MQTT discovers and it changes the topic… eg:
sonoff-6283/stat/POWER
So your manually configured switches will disappear. Even if you turn discovery off it won’t revert the topic - you will need to do that in Tasmota seperately.

Your problem is probably because you set retain: true. That screws everything up.

I personally don’t have any manually configured switches and I don’t have a mqtt: section either as it’s not required for the Hass.io broker. I use MQTT discovery and when I set the option they all just pop up in HA.

It seems like this might be a better route for you here.

Incidentally, the username you have used for Tasmota - homeassistant is a reserved username in the latest (v4+ versions of the broker)

1 Like

thank you very much guys :slightly_smiling_face: without retain and with proper state_topic my switch is working like a charm :heart_eyes:

I have exactly the same issue as @dvdrw15 describes, but I’m using the autodiscovery MQTT-feature:

The binary_sensor.so_s_100_b2 (name of my entity) turns on for 2-3 seconds when I push the button in either direction, but then flips back to off.

Is it possible to also use retain: false whilst autodiscovery is enabled or do I have to switch over to manual config for the expected behavior? If yes, where could I change the retain-flag?

I found the solution: I had to change the settings on the tasmota-config: Configuration -> Configure Template -> **GPIO4** Switch2 (10). Now the state of the switch is displayed correctly in Home Assistant for the external switch.