Netatmo Door/Window Tag - problem with curl response, body missing

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
herscotty
Posts: 13
Joined: Wednesday 06 May 2015 22:57
Target OS: Linux
Domoticz version: beta
Location: Germany
Contact:

Netatmo Door/Window Tag - problem with curl response, body missing

Post by herscotty »

Hello everyone,

i try to integrate the Netatmo tags into Domoticz.

For that i already wrote a little Script which works fine but i have some trouble with the tokens.
When i use some other Scripts i always get a Mail for the login. So i try to use the Token:

You can get the status of the tags with the following command:
curl -X GET "https://api.netatmo.com/api/homestatus? ... 191428bXXX" -H "accept: application/json" -H "Authorization: Bearer 519f537b187759b932000XXX|99a6d42c1deeefec6e35fa0ca732XXX"
i got this Command from https://dev.netatmo.com/apidocumentatio ... homestatus

But when i change the token, i only get this back:
{"status":"ok","time_server":1647945445}
the whole body is missing.

I also tried:
curl -d "access_token=XXX|XXX&home_id=XXX" https://api.netatmo.com/api/homestatus
But i also only get the "time_server" response.

If i change the token, i get a bad login so the token must be right.

I already got the full Script to get the Tag Data but it only works till the Token from the dev.netatmo page expires.

Maybe someone can help me?

Script:

Code: Select all

#!/bin/bash

USER="XXX"
PASS="XXX"

token=`curl --location --request POST "https://api.netatmo.com/oauth2/token" \
  --form "grant_type=password" \
  --form "client_id=XXXX" \
  --form "client_secret=XXXX" \
  --form "username=$USER" \
  --form "password=$PASS"`
  
# echo $token to see home_id
  
refresh_token=$(echo $token| jq ."refresh_token" | cut -d '"' -f 2 )
echo refresh_token $refresh_token
access_token=$(echo $token| jq ."access_token" | cut -d '"' -f 2 )
echo access_token $access_token

PARAM="access_token=$access_token&home_id=XXX"
netatmo=`curl -d $PARAM "https://api.netatmo.com/api/homestatus"`
#also possible:
# curl -X GET "https://api.netatmo.com/api/homestatus?home_id=XXX" -H "accept: application/json" -H "Authorization: Bearer $access_token"

if [ -z "$netatmo" ]
then
   exit 1
else
        Haustuer=$(echo $netatmo | jq '.body.home.modules[] | select(.id=="70:ee:50:22:91:83") | .status' | cut -d '"' -f 2 )
        Schlafzimmer=$(echo $netatmo | jq '.body.home.modules[] | select(.id=="70:ee:50:22:81:92") | .status' | cut -d '"' -f 2)
        Bad=$(echo $netatmo | jq '.body.home.modules[] | select(.id=="70:ee:50:22:7b:5b") | .status' | cut -d '"' -f 2)

fi

echo Haustür $Haustuer
echo Bad $Bad
echo Schlafzimmer $Schlafzimmer

if [[ $Bad = "closed" ]]
then
        echo "zu"
         curl -s "http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=36971&switchcmd=Off" >>/dev/null
else
        echo "auf"
        curl -s "http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=36971&switchcmd=On" >>/dev/null

fi
herscotty
Posts: 13
Joined: Wednesday 06 May 2015 22:57
Target OS: Linux
Domoticz version: beta
Location: Germany
Contact:

Re: Netatmo Door/Window Tag - problem with curl response, body missing

Post by herscotty »

I think i found a solution.

I added the Scope to the Token request:


token=`curl --location --request POST "https://api.netatmo.com/oauth2/token" \
--form "grant_type=password" \
--form "client_id=5548bd8f207759344885ced0" \
--form "client_secret=LrJdHJjjwpzKdehThvi2qZw1A0duZBQe62H6mj9" \
--form "username=$USER" \
--form "password=$PASS" \
--form "scope=read_camera"`

Now it seems to work. So i get now the Status of the Tags in my Domoticz and can use it for automation :)
I execute the Script every minute with crontab.
Feel free to ask if you need help with the Script!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest