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¶m=switchlight&idx=36971&switchcmd=Off" >>/dev/null
else
echo "auf"
curl -s "http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=36971&switchcmd=On" >>/dev/null
fi