is it possible (e.g. through a rule) to trigger the update of an item’s value? And by triggering an update, I don’t mean setting its value from a rule, cause I know I can call .postUpdate( ) with a value.
Actually, I’d like for an item to refresh its value through the binding it is configured to use. Therefore, if I have an item that is configured to receive its value through a http binding on a time interval, I’d like to refresh its value on my own, i.e. from a rule, before the interval is due to do that.
Is this possible?
Of course I can make this workaround where I code my custom API and, then, call it from a rule in order to read the value from the source (the same way a http binding would do) and forward it to OpenHAB’s REST API. Yet this is impractical if this was possible to do this from a rule with one line.
thanks for the answer. Your solution still requires me to have the URL of the HTTP source written at two places, i.e. in the item’s definition itself as well as in the rule where I use sendHttpGetRequest.
The only difference of what you’re suggesting is to directly use the sendHttpGetRequest’s result in the rule and write it using postUpdate directly to an item. I still have to process the response’s JSON though and find out the object. I mean, it works and it would spare me one step, but it’s still quite similar to my originally devised approach.
Isn’t there a command like itemName.refreshValueFromItsBinding() ?
Thank you for taking part in this discussion. Much appreciated.
It’s that simple in OH2.
There is a huge caveat; the binding has to be written to support that REFRESH command (it would not make sense in every binding anyway, for example Zwave where devices go to sleep)
So far as I know, only a few v2 bindings support it e.g. Modbus (which is a polling environment by its nature)
All Items should accept REFRESH command without error, but nothing will happen unless (one of) its inbound binding(s) knows what to do with it. I wonder if that holds up in practice?
It seems like there is no REFRESH support for http binding in OH 3.4 yet. But there is a workaround - you can disable and enable the thing in a rule using the REST API. The thing will get updated with its enablement.