Trying to extract furnace runtime

Hello all,

Trying to figure out how to return/display the furnace runtime.

I’ve added a call to the furnace in my http binding:

http:tstat2.url=http://192.168.224.50/tstat/datalog
http:tstat2.updateInterval=3600000

And then I created an item to display the entire string returned.

String Tstat2_Ystrdy “Yesterday runtime [%s]” { http="<[tstat2:600000:JSONPATH($.yesterday)]" }

And then this in my sitemap:

Text item=Tstat2_Ystrdy

And it returns the data as expected:

But what I’d like to get it to look like is:

Yesterday runtime 3hrs, 21min

How do I parse the string and format it like that?

Thanks

Use JS(yesterdayRuntime.js) instead of JSONPATH. Make transform/yesterdayRuntime.js:

(function(json) {
  var datalog = JSON.parse(json);
  return "Yesterday runtime " + datalog.yesterday.heat_runtime.hour + "hrs, " + 
    datalog.yesterday.heat_runtime.minute + "min";
})(input)

Thanks for that, but where do I put it???

Unfortunately you’re talking above my head…

You would create a text file named yesterdayRuntime.js in the /etc/openhab/configurations/transform directory on your openHAB server (assuming you installed openHAB via the official apt-get instructions; otherwise, wherever your transform directory is on your installation). The file would contain:

(function(json) {
  var datalog = JSON.parse(json);
  return "" + datalog.yesterday.heat_runtime.hour + "hrs, " + 
    datalog.yesterday.heat_runtime.minute + "min";
})(input)

You would then change your Tstat2_Ystrdy item configuration to look like this:

String Tstat2_Ystrdy "Yesterday runtime [%s]" { http="<[tstat2:600000:JS(yesterdayRuntime.js)]" }

That makes sense and work perfectly! Appreciate the lesson today.

Have a Merry Christmas and Happy New Year!

1 Like