MQTT ESP8266 Issue (Running Tasmota)

Hi, am having issues with the HA dashboard and some ESP8266’s with Tasmota installed.
If the switches are controlled manually then the state updates in HA via MQTT and everything looks normal.
if the switches are toggled in HA then the action is performed via MQTT but the state quickly toggles back to the original. It’s as if HA isn’t receiving the state back from the device.
It’s puzzling me as the state updates correctly in HA if I control the switches manually or by using homebridge, which again works perfectly. Here is a screenshot -

- platform: mqtt
  name: "bedroom"
  state_topic: "stat/sonoff-bedroom/POWER"
  command_topic: "cmnd/sonoff-bedroom/power"
  qos: 0
  payload_on: "ON"
  payload_off: "OFF"
  optimistic: false
  retain: true

MQTT setup on switch as follows:

Any help would be greatly appreciated as I’m going crazy trying to figure it out!

Have you tried:

  state_topic: "stat/sonoff-bedroom/POWER"
  command_topic: "cmnd/sonoff-bedroom/POWER"

Upper and lower case matters.

Yes I’ve tried every possible combination of uppercase and lowercase between the two but with no luck :frowning:

Gif Link <<

I have seen this before on one of my sonoffs. Have you checked the PowerRetain setting on your sonoff? IIRC it should be configured as ‘On’

have a read up on https://github.com/arendst/Sonoff-Tasmota/wiki/Home-Assistant as it has an example configuration in the WiKi which I found useful and
as Lxz says, turn on the power retain setting and I usually set QOS to 1. I notice you have changed the client id, I have always left mine as the default DVES_%06X and that there are both stat/Sonoff-bedroom and stat/bedroom in the console output. have you restarted the sonoff?

yeah open the tasmota web gui, goto console, and then type PowerRetain 1

This is my working Configuration.yaml entry

switch:

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

It is a little different to yours hope this helps

Thanks - this did the trick :smiley:

Thanks everyone else too - working perfectly now

1 Like

I’m experiencing the same thing and I tried all of the above (power retain, console matches the command, etc…)

No matter the config, the switch keeps bouncing back to off in the HA frontend.

image

(that first power is lowecase atm for trying out stuff, but usually it’s uppercase)

I had this problem, and it was fixed when I reset the topic at the bottom of the mqtt page back to default.

Where exactly? In the sonoff’s web ui? Here?

What should I do if I have more than one sonoff then?

(Also, just tried it, didn’t work.)

FWIW, i have several SONOFFs running tasmota and this is how they’re all configured:

(also i enabled powerretain on all of them)

- platform: mqtt
  name: "Porch Door Lights"
  state_topic: "stat/sonoff1155/POWER"
  command_topic: "cmnd/sonoff1155/POWER"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  retain: true
- platform: mqtt
  name: "Porch Jar Lights"
  state_topic: "stat/sonoff1681/POWER"
  command_topic: "cmnd/sonoff1681/POWER"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"

What broker are you using? I have the same setup and seeing the same problem.
Maybe its an issue with the embedded broker?

I’m using stand-alone mosquitto (I’m not running hass.io)

Seems like this thread is exactly my issue: Sonoff with embedded mqtt

Hi Richard
You say this did the trick , what did the trick to sort your problem out thanks
Struggling with the same problem.

Thanks

I believe it was changing the client ID back to the default one that resolved it for me. But it could have been that coupled with a number of other points in this post like changing the QoS and formatting my yaml like one of the examples.

Hope you get it sorted.

1 Like