Reading JSON values from MQTT

I’m still on a steep learning curve with OpenHAB using openhabian 1.4, but I’m stuck on trying to read a couple of MQTT values into an items file. I am using RTL_433 to read power consumption from a Current Cost meter and I can see the values in JSON format:

{“time” : “2017-12-28 11:49:46”, “model” : “CurrentCost TX”, “dev_id” : 77, “power0” : 1845, “power1” : 0, “power2” : 0}

What I want is just the power0 value, so I am using this in the items file:

Number PowerMeter “Power [%d W]” (g1) {mqtt="<[openHAB2:RTL_433/JSON:state:JSONPATH($.power0)]"}

I have installed the JSON path transform and there are no errors in the logs, but I do not see the value in my sitemap.
Can someone please point out whatever glaring mistake I have made?
Thanks!

Your JSONPATH is ok it seems.
I presume openHAB2 is the name of your broker and RTL_433/JSON is your MQTT topic?
are you sure those are correct?
Are you able to read any of the other values in the JSON stream?

As it is easy to overlook something, let me just put my JSONPATH here, that I use for a similar shaped JSON:

Number Temperature_coop "Temperatuur [%.2f °C]" (coop) {mqtt="<[mosquitto:home/coop:state:JSONPATH($.Temperature)]"}

I think that is indeed exactly how you do it, so maybe the fault is not in yr JSONPATH
Do you have any MQTT monitor like MQTT spy? can you see the JSON actually being sent on that topic?

Edit: when I run your JSON through a validator, your JSON seems ok

Hi Kees, I just found it through a process of elimination. My mqtt.cfg is:
mqtt:broker.url=tcp://localhost:1883
mqtt:brokerclientId=OpenHAB2

I thought I should be using the brokerclientID in the item but it’s the broker.url, so:
Number PowerMeter “Power [%d W]” (g1) {mqtt="<[broker:RTL_433/JSON:state:JSONPATH($.power0)]"}

works fine. Thanks!

1 Like

Thanks for feedback. Indeed I already expected your problem to be with the MQTT, not with the JSON.
happy you found it