Migration from MQTT 1.x to 2.5.1

  • Platform information:
    • Hardware: Intel NUC
    • OS: Debian GNU/Linux 10
    • Java Runtime Environment: openjdk version “1.8.0_232”
    • openHAB version: 2.5.1 (openhabian-config)

I m using Openhab for a couple of years, and recently i migrated to ver. 2.5.1 (from 2.4)
The only thing I cound not migrate was MQTT binding (from 1.x to 2.5.1). (My configuration is working on MQTT 1.x). I searched the forum for similar questions but I couldnt find an answer for this specific problem.

Problem: a simple SWITCH item publishes (on the correct topic) 1/0, instead of ON/OFF.
[Rich Koshak] at some topic suggested to fix this by changing “Custom On/Open Value”/“Custom Off/Closed Value” in PaperUI.
But i would prefer to fix this through text files.

.things definition:

Bridge mqtt:broker:openhab [ host="localhost", secure=false ] {
    Thing topic WaterHeater {
        Type switch : HeaterTurnOn "Turn On Water Heater" [ commandTopic="relay/command", on="ON", off="OFF", formatBeforePublish="%s" ]

and .items

Switch HeaterTurnOn "Turn On Water Heater" { expire="1s,command=OFF", channel="mqtt:topic:openhab:WaterHeater:HeaterTurnOn" }

Here is the karaf output

15:42:15.314 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'HeaterTurnOn' received command ON
15:42:15.326 [INFO ] [arthome.event.ItemStatePredictedEvent] - HeaterTurnOn predicted to become ON
15:42:15.334 [INFO ] [smarthome.event.ItemStateChangedEvent] - HeaterTurnOn changed from OFF to ON
15:42:15.339 [DEBUG] [mqtt.generic.AbstractMQTTThingHandler] - Successfully published value ON to topic relay/command
15:42:17.070 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'HeaterTurnOn' received command OFF
15:42:17.088 [INFO ] [arthome.event.ItemStatePredictedEvent] - HeaterTurnOn predicted to become OFF
15:42:17.093 [INFO ] [smarthome.event.ItemStateChangedEvent] - HeaterTurnOn changed from ON to OFF
15:42:17.097 [DEBUG] [mqtt.generic.AbstractMQTTThingHandler] - Successfully published value OFF to topic relay/command

and here is the mqtt broker (mosquitto) log

mosquitto_sub -v -t '#'
relay/command 1
relay/command 0

How can I post ON/OFF instead of 1/0

Thanks in advance for your time.

Also tried the following:

Type switch : HeaterTurnOn "Turn On Water Heater" [ commandTopic="relay/command", on="ON", off="OFF", transformationPatternOut="MAP:onoff.map" ]

where onoff.map contains:



Type switch : HeaterTurnOn "Turn On Water Heater" [ commandTopic="relay/command", transformationPattern="MAP:onoff.map" ]

and onoff.map


Thank you very much for your response.
I tried it, but it didn’t work.
Then, after reading some post, I cleared cache, and then a total nightmare.
Java errors and stuff.
I ll try to reinstall everything and start from scratch.
Thanks again