To get Temperature from MQTT message like
tele/sonoff-greenhouse/SENSOR = {“Time”:“2019-03-31T20:21:30”,“DHT11”:{“Temperature”:26.0,“Humidity”:21.0},“TempUnit”:“C”}
I can create item like below,
Number greenhouse_temp “Greenhouse Temp” (Lights)
{mqtt="<[mbroker:tele/sonoff-greenhouse/SENSOR:state:JSONPATH($.DHT11.Temperature)]"}
But now I want to create item base on json content, for example with MQTT messages like below
tele/sonoff-DS02/SENSOR = {“ACURITE”:{“ChannelId”:5776452,“Temperature”:28.4,“Humidity”:45}}
tele/sonoff-DS02/SENSOR = {“ACURITE”:{“ChannelId”:8020548,“Temperature”:14.4,“Humidity”:50}}
I want to create two items, one for each ChannelId, messages with ChannelId 5776452 go to one item, messages with ChannelId 8020548 go to another.
Could someone help to make it work?
Thanks
rossko57
(Rossko57)
March 31, 2019, 9:39pm
2
One way to do this would be to accept the MQTT JSON into a String Item.
Trigger a rule from Item change, analyse the JSON and update the target Items as required.
There is also a different approach here, using a REGEX in Items MQTT-1 binding. I’m not sure if you can do this with MQTT-2 (channels)
OK, I have got this to work now. I had two different streams of data on the same MQTT topic - power useage which was logged every 5 seconds and was constantly changing, and the oil tank level which logged every 15 minutes and only changed every one or two days. I didn’t realise that OpenHAB only logs an event if the MQTT data changes, but once I published the data manually using
mosquitto_pub -h localhost -i RTL_433 -t RTL_433/JSON -m '{"time" : "2017-12-29 09:52:32", "model" : "Oil Watchman", …
Edit - this outlines the way for MQTT-2 I think, but you’ll need the 2.5 binding
Problem
In the MQTT1 binding there was a feature that let us filter messages published to a given topic and only pass those that match a given REGEX to the transformation and/or on to the Item. This was useful to handle devices that publish messages to a single well known topic for all their devices.
For example, the official firmware from the vendor of Shelly devices have a request/response protocol over MQTT to get meta data about the devices (IP address, MAC address, firmware version, whethe…