MQTT switch not working

I’m very new to HA and have started down the rabbit hole but ran into some issues… hopefully someone here can help.

I’ve set up my RPi HA with a MQTT broker and Smartthings bridge. I’ve got a z wave contact sensor working (reports open/close) while testing but have not been able to get a switch to work. I have following in my yaml:

switch:

  • platform: mqtt
    name: “Office Lights”
    state_topic: “smartthings/Office Lights/switch”
    command_topic: “smartthings/Office Lights/switch”
    payload_on: “on”
    payload_off: “off”
    retain: true**

I’m not sure I fully understand ‘Topics’ fully and feel this may be where the problem lies. I can see in the logs for this switch coming back with the following when I manually use the switch:

info: Incoming message from SmartThings: smartthings/Office Lights/switch/state = off

info: Incoming message from SmartThings: smartthings/Office Lights/switch/state = on

At this point, I can see the switch in my HA Dashboard, but the toggle does not work and I see no command being sent in the logs when I use the toggle. Any advice is greatly appreciated!

I have no idea, i’m in the same boat as you but… i would try
`

state_topic: “smartthings/Office Lights/switch/state”

`

see what happens

edit… the “Office Lights” part looks strange, i don’t know if you can get away with a space inbetween

I tried that and it still does not work. I’m not sure if the path 'smartthings/Office Lights/… it correct. I just guessed. How would I verify this? I just used the ‘Office Lights’ because that’s what it is named in Smartthings.

You might want to find some MQTT tool you can run from some other system to monitor the MQTT topic and see what’s actually being sent to the relevant topics. You’ll save a lot of time wondering/speculating on what’s going on.

I believe that’s a Chrome browser app that can do this, but I just cooked up a small python program that I run from the shell for that purpose.

I managed to get the subscribe command to work when SSH into the RPi. I can see it sending ‘smartthings/Office Lights/switch/state (off/on)’ when I toggle the switch from HA and ST. I’m stumped…

This is what should be in the state_topic: section. When you restart, HA subscribes to that topic, and matches the payload to either on or off. People have also reported better results by not having quotes on the payload lines.

I just managed to figure it out…

light:

  • platform: mqtt
    name: “Office Lights”
    state_topic: “smartthings/Office Lights/switch/state”
    command_topic: “smartthings/Office Lights/switch/cmd”
    payload_on: “on”
    payload_off: “off”
    retain: true

The command_top needed to have ‘cmd’. I just happened to find an example using that and got lucky… How would I have known to use ‘cmd’ for future reference?

Presumably there is some smartthings documentation that will tell you what it expects.

Interesting… I’ll have to do some searching… Hours have been wasted chasing this and that documentation would be helpful (if it exists). Thanks for the help!