Call REST api

Hi,

Currently I’m using the TCP/UDP binding to get/update status of my lights.
The disadvantage of this is that I need to get the status one-by-one, which is a bit cumbersome.
With the new version of my modules, I noticed that there is also a REST API I can call.
Just need to browse to the correct URL on my module and I get a JSON file with the status of all my lights.
But I’m not sure how to handle this in openHAB :slight_smile:

My idea would be to make a rule that calls the API and parses the JSON file to update my lights in openHAB.
Could somebody point me in the right direction for this implementation?
My ideal scenario would be that I only make a call when it’s need (when somebody wants to see the status)
But I’m not sure if that’s possible. Otherwise I will probably need a time based trigger.

Any help is appreciated.

that’s a perfect candidate for the HTTP Binding with a jsonpath transformation service

Read more here:

  1. https://www.openhab.org/addons/bindings/http1/
  2. https://www.openhab.org/addons/transformations/jsonpath/

Why do this? You could setup a rule of course that reads (using sendHttpGetRequest) on demand (based on a trigger) the state but it’s better to use updateInterval of the HTTP Binding to poll every so often the state.

edit: ok, you don’t want to poll individual states but to process the complete json containing all the statuses in one shot and update the OH2 Items… I think that this can be achieved only with a rule using the http action (sendHttpGetRequest) and some scripting with variables to take the json parts and send them as postUpdates to the corresponding OH2 Items. You can have a button that triggers such rule.

And what kind of modules are we talking about?

It’s a basic relay and a dimmer module that work with UDP commands.