[SOLVED] Mqtt Item data Problem

Hi,

I have been on this for 2 days and read as many articles, postings, documentation I can find but still can’t get this to work.

I am running pywws which grabs weather station info it then sends it to mosquitto.

I have configured OpenHAB and I can see the data in events.log

events.log

2019-01-05 21:33:12.257 [vent.ChannelTriggeredEvent] - mqtt:broker:openhab:pywws triggered {"hum_out": "86", "rainin": "0", "dailyrain": "0", "wind_gust": "0.67", "idx": "05.01 21:33", "temp_out_f": "41.9", "wind_ave": "0.00", "rain": "0", "temp_out_c": "5.5", "rel_pressure": "1007.6000", "hum_in": "67", "temp_in_f": "63.1", "dailyrainin": "0", "wind_dir": "SW", "temp_in_c": "17.3"}

site.items

Number TempOutside "Temp Outside [%.1f °C]" <temperature> {mqtt="<[broker:openhab:pywws:state:JSONPATH(temp_out_f)]"}

site.sitemap

Text item=TempOutside label="Out Temperature [%.1f °C]" icon="lightbulb"

I am not at a total loss and going round in circles.
In my site map all I get is °C

Any advice would be greatly appreciated

Thanks

This an MQQTv1 syntax and you are using the MQQTv2 binding
You have abvioulsy configured your broker thing correctly

You now need to go back to the PaperUI to create an MQTT generic thing:

PaperUI - Inbox - + - MQTT Thing Binding - Add Manually - Generic MQTT Thing


Change the Name and ThingID to something more human
Select the MQTT bridge that we know is working

Go to the thing in the Configuration - Things screen:

We are going to create the Humidity channel:
Add a channel: - Select Number type

Change the channelID to humidity
Change the MQTT State topic to the topic that pywws publishes data on

Click SHOW MORE
Change the Incomming Value Transformation to: JSONPATH:$.hum_out

SAVE

Copy the name of the newly created channel and change your item:

Number HumOutside "Temp Outside [%.1f °C]" <temperature> { channel="nameofthechannelyoujustcopied"} }

Sle

1 Like

Thank you SO much, I would have never figured that out!

John

Yes you would, if you had read the docs and searched the forum about MQTT version 2
Please refer to: https://www.openhab.org/blog/2018-12-16-mqtt-arrives-in-the-modern-openhab-2-x-architecture.html

1 Like

Thank you

If I was to try and filter data, for example I am experimenting with a oil level monitor however my neighbour has one as well so i’m getting his data as well.

I can’t see clear documentation on regex on the new 2.x mqtt.

I can get data through if I have JSONPATH:$.depth but would ideally like to filter it to my own based on id

JSONPATH($.depth):.“id” . 137574874,.

but this doesn’t work and I’m not too sure why.

Can you paste the whole JSON, please

2019-01-14 19:32:30.852 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"time" : "2019-01-14 19:32:30", "model" : "Oil Watchman", "id" : 141932971, "flags" : 128, "maybetemp" : 25, "temperature_C" : 6.667, "binding_countdown" : 0, "depth" : 36}'

This is a full message from the watchman

There is one 1 record in the Json so you won’t be able to “filter” it.
What you need to do is use a String channel to get the RAW Json and link it to an item
Then use this item in a rule an rule the transform() action to check for the id and then update your value.
Does that make sense?

item:

String RawJson { channel="mqtt......." }

Rule

rule "Update oil level"
when
    Item RawJson changed
then
    val String id = transform("JSONPATH", "$.id", RawJson.state.toString)
    if (id == "141932971") {
        OilLevelDepthItem.postUpdate(transform("JSONPATH", "$.depth", RawJson.state.toString))
    }
end

I have been experimenting but no joy, I have modified your rule to cover my existing rule so it does it all in one go but no errors are displayed, nothing in events or openhab.log when data is sent so not sure what i’m missing, there’s not much to go on

Items

Number WatchmanPercentage "Oil Remaining [%.2f %%]" (WatchmanPercentage)
String RawJson { channel="mqtt:topic:MyMQTTThing:watchmandepth" }

rule

val float height = 89 // height of the tank

rule "Update oil level"
when
    Item RawJson changed
then
    val String id = transform("JSONPATH", "$.id", RawJson.state.toString)
    if (id == "141932971") {
    val float depth = Float::parseFloat(WatchmanDepth.state.toString) as Number
    val float left = height - depth
    val float per = (left / height) * 100
    WatchmanPercentage.sendCommand(per) // update the item that holds the percentage
    }
end

Can you show the thing and channel, please?
Also try to avoid the use of primitives in the DSL, use Number instead of Float

val Number height = 89 // height of the tank

rule "Update oil level"
when
    Item RawJson changed
then
    val String id = transform("JSONPATH", "$.id", RawJson.state.toString)
    if (id == "141932971") {
        val Number depth = Float::parseFloat(WatchmanDepth.state.toString) as Number
        val Number left = height - depth
        val Number per = (left / height) * 100
        WatchmanPercentage.postUpdate(per) // update the item that holds the percentage
    }
end

Incoming value transformation is

JSONPATH:$.depth

Does the item updates in the log when a new Json is received?

NO transformation. You want the RAW json.

nothing updates when the data is received, nothing in any logs. i can see the send in mosquitto but nothing in openhab

I take out the transformation line and put nothing else in there?

That’s right. Nothing else in there

Does the script look OK?

I have to wait 20mins between transmissions from the watchman, with your example i needed ‘Item’ at the start and a close brackets on the transform line

Make your own…
Use mqtt.fx

Yes, sorry, corrected above

I am seeing log entries now but it’s not being processed

2019-01-15 13:13:51.607 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"time" : "2019-01-15 13:13:51", "model" : "Oil Watchman", "id" : 141932971, "flags" : 128, "maybetemp" : 23, "temperature_C" : 10.000, "binding_countdown" : 0, "depth" : 36}' not supported by type 'NumberValue'

Ok, it should be a text channel