OH3: Publish String to MQTT from Switch State

Hi All,

As a long time OH user, I’m finally making the transition to OH3. Things are going well but I’m struggling with an issue related to publishing a string to my MQTT broker using switch state and the MAP transformation. I should say that this all worked perfectly well in OH2.5.

I have a 433MHz gateway that receives commands over MQTT and transmits the radio signals to control various items such as wireless outlets for lamps etc. My broker is all set up and working (I am receiving MQTT strings fine and extracting data using REGEX etc). Therefore I know my MQTT thing is working and the various receive channels are all good.

What I’m trying to do is send a string over MQTT based on a switch state. I have a .map file saved in the transform directory that maps ON and OFF to the relevant command strings to turn the specific wireless outlet on or off (worked fine in OH2.5). I have the map file referenced in the MQTT channel in the Outgoing Value Transformation field in the following format:


The channel is linked to a switch. However, monitoring the MQTT traffic, I only see the string “ON” or “OFF” being published to the broker as the switch state changes. This proves that OH3 can publish MQTT strings but clearly that the MAP is not working correctly. I have tried every combination that I can think of including adding the MAP into the switch item.

Any thoughts about what I might be doing wrong? All pointers much appreciated…

If you want to send two different strings depending on the switch item just set on and off value to the strings which shall be sent.

Maybe consider to post the code of your thing…

Don’t forget transformations like MAP are optional add-ons that need to be installed.

Hi Udo,

Thanks for the reply.The .map file does have values defined for ON and OFF as below:


As I mentioned earlier, this is a carry over from a working OH2.5 set up. I don’t believe the content of the map file is the issue. It’s actually that the map file is not being called to do the the transform of the ON and OFF states

Sorry - I got what you mean now. Simpler solution than I expected. Adding the custom values worked perfectly! Thank you

1 Like