Mqtt + Sonoff Will not toggle

Using the directions here I installed the updated firmware on my sonoff device
In my configuration.yaml. I have
platform: mqtt
name: “2nd Floor Hall Sonoff”
state_topic: “home/sonoff/2ndhall/1/stat/POWER”
command_topic: “home/sonoff/2ndhall/cmnd/power”
qos: 1
payload_on: “ON”
payload_off: “OFF”
retain: true

My soniff mqtt configuration is

Watching the device, during HA restart i see

mosquitto_sub -u sonoff -P <hidden> -v -t \#

home/sonoff/2ndhall/1 ON
tele/home/sonoff/2ndhall/1/LWT Online
cmnd/2ndhall/POWER ON

My in my HA screen i have a switch which stays in the off position. When I toggle it on, It switches for a second, then back to off. There is no change on the state of the physical device.
sonoff2

the mqtt log shows

home/sonoff/2ndhall/cmnd/power ON
home/sonoff/2ndhall/cmnd/power ON

I can’t figure out why.

This is my working config

mqtt:
  broker: 192.168.x.xxx
  port: xxxxxx
  client_id: home-assistant-1
  keepalive: 60
  username: xxxxxx
  password: xxxxxxx
  protocol: 3.1
  birth_message:
    topic: "tele/sonoff/LWT"
    payload: "Online"
    qos: 1
    retain: true
  will_message:
    topic: "tele/sonoff/LWT"
    payload: "Offline"
    qos: 1
    retain: true



#####################
# SONOFF switches   #
#####################


- platform: mqtt
  name: "Sonoff"
  state_topic: "stat/sonoff/POWER"
  command_topic: "cmnd/sonoff/POWER"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  retain: true

It is strange to have these topics as the birth and will message of HA. Normally, you would want something to indicate the HA was alive or not.

Based on your setup. This is my config now and it works. I guess all the other places I pulled code from dont seem to work right.

platform: mqtt
    name: "Sonoff1"
    state_topic: "stat/sonoff1/POWER"
    command_topic: "cmnd/sonoff1/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

Same advice as always, USE THE BASIC SETUP IN THE GUIDES AND MAKE SURE IT WORKS BEFORE ADLIBBING WITH YOUR OWN CODE!

That said, you have a /1 missing in the command topic and they’re supposed to be in the format…

state_topic: “stat/topic/POWER”
command_topic: “cmnd/topic/POWER”

anyone mind if i high jack this thread?

I’m struggling to get the switches to connect to the embedded MQTT
Can someone please explain how the topic works? I’ve read numerous conflicting posts

I have numerous sonoff switches - so using sonoff as the topic for all of them would surely kick each other off it they ever connected? Unless i’m missing something?

Right now in my config.yaml:
mqtt:

then on the switch:
Host: [IP of MQTT broker / HASSIO]
Port: 1883
Client: DVES_A4B30E
user: homeassistant
pass: xxxxxxxxxxxx
Topic: Studio_Right_Front_Light
Full Topic: lab/%topic%

I can control the lights etc from the console via the switches IP, so all good there - just scratching my head now!

All/any help welcomed :slight_smile: thanks