Getting a value via http from within a rule

Is it possible to use a rule to get a JSON value once a day, rather than use the http binding which only has a frequency? I have a JSON value that I want to retrieve around midnight once a day and store it, something like:

rule “Get heating counter and save”

Time cron "* 0 0 * * ?"
var value

I can’t find any code examples of getting values via http from a rule, just that most people use the http binding. I only need this value once a day, and it would be wasteful to keep polling it.


Well, you can set a really long polling period.

But in this case you can call any transformation from Rules using the transform Action.

transform("JSONPATH", "$", value)

I have no idea what you are trying to do with the value.persist though. perisist only is valid for Items. getHttpRequest returns a String. So you will need to create a new Item to hold your value and postUpdate to it in your rule:

MyValueItem.postUpdate(transform("JSONPATH", "$", value))

The device is a CT50 thermostat. It maintains an elapsed counter of the total amount of time the thermostat is on for the day, but it gets cleared at midnight every day. It looks like this:


So I want to read out and store this value just before it gets cleared for the next day, which is why the time I poll it is important.I guess what I can do is long-poll the “yesterday” value which is the previous day. No matter when it hits I’ll have a solid value, but I thought there might be a way to get the current “today” value just before midnight.

There is and I just showed you how above.

But you have to store the value in an Item. You can’t just call .persist on any random variable you happen to create.

Thank you.
I was able to get it to work using something like: