Trigger an item's update from a http binding

Hey guys,

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.

Best and Thanks for your help,
Denis

You can use the sendHttpGetRequest action.

That will be much easier that playing with a custom API and using the REST api.

You can call an HTTP request and get the result in a variable. Please note that the return value is ALWAYS a string.
Good luck

Hey,

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() ? :slight_smile:

Thank you for taking part in this discussion. Much appreciated.

Best,
Denis

Afraid not.
You could increase the binding update rate.
I can’t think of another solution than the one I proposed

Example

Sensor.sendCommand(REFRESH)

It’s that simple in OH2.
BUT
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?

OK later when I have access, I’ll check if the http binding in OH2 supports .sendCommand(REFRESH).

Thank you.

If it doesn’t yet support REFRESH, it would be a useful enhancement request.
If it does, it would be helpful to add it to the docs webpage.

hi, same question in 2020 :wink: was there any update to this request?

Does anything make you think a formal request was created?

nope, neither do I know if it was declined for any reason.