MQTT Channel Configuration

Hello All,

Just upgraded to OH 3.2.0 (Docker) and using Mosquitto (Docker) for MQTT server.

I’m in the process of adding some functionality of my pool controller into OH using MQTT and thought I would ask for a sanity check on an MQTT Channel that uses both state and command topics.

The message I’m receiving in the stateTopic is: {“id”:4,“isOn”:“off”}.
For the commandTopic I’m replicating the JSON format.

Here is the channel code:

id: spalight
    channelTypeUID: mqtt:switch
    label: Spa Light
    description: ""
    configuration:
      commandTopic: intellicenter-i10ps/state/circuits/setState
      formatBeforePublish: '{"id":4,"isOn":"%s"}'
      stateTopic: intellicenter-i10ps/state/circuits/4/spalight
      transformationPattern: JSONPATH:$.isOn
      off: off
      on: on

This is appears to be working fine. The only potential issue is when I turn the light on from OH, I also receive the response from the stateTopic, is this normal behavior?

Any feedback on how to better set this up would be much appreciated.

Yes. The end device almost certainly reports that it has changed state on the stateTopic regardless how why it changed state. That state topic is supposed to represent the device’s current state. When the device changes state, it publishes a message with that new state.

You could disable Autoupdate on the Item linked to this Channel and the Item won’t change it’s state in response to the command until that state message is received. It’s one of the well known Item metadata that can be set from the Item’s page.

1 Like

Perfect, thank you Rich!