OH3 MQTT state topic


I upgraded my Openhab2 to Openhab 3 and now have to re create all the MQTT stuff.
I have a device that sends its state as 0 for off and 1 for on. I have a map file called onoff.map that I used in OH2 that worked 100%. So how do I configure the new MQTT thing to look at that mapping?

This was the setup in OH2

Switch gate “Pedestrian Gate” [Switchable]
{mqtt=“>[broker:GateControl/Command:command:ON:U1 0],
>[broker:GateControl/Command:command:OFF:U2 0],

So I send a U1 0 for on and then the device will send back a 1 on the state topic. Then after 3 seconds it will send a 0 on the state topic. How do I use the map file or do I have to do something else now?

This does not work. The state does not update.


Please do not post screenshots. Copy the code and paste it using the code tags.

You did not set a StateTopic, that way no reported state could be received by the channel.


There is a state topic. “Gate/Relay1State”

UID: mqtt:topic:c92e3237df:ce6f4bee85
label: Pedestrian Gate
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:c92e3237df
  - id: PedestrianGate_Channel
    channelTypeUID: mqtt:switch
    label: PedestrianGate_Channel
    description: ""
      commandTopic: GateControl/Command
      TransformationPattern: MAP:onoff.map
      stateTopic: Gate/Relay1State
      off: U2 0
      on: U1 0

Ups! Sorry, I missed that line on the screenshot.

It doesn’t really make sense to use both a transformation and setting the off and on properties. Usually it’s either or. The off/on properties would normally replace your onoff.map.

I’m not sure what having both would do. This might be the confusion. The off/on properties are for incoming messages, not outgoing messages IIRC. But rereading the docs makes me wonder if I’m wrong on that.

Also, on my system at least, it’s transformationPattern (notice the lowercase ‘t’). I’m not sure if that causes problems but usually OH is case sensitive. That’s for the incoming message transformation. You want to transform the outgoing messages (if I understand your MQTT 1.x config correctly).

So I recommend the following:

  1. Fix that “transformationPattern” entry and double check that your map file is configure to translate the incoming messages only. Verify whether that fixes it or not. If not proceed to 2.

  2. Remove the on/off properties and replace that with a transformationPatternOut property (i.e. outgoing transformation pattern) with a MAP file that maps ON/OFF to U1 0 and U2 0.

The good news here is it will work. We just need to get the incoming and outgoing stuff straightened out.

1 Like


This works 100% in OH2. The on / off is outgoing as the gate will buzz open when the value U1 0 is sent to it. The only thing not happening is the translation between 0 to Off and 1 to On, on the status topic to update the control in the UI.

OK great it was the uppercase T.
Thanks for that.

If you configured this Thing using the UI, that capital ‘T’ should have never happened. So there is a bug somewhere in the binding that needs to be fixed. If it was a copy/paste/edit error or the like then take extra care on the case of the letters.