I’d like to use OpenHAB to publish lots of weather data (read from an XML feed) to a series of MQTT topics, like this:
home/weather/day0 -> 1:2:0:2:3:1:5:2:1:4:2:-2:0:-1:-2:-1:25:40:50:70:90:100:0:0:2:8
home/weather/day1 -> etc…
There are 130 values I want to publish (5 days * 26 values per day), but obviously I’d rather not store them as 130 OH Items, each with its own XSLT file! Apart from anything, this would cause 130 hits on the API per 5 minutes instead of 1…
So is there a way to, e.g. store 26 values that are returned from one XSLT transform, e.g. as a string?
NOTE: I don’t actually need to use these values in a sitemap, or keep any historic data with persistence, so if there’s a way to do this in a rule without even creating Items that’s fine!
You can store everything is one big String item and parse out the data you need in a rule. Then you have just one xslt and if you write your xslt right parsing your big string of values in the rule should be easy.
If your item is a String then it should store whatever the xslt returns.
Ahh that’s brilliant, thanks! I’m new to XSLT and I hadn’t realised how powerful it was. Looks like I can do most of the formating of numbers etc. in XSLT which saves a lot of hassle!
Wouldn’t be true if you are using the HTTP binding to retrieve the values and use the binding’s caching feature to only retrieve from the URL at some frequency.
As Rich suggested, you could have a String item receive the entire XML string, and in the body of a rule, use the
transform function like
Item WeatherXML changed
val String processed = transform("XSLT", "weather.xsl", WeatherXML.state.toString)
// use processed for something