New Setup: Sonoff switch not toggling on

I am rebuilding my HA setup, running Home Assistant on Docker and the Mosquito Docker container as well.

My configuration.yaml file currently looks like this:

mqtt:
  broker: 192.168.87.190
  port: 1883
  username: !secret mqtt_username
  password: !secret mqtt_password

switch:
  platform: mqtt
  name: "Sonoff Passage 1"
  command_topic: "cmnd/sonoff_t1_passage/POWER1"
  state_topic: "stat/sonoff_t1_passage/POWER1"

Then on my T1 Sonoff Switch that has been flashed with Tasmota I have setup the MQTT as such:

On the console within my Tasmota device it doesn’t look like there are any issues:

Going back to Home Assistant I can see the Switch on my Overview page:

When I click to toggle it moves, and a second later moves back - without have changed the state of the light at all. Switching the light on in the Tasmota GUI of the switch works, but doesn’t update the state on the HA page.

What am I missing, or what other information can I provide to help?

Go to developer tools -> mqtt. Enter # under listen to a topic, and click ‘Start Listening’

image

Now switch the light on and off from the Tasmota Gui. What do you see now under ‘Start Listening’ ?

Looks like the messages are coming through:


Message 6 received on sonoff_t1_passage/stat/POWER1 at 4:08 PM:

OFF

QoS: 0 - Retain: false
Message 5 received on sonoff_t1_passage/stat/RESULT at 4:08 PM:

{
    "POWER1": "OFF"
}

QoS: 0 - Retain: false
Message 4 received on sonoff_t1_passage/tele/STATE at 4:08 PM:

{
    "Time": "2020-04-14T16:08:27",
    "Uptime": "0T00:40:50",
    "UptimeSec": 2450,
    "Heap": 27,
    "SleepMode": "Dynamic",
    "Sleep": 50,
    "LoadAvg": 19,
    "MqttCount": 2,
    "POWER1": "OFF",
    "POWER2": "OFF",
    "POWER3": "OFF",
    "Wifi": {
        "AP": 1,
        "SSId": "OMG-Home",
        "BSSId": "7A:8A:20:DD:CB:19",
        "Channel": 13,
        "RSSI": 60,
        "LinkCount": 1,
        "Downtime": "0T00:00:05"
    }
}

QoS: 0 - Retain: false
Message 3 received on sonoff_t1_passage/stat/POWER1 at 4:08 PM:

ON

QoS: 0 - Retain: false
Message 2 received on sonoff_t1_passage/stat/RESULT at 4:08 PM:

{
    "POWER1": "ON"
}

QoS: 0 - Retain: false
Message 1 received on sonoff_t1_passage/tele/STATE at 4:08 PM:

{
    "Time": "2020-04-14T16:08:18",
    "Uptime": "0T00:40:41",
    "UptimeSec": 2441,
    "Heap": 27,
    "SleepMode": "Dynamic",
    "Sleep": 50,
    "LoadAvg": 19,
    "MqttCount": 2,
    "POWER1": "ON",
    "POWER2": "OFF",
    "POWER3": "OFF",
    "Wifi": {
        "AP": 1,
        "SSId": "OMG-Home",
        "BSSId": "7A:8A:20:DD:CB:19",
        "Channel": 13,
        "RSSI": 62,
        "LinkCount": 1,
        "Downtime": "0T00:00:05"
    }
}

QoS: 0 - Retain: false
Message 0 received on sonoff_t1_passage/tele/LWT at 4:08 PM:

Online

QoS: 0 - Retain: true

You configure your switch as :

switch:
  platform: mqtt
  name: "Sonoff Passage 1"
  command_topic: "cmnd/sonoff_t1_passage/POWER1"
  state_topic: "stat/sonoff_t1_passage/POWER1"

But the messages don’t match :

sonoff_t1_passage/stat/POWER1

Try :

switch:
  platform: mqtt
  name: "Sonoff Passage 1"
  command_topic: "sonoff_t1_passage/cmnd/POWER1"
  state_topic: "sonoff_t1_passage/stat/POWER1"

Oh my, that’s what happens when you read tutorials and don’t double check. Thanks so much @francisp

Another question if I may, is there any reason to set the commented out values in the below?

switch:
  platform: mqtt
  name: "Sonoff Passage 1"
  command_topic: "sonoff_t1_passage/cmnd/POWER1"
  state_topic: "sonoff_t1_passage/stat/POWER1"
  # qos: 1
  # payload_on: "ON"
  # payload_off: "OFF"
  # retain: true

Never use retain: true, it causes unpredictable behavior.
Payload_on / payload_off is not necessary as that is the default.
qos : I never set it, but you can read more about it here :

https://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels/

1 Like

The default is 0 (spray and pray). Which should be fine for an uncongested local network.

I have a similar issue (TH16), my setup is similar to above however the switch will toggle on but not off… I have to hold and then use the little toggle and switch it on and then off again to get it to go off.