Hello,
this is my first post here as im two days into OH:slight_smile:
I’ve searched alot but didnt find a solution for my task. I have ESP32+BME280 sensors in different rooms publishing data to MQTT topic “home/weather” in JSON format:
{'deviceId': 'office', 't': 2.53, 'p': 94134.55, 'time': '2018-03-02T17:16:12.281710388Z', 'h': 79.78}
I want to update sitemap’s Frame depending on the node attribute because it represents a different location. I cant find a way to dynamically create/update frames. So i changed the topics items and sitemaps:
home.item:
Number temp2 "temp [%s C]" {mqtt="<[mosquitto:home/office/weather:state:JSONPATH($.t)]"}
Number press2 "press [%s hPa]" {mqtt="<[mosquitto:home/office/weather:state:JSONPATH($.p)]"}
Number hum2 "hum [%s %%]" {mqtt="<[mosquitto:home/office/weather:state:JSONPATH($.h)]"}
String nodeId2 "Node [%s]" {mqtt="<[mosquitto:home/office/weather:state:JSONPATH($.deviceId)]"}
String dateTime2 "[%s]" {mqtt="<[mosquitto:home/office/weather:state:JSONPATH($.time)]"}
Number temperatureOut "temp [%s C]" {mqtt="<[mosquitto:home/garden/weather:state:JSONPATH($.t)]"}
Number pressureOut "press [%s hPa]" {mqtt="<[mosquitto:home/garden/weather:state:JSONPATH($.p)]"}
Number humidityOut "hum [%s %%]" {mqtt="<[mosquitto:home/garden/weather:state:JSONPATH($.h)]"}
String nodeId "Node [%s]" {mqtt="<[mosquitto:home/garden/weather:state:JSONPATH($.deviceId)]"}
String dateTime "[%s]" {mqtt="<[mosquitto:home/garden/weather:state:JSONPATH($.time)]"}
home.sitemap:
sitemap home label="Home" {
Frame label="2nd floor" icon="firstfloor" {
Text item=temp2 icon="temperature"
Text item=hum2 icon="humidity"
Text item=press2 icon="pressure"
Text item=nodeId2 icon="office"
Text item=dateTime2 icon="time"
}
Frame label="Backyard" icon="garden" {
Text item=temperatureOut icon="temperature"
Text item=humidityOut icon="humidity"
Text item=pressureOut icon="pressure"
Text item=nodeId icon="garden"
Text item=dateTime icon="time"
}
}
And everything is working fine
- As there are many sensors in my home i dont wanna create the same code again and again. As you see its almost identical.
- Im not sure how the MQTT Binding and JSONPATH transformer internally work but it looks to me as unneeded JSONPATH parsing to find the right Item.
Thank you!