Strange Exception while transforming JSON from MQTT message

mqtt
jsonpath
sonoff
Tags: #<Tag:0x00007f6ce8ae4028> #<Tag:0x00007f6ce8ae3e70> #<Tag:0x00007f6ce8ae3cb8>

(Frank Kintrup) #1

Hello,

I’ve encountered a strange Exception while trying to receive the current power from a Sonoff POW via MQTT.
MQTT itself is running perfectly as are all other transformations via JSONPATH.

This is the exception:

2018-02-12 23:07:18.814 [ERROR] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: An error occurred while transforming JSON expression.
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) [208:org.openhab.core.compat1x:2.2.0]
	at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:138) [226:org.openhab.binding.mqtt:1.11.0]
	at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:556) [210:org.openhab.io.transport.mqtt:1.11.0]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) [210:org.openhab.io.transport.mqtt:1.11.0]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) [210:org.openhab.io.transport.mqtt:1.11.0]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) [210:org.openhab.io.transport.mqtt:1.11.0]
	at java.lang.Thread.run(Thread.java:748) [?:?]

This is my items definition (broken in two lines for readability):

Number sonoff_washer_power "Power: [%.1f W]" (group_sonoff)
   { mqtt="<[mosquitto:sonoff_washer/tele/ENERGY:state:JSONPATH($.ENERGY.Power)]" }

and this is the JSON payload of the MQTT message “sonoff_washer/tele/ENERGY”:

{"Time":"2018-02-12T23:07:15","ENERGY":{"Total":1.016,"Yesterday":0.016,"Today":0.014,"Period":0,"Power":0,"Factor":0.00,"Voltage":234,"Current":0.111}}

A very similar JSONPATH transformation works absolutely fine:

Number sonoff_washer_power2  "Power: [%.1f W]" (group_sonoff)
    { mqtt="<[mosquitto:sonoff_washer/stat/STATUS8:state:JSONPATH($.StatusSNS.ENERGY.Power)]" }

JSON payload:

{"StatusSNS":{"Time":"2018-02-12T21:10:19","ENERGY":{"Total":1.014,"Yesterday":0.016,"Today":0.012,"Period":0,"Power":1,"Factor":0.08,"Voltage":230,"Current":0.081}}}

I don’t know how often I checked the syntax of my items definition and found nothing wrong. I copied from the working example multiple times, carefully replacing the relevant parts. But to no avail, the exception is very stable :roll_eyes:

This one works, but it’s obviously not what I want :wink::

String sonoff_washer_power3 "%s" (group_sonoff)
   { mqtt="<[mosquitto:sonoff_washer/tele/ENERGY:state:default]" }

Has anyone an idea what’s wrong?


(Frank Kintrup) #2

I’m somewhat baffled :face_with_raised_eyebrow:
I did not change a thing since yesterday, no reboot of openHAB or the MQTT broker or the Sonoff, nothing, and now the exception is gone and I receive the correct value.

Posting in this forum alone seems to have healing powers :smiley: