MQTT map "on" or "off" to ON/OFF

I think I must be missing something obvious here so apologies in advance.

I have an MQTT interface from my heating boiler to my OH 2.5.4 system (on Ubuntu 20.04) that sends info with the path home/ems-esp/boiler_data with the following format:

{
  "wWComfort": "Hot",
  "wWSelTemp": 55,
  "selFlowTemp": 25,
  "selBurnPow": 32,
  "curBurnPow": 0,
  "pumpMod": 0,
  "wWCurTmp": 27.2,
  "wWCurFlow": 0,
  "curFlowTemp": 48.7,
  "wWActivated": "on",
  "burnGas": "off",
  "heatPmp": "off",
  "fanWork": "off",
  "ignWork": "off",
  "wWCirc": "off",
  "wWHeat": "on",
  "burnStarts": 36567,
  "burnWorkMin": 698583,
  "heatWorkMin": 568260,
  "ServiceCode": "",
  "ServiceCodeNumber": 0
}

Screenshot from MQTT Explorer:

I’d like to map those “on” and “off” values to ON and OFF switch items.

I have to use a things file because using the PaperUI causes my OH system CPU usage to go through the roof and can only be fixed with a service restart. My things file looks like this:

Bridge mqtt:broker:mqttboilerbridge "MQTT Broker Bridge Boiler" [ host="192.168.0.20", port=1883, secure=false, username="openhab", password="password", clientID="openHAB2_boiler" ] 
{
    // Boiler
    Thing topic boilerthing "Boiler" @ "Cellar" {
    Channels:
        Type string :   status              "Reachable"                     [ stateTopic="home/ems-esp/status" ]
        Type number :   tapwater_active     "Tapwater Active"               [ stateTopic="home/ems-esp/tapwater_active" ]
        Type number :   heating_active      "Heating Active"                [ stateTopic="home/ems-esp/heating_active" ]
        // Type string :   wWComfort           "Warm Water Comfort Setting"    [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.wWComfort" ]
        Type string :   wWComfort           "Warm Water Comfort Setting"    [ stateTopic="home/ems-esp/boiler_data/wWComfort" ]
        Type number :   wWSelTemp           "Warm Water Selected Temp"      [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.wWSelTemp" ]
        Type number :   selFlowTemp         "Flow Selected Temp"            [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.selFlowTemp" ]
        Type number :   selBurnPow          "Selected Burner Power"         [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.selBurnPow" ]
        Type number :   curBurnPow          "Current Burner Power"          [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.curBurnPow" ]
        Type number :   pumpMod             "Pump Modulation"               [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.pumpMod" ]
        Type number :   wWCurTemp           "Warm Water Current Temp"       [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.wWCurTmp" ]
        Type number :   wWCurFlow           "Warm Water Flow Rate (L/min)"  [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.wWCurFlow" ]
        Type number :   curFlowTemp         "Flow Current Temp"             [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.curFlowTemp" ]
        Type string :   wWActivated         "Warm Water Activated"          [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.wWActivated" ]
        // Type string :   wWActivated         "Warm Water Activated"          [ stateTopic="home/ems-esp/boiler_data/wWActivated", transformationPattern="MAP:onoff.map" ]
        Type string :   wWActivated2        "Warm Water Activated"          [ stateTopic="home/ems-esp/boiler_data/wWActivated", transformationPattern="MAP:onoff.map" ]
        Type string :   burnGas             "Gas Burning"                   [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.burnGas" ]
        Type string :   heatPmp             "Heat Pump On/Off"              [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.heatPmp" ]
        Type string :   fanWork             "Fan On/Off"                    [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.fanWork" ]
        Type string :   ignWork             "Ignition On/Off"               [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.ignWork" ]
        Type string :   wWCirc              "Warm Water Circulating On/Off" [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.wWCirc" ]
        Type string :   wWHeat              "Warm Water Heat On/Off"        [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.wWHeat" ]
    }
}

I think where I might be stuck is how to use the “JSONPATH:$.burnGas” syntax to get to the relevant value in the MQTT message but also use the MAP:onoff.map to map “on” and “off” to ON/OFF. I tried using the MAP:onoff.map with the wWActivated2 channel but it doesn’t seem to work.

What’s the magic syntax that I’m missing?

Have you searched? Here is my forst guess after searching.

BTW, you need to learn how to properly ask a question here., especially #2, 4, 9, 11

How to ask a good question / Help Us Help You - Tutorials & Examples - openHAB Community

Yes, I looked there, thanks.

You can use your unique ON/OFF values easily with MQTT2 binding, no need of any transformation service.
So for example:

        Type switch :   burnGas             "Gas Burning"                   [ stateTopic="home/ems-esp/boiler_data",  on="on", off="off", transformationPattern="JSONPATH:$.burnGas" ]

This will create a Switch item, not a String item, properly using ON/OFF states when on/off state is received.
Ps.: Sorry, I deleted the transformationPattern, but that one is needed.

OK, you did not say that originally.

I thought I needed to use the transformation to access the correct element of the boiler_data node of the MQTT message. In the screenshot from MQTT Explorer I included in the OP you can see that, for example, the wWActivated node is within /home/ems-esp/boiler_data and that is why I needed this transformation:

transformationPattern="JSONPATH:$.wWActivated"

However, I just added your suggestion into the channel definition like this:

Type switch : wWActivated "Warm Water Activated" [ stateTopic="home/ems-esp/boiler_data", transformationPattern="JSONPATH:$.wWActivated", on="on", off="off" ]

And it works!

The corresponding item definition is:

Switch BoilerGasBurning "Gas Burning [%s]" (Boiler) { channel="mqtt:topic:mqttboilerbridge:boilerthing:burnGas" }

Thank you so much! :smile:

Great, yes I accidentally deleted the transformationPattern, but that one is needed.

Anyway I would look into why PaperUI is not working properly…

Ok, cool, that explains it. I was a bit confused but only for a short while (for a change). :slight_smile:

The PaperUI issue seems to be a well known issue and one of those elusive bugs that is difficult to reliably recreate and doesn’t affect everyone. Sometimes within minutes of starting the PaperUI the java heap space is exhausted, sometimes it happens after a number of hours. There’s nothing obvious in the logs. Anyway, that’s a problem for a different thread.

Thanks again for your help, all it takes is someone with the right knowledge to post a few lines and the issue I’ve been wrestling with for ages is solved! :slight_smile:

The Paper UI is only for administering OH. Use sitemaps & the Basic UI for daily use.

I don’t understand this. Who said that anyone want to use it for anything else?

So, what isn’t working properly then? That UI has already been removed from OH3.

Read the first post again, carefully…

1 Like