Drivia contactor with Netatmo Binding

Hi!
I want to add some new things on OH 4.1 from Netatmo Binding without success.

With the API (Netatmo Connect | Legrand API Documentation), i can change state of legrand contactor (drivia with netatmo) using CURL command. (i use this contactor to on/off some exterior light)

curl -X POST "https://api.netatmo.com/api/setstate" -H "accept: application/json" -H "Authorization: Bearer xxxx|xxxx" -H  "Content-Type: application/json" -d "{\"home\":{\"id\":\"myid\",\"modules\":[{\"id\":\"contactorid\",\"on\":true,\"bridge\":\"bridgeid\"}]}}"

Try to find on Netatmo Binding a solution to manage it but without success… I think source code of Netatmo Binding can’t discover those elements. Does anyone have already try to implement it on OH?

PS : Exec binding ou HTTP binding could maybe do the job but Netatmo auth need to be manage… that’s why i think my solution is on this binding…

Thanks by advance for those who will try to help me ^^

HTTP binding supports bearer authentication, so probably is your best chance

Thanks for the quick reply!
I have tried http binding (before my post) but it seems i don’t configure it correctly cause no success
I will try again

Just retry and with http binding correctly configured, it’s ok, thanks @moody_blue

1 Like

Come back here cause, with the http binding solution, I must adapt the auth/netatmo provide a token but with expiration and we must refresh it (Netatmo Connect | Authentication)

Do you have an idea how I can do that with OH and http binding?

To complete my precedent post :

  • HTTP Binding is ok to switch contactor state
  • I must pass on Headers a string like this “Authorization=Bearer xxx|xxx” where xxx|xxx is the access token genereated on my netatmo app
  • Acess token have a lifetime (it seems to be 3 hours) so, before try to switch state, i must refresh the token

It’s possible with a new api request :

curl --request POST "https://api.netatmo.com/oauth2/token" --form "grant_type=refresh_token" --form "client_id=myclientid" --form "client_secret=myclientsecret" --form "refresh_token=yyy|yyy"

yyy|yyy is a token generated on same time than access token

This request give a json response like this :

{"scope":["read_magellan","write_magellan"],"access_token":"xxx|xxx","refresh_token":"yyy|yyy","expires_in":10800,"expire_in":10800}

I must take the new xxx|xxx token and put it on the headers setting on the http binding thing

Is it possible with the HTTP Binding to make a request, store the response on a global var and make a new request with parameters update with global var?

Or is it possible in OH to make some JS code and associated this JS code to an item?

I don’t think that you can change login credentials programatically in the http binding, but maybe @J-N-K can change that.

Changing thing configuration dynamically is not supported in openHAB. Probably using a rule is the better way here.