[SOLVED] transformationPattern issue with OH 2.4 with new MQTT


After a long struggle I was able to get the new binding up and running however I cannot get the parsing done correctly.
My bridge.things:

Bridge mqtt:broker:mybroker  "mosquitto broker" [ host ="localhost", port=1883, secure=false ]

My sonoff.things:

Thing mqtt:topic:son192  (mqtt:broker:mybroker) { 
        Type switch : outlet            [stateTopic="stat/sonoff192/POWER",   commandTopic="cmnd/sonoff192/POWER", on="ON", off="OFF"]
        Type string : status            [stateTopic="tele/sonoff192/LWT"]
        Type string : uptime            [stateTopic="tele/sonoff192/STATE", transformationPattern="JSONPATH:$.Uptime"]
        Type number : wifi              [stateTopic="tele/sonoff192/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]

My sonoff.items:

Switch sonoff192_Switch     "PowerMeter [%s]"                               (gLA, son192)       { channel = "mqtt:topic:mybroker:son192:outlet"}
String sonoff192_Status_1   "PowerMeter (son192) [%s]"          <check>     (gStatus)           { channel = "mqtt:topic:mybroker:son192:status"}
String sonoff192_Status     "Status [%s]"                       <check>     (son192)            { channel = "mqtt:topic:mybroker:son192:status"}
String sonoff192_Uptime     "Uptime [JS(uptime4.js):%s]"        <clock>     (son192)            { channel = "mqtt:topic:mybroker:son192:uptime"} 
Number sonoff192_Wifi       "Wifi [%d]"                         <antenna>   (son192)            { channel = "mqtt:topic:mybroker:son192:wifi"}

Problem occurs with the WIFI reading, by no means it shows the wifi data, it looks like there is a problem with the transformationPattern. When it is more then 1 level ‘deep’ (like Wifi.RSSI), it does not decode it.

Data captured using mosquitto CLI:

tele/sonoff192/STATE {"Time":"2019-02-01T12:39:19","Uptime":"0T00:05:13","Vcc":3.245,"POWER":"ON","Wifi":{"AP":1,"SSId":"eigenhuis","RSSI":82,"APMac":"06:02:6F:B4:B4:95"}}

Uptime is okay but WIFI can not be decoded/captured, I tried string/number etc but without any luck.

Any ideas?


I have just compared my item against yours and the only difference is that i have %% after the %d.

Number sonoff01_switch_RSSI   "Sonoff01 Switch: RSSI [%d %%]"      { channel="mqtt:topic:sonoff01_switch:sonoff01_switch_rssi" }

Hi Graham,

Yes this is to display the single ‘%’ sign, thanks anyway.
Can you show me the .things file please ?


No problem, this is mine…

Thing mqtt:topic:sonoff01_switch "Dining Room Plug" (mqtt:broker:mosquitto) {
             Type switch : sonoff01_switch "OnOff"                           [ stateTopic="stat/sonoff01_switch/state/POWER", commandTopic="cmnd/sonoff01_switch/cmnd/power" ]
             Type number : sonoff01_switch_temp "Dining Room Temp"           [ stateTopic="tele/sonoff01_switch/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature" ]
             Type number : sonoff01_switch_humidity "Dining Room Humidity"   [ stateTopic="tele/sonoff01_switch/SENSOR", transformationPattern="JSONPATH:$.SI7021.Humidity" ]
             Type number : sonoff01_switch_rssi "Dining Room Plug RSSI"      [ stateTopic="tele/sonoff01_switch/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI" ]
             Type string : sonoff01_switch_lwt "Dining Room Plug LWT"        [ stateTopic="tele/sonoff01_switch/LWT" ]


After a lot of testing and restarting, it looks like it has to do with defining Items:
As soon as it is an number, it cannot be linked anymore to a channel.


Switch sonoff192_Switch     "PowerMeter [%s]"                               (gLA, son192)       { channel = "mqtt:topic:mybroker:son192:outlet"}
String sonoff192_Status_1   "PowerMeter (son192) [%s]"          <check>     (gStatus)           { channel = "mqtt:topic:mybroker:son192:status"}
String sonoff192_Status     "Status [%s]"                       <check>     (son192)            { channel = "mqtt:topic:mybroker:son192:status"}
Number sonoff192_Vcc        "Vcc [%.3f V]"                                  (son192)            { channel = "mqtt:topic:mybroker:son192:vcc"}
Number sonoff192_Wifi       "Wifi [%s %%]"                      <antenna>   (son192)            { channel = "mqtt:topic:mybroker:son192:wifi"}
String sonoff192_Uptime     "Uptime [JS(uptime4.js):%s]"        <clock>     (son192)            { channel = "mqtt:topic:mybroker:son192:uptime"}
Number sonoff192_Today      "Energy Today [%.3f kWh]"                       (son192)            { channel = "mqtt:topic:mybroker:son192:today"}
Number sonoff192_Voltage    "Voltage [%.1f V]"                              (son192)            { channel = "mqtt:topic:mybroker:son192:voltage"}
Number sonoff192_Period     "Energy period [%.3f kWh]"                      (son192)            { channel = "mqtt:topic:mybroker:son192:period"}
Number sonoff192_Current    "Current [%.1f A]"                              (son192)            { channel = "mqtt:topic:mybroker:son192:current"}


Thing mqtt:topic:son192  "Sonoff192" (mqtt:broker:mybroker) { 
        Type switch : outlet        "Output"        [ stateTopic="stat/sonoff192/POWER", commandTopic="cmnd/sonoff192/POWER", on="ON", off="OFF"]
        Type string : status        "Status"        [ stateTopic="tele/sonoff192/LWT"]
        Type number : vcc           "Vcc"           [ stateTopic="tele/sonoff192/STATE", transformationPattern="JSONPATH:$.Vcc"]
        Type string : uptime        "Uptime"        [ stateTopic="tele/sonoff192/STATE", transformationPattern="JSONPATH:$.Uptime"]
        Type number : wifi          "Wifi"          [ stateTopic="tele/sonoff192/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
        Type number : today         "Energy Today"  [ stateTopic="tele/sonoff192/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Today"]
        Type number : voltage       "Voltage"       [ stateTopic="tele/sonoff192/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Voltage"]
        Type number : current       "Current"       [ stateTopic="tele/sonoff192/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Current"]
        Type number : period        "Energy Period" [ stateTopic="tele/sonoff192/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Period"]

frontail (filtered on 192):

2019-02-01 17:06:11.803 [me.event.ThingUpdatedEvent] - Thing 'mqtt:topic:son192' has been updated.
2019-02-01 17:06:23.757 [vent.ItemStateChangedEvent] - sonoff192_Uptime changed from UNDEF to 0T00:10:14
2019-02-01 17:06:23.773 [vent.ItemStateChangedEvent] - mqtt_topic_son192_wifi changed from UNDEF to 82
2019-02-01 17:06:23.776 [vent.ItemStateChangedEvent] - mqtt_topic_son192_vcc changed from UNDEF to 3.244
2019-02-01 17:06:23.817 [vent.ItemStateChangedEvent] - mqtt_topic_son192_voltage changed from UNDEF to 0.0
2019-02-01 17:06:23.829 [vent.ItemStateChangedEvent] - mqtt_topic_son192_current changed from UNDEF to 0.0
2019-02-01 17:06:23.835 [vent.ItemStateChangedEvent] - mqtt_topic_son192_today changed from UNDEF to 0.176
2019-02-01 17:06:34.423 [ome.event.ItemCommandEvent] - Item 'sonoff192_Switch' received command ON
2019-02-01 17:06:34.476 [nt.ItemStatePredictedEvent] - sonoff192_Switch predicted to become ON
2019-02-01 17:06:34.544 [vent.ItemStateChangedEvent] - sonoff192_Switch changed from UNDEF to ON
2019-02-01 17:06:37.807 [vent.ItemStateChangedEvent] - mqtt_topic_son192_voltage changed from 0.0 to 233.5
2019-02-01 17:06:37.810 [vent.ItemStateChangedEvent] - mqtt_topic_son192_current changed from 0.0 to 0.098
2019-02-01 17:06:39.258 [ome.event.ItemCommandEvent] - Item 'sonoff192_Switch' received command OFF
2019-02-01 17:06:39.268 [nt.ItemStatePredictedEvent] - sonoff192_Switch predicted to become OFF
2019-02-01 17:06:39.306 [vent.ItemStateChangedEvent] - sonoff192_Switch changed from ON to OFF
2019-02-01 17:06:41.331 [ome.event.ItemCommandEvent] - Item 'sonoff192_Switch' received command ON
2019-02-01 17:06:41.339 [nt.ItemStatePredictedEvent] - sonoff192_Switch predicted to become ON
2019-02-01 17:06:41.357 [vent.ItemStateChangedEvent] - sonoff192_Switch changed from OFF to ON
2019-02-01 17:08:12.530 [vent.ItemStateChangedEvent] - sonoff192_Status changed from Online to Offline
2019-02-01 17:08:12.533 [vent.ItemStateChangedEvent] - sonoff192_Status changed from Offline to Online
2019-02-01 17:08:21.959 [vent.ItemStateChangedEvent] - sonoff192_Uptime changed from 0T00:10:14 to 0T00:00:13
2019-02-01 17:08:21.965 [vent.ItemStateChangedEvent] - mqtt_topic_son192_wifi changed from 82 to 80
2019-02-01 17:08:21.971 [vent.ItemStateChangedEvent] - mqtt_topic_son192_vcc changed from 3.244 to 3.243
2019-02-01 17:08:22.135 [vent.ItemStateChangedEvent] - mqtt_topic_son192_voltage changed from 233.5 to 234.6
2019-02-01 17:08:22.143 [vent.ItemStateChangedEvent] - mqtt_topic_son192_current changed from 0.098 to 0.105

I’m using JSONPATH in other bindings (MQTT 1.x) and there it works fine.

Any idea’s ?


I made a quick test and it works with MQTTv1 but not with MQTTv2
It also fails silently…

@David_Graeff, any idea?

The log doesn’t help as we do not the see the part where the item linking happens.

Could you please lookup in Paper UI if the channels are indeed linked? We need to find out if it is a binding issue, an openHAB core issue or an xtend .items file parser issue.

Cheers, David

Tnx David,

I just learned (from you) that linking is not automatic although some items were!

Does this mean I ALWAYS have to use PAPER UI to link Items to Channels?

I would rather use text based configurations since this is much easier then 10 mouse clicks and scrolling …


Linking happens when the .item file parser detects those statements: { channel = "mqtt:topic:mybroker:son192:outlet"}. If you misspell channels or the parser encountered any other problems, links will not be created and silently ignored.

I’m not a big fan of those ancient .items files so can’t help any further unfortunately.

Hi David,

Understood, so first create things/channels and then the (correct) items hoping they will be linked automagically …


Hoping isn’t needed, PaperUI will show in any case(configured via file or PaperUI) if a channel is linked to an item!