General MQTT Configuration, how do you figure out command, state topics?

I’ve been stumbling through a hass.io setup and am getting closer but have been trying to get MQTT to work correctly for a couple hours now and can’t seem to figure it out. Any assistance would be greatly appreciated! I think the only problem I’m having now is an inability to figure out how to set up MQTT switches

I’ve installed hass.io, and I’m trying to get Home Assistant to play with my SmartThings hub.

I installed Mosquitto, SmartThings MQTT Bridge, and the necessary SmartThings Smart App and Device.

I think all of the configuration is sound. I refreshed to clear the log in SmartThingsBridge, and here’s what is shows:

starting version 3.2.2
info: Starting SmartThings MQTT Bridge - v1.3.4
info: Loading configuration
info: Loading previous state
info: Perfoming configuration migration
info: Saving current state
info: Connecting to MQTT at mqtt://172.17.0.1:1883
info: Configuring autosave
info: Configuring API
info: Listening at http://localhost:2080

When I press a button in the SmartThings app to turn off a light called Reading Light, I see this in the SmartThingsBridge log:

info: Incoming message from MQTT: smartthings/Reading Light/switch/cmd = OFF
info: Incoming message from SmartThings: smartthings/Reading Light/switch/state = off

When I switch it back on again, there is only the message from SmartThings not from MQTT:

info: Incoming message from SmartThings: smartthings/Reading Light/switch/state = on

My problem is, I can’t seem to figure out how to configure my switches. I’ve tried an awful lot of variations, this is what I’m currently on:

switch:
  - platform: mqtt
    name: "Reading Light"
    command_topic: "smartthings/Reading Light/switch/state/set"
    state_topic:  "smartthings/Reading Light/switch/state"
    qos: 1
    payload_: "on"
    payload_off: "off"
    retain: true

How do I figure out what the command_topic and state_topic are? I’ve tried all kinds of variations, from switch/cmd to switch/state to switch/ to switch/state/cmd, I just don’t know how we’re supposed to figure these out?

No matter what i’ve tried, the light does not respond when I press the switch in the HA dashboard, and the switch in the HA dashboard does not respond when I press the switch by other means.

Am I missing something obvious? I’ve tried a lot of searching but can’t seem to figure out what I’m doing wrong here.

In case it’s important, here’s my mqtt config:

mqtt:
  broker: core-mosquitto
  port: 1883
  client_id: hassio
  keepalive: 60
  discovery: true
  discovery_prefix: smartthings

Discovery doesn’t seem to work for me, at least it isn’t righting to any config files that I can tell.

Thanks in advance!

I wouldn’t use the smart things logs - it’s not clear exactly what the topic is and what the payload is. Run a separate MQTT client somewhere (anywhere). If you have mosquitto installed, run:

mosquitto_sub -v -t '#'

which will print the topic and payload for every MQTT message going through the broker (you can change the # to something like smarthings/# to limit it further. You may need to add host and port inputs (mosquitto_sub --help) if you’re on a different machine. Then trip the switch on and off and see what it’s broadcasting. That will tell you the state updates that it’s sending - but not the command topic to change the switch from HA. Either find the docs for the the switch somewhere or use the smarthings app to send a command to the switch from somewhere else and look at the logs, that should give you the command topic and payload that are needed.

If you use chrome you can use mqtt lens or mqtt box to see the topics using # as the topic.

Thank you so much for the replies! I spent some time debugging with mosquitto_sub and mqttbox this morning and got things working. So far anyway. Now on to the next thing!