I have a Json array with the energy prices of the next day, it looks like that:
So it’s a string item with the values for the whole day. I want to get a notification, if just one “total” value is under 0.20. How do I get this in a rule, I really have no idea how to do it, because there are 24 “total” values. The best would be, if I also get the startsAt value (or just the time of it) in this notification.
Can someone help me with this array?
The item is called Tibber_API_Prices_for_tomorrow_as_a_JSON_array
You have several approaches you can do but they depend on what binding you are using to retrieve these values.
Assuming the HTTP or MQTT binding or binding that lets you create your own channels, and assuming it’s always 24 values and always in chronological order I would implement this at the binding level. Create one Channel for each entry with the JSONPATH to select the “total” for a given array element ($.total, $.total, and so on, see JsonPath - Transformation Services | openHAB). Make sure to name the element based on the time it represents. Link each Channel to a Number Item, again named/labeled with the time that value represents. Add the Items to a Group.
In a Rule you can sort the members of the Group to find the minimum and then use the name or label of the Item to extract which time is at the lowest value. See Design Pattern: Encoding and Accessing Values in Rules for further details.
If it isn’t an option to implement this at the Thing with Channels but the rest of my assumptions hold true I’d implement the same approach except using the transform Profile. You’d only have the one Channel but link that to the same 24 Items and use the transform Profile to extract the element for the given Item. Still use the Item name/label to identify which time the value represents.
In general, it’s going to be easier if you can get that bid array into Items. Once you have that it becomes a straight forward OH problem.
JSON.parse(items.Tibber_API_Prices_for_tomorrow_as_a_JSON_array.state) and you will have converted the JSON into a JS Object which can be processed using normal coding tools.