openHab, mqtt 2.4 and JSON

Hi everybody!
I was testing new JSON publish functionality but it looks much more complex to get things out of OMG to openHAB …
I.E. for BLE detection now i have only one topic that publish information about all devices, how did you manage to update different items from the same topic, looking at payload? I think it can be done with combination of JS and JSON transformation but that’s really not “out of the box” and much more complex than before…
Any hint?


It seems that OpenHAB 2.4 implement auto discovery following home assistant “way”, did you try to activate Zmqttdiscovery in user_config.h and see if OpenHAB2.4 discover the devices?

Hi, no i didn’t try because i prefer coding in OH rather than using UI for the definition of things… flexibility of files is sooo much better! :slight_smile:

And did you succeeded by coding?
If yes it would be nice to share your codes

That’s my aim for tomorrow… I’ll try and if I succeed I will share :slight_smile:

Maybe it’s not the most elegant, but this way it works for my purpose to detect presence.

in thing file:

Thing mqtt:topic:omgentrance (mqtt:broker:localBroker) {
    Type string : blepresence "People Presence"  [ stateTopic="home/home_presence/OpenMQTTGatewayEntrance"]

in item file

String OMG_BLE_Entrance "BLE Entrance Detector" { channel="mqtt:topic:omgentrance:blepresence" }
Switch   Presence_Keys_Rick      "Rick's Keys"       <keyring>      (People, gKeys)        {expire="240s,OFF"}

and in rule file:

rule "BLE Presence Detector"
Item OMG_BLE_Entrance received update
val String msg = (OMG_BLE_Entrance.state as StringType).toString
val String id  = transform("JSONPATH", "$.id", msg).toString
if(id == "xx:xx:xx:xx:xx:xx")

This way, when i get mqtt update i turn on the Presence_Keys_Rick switch.
The item has an expire at 240s, that means if no udpate coming from OMG for 4 minutes i turn off presence.
Let me know if i can improve :wink:

Would it be possible to use the code syntax “preformatted text” to get a better visibility of your rules please?

sorry, i hope is more clear and useful now :wink:

1 Like

perfect, thanks for this I will add it to the wiki as an example

thanks to you for the effort!
i am sure it will be much better when it will be possible to add filters and publish just some mac and avoid lots of messages :slight_smile:

For info the wiki has been updated with new examples of sensors and switch.