Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/sh
- set +x
- #EInstellungen
- tokenfile="/etc/openhab2/html/netatmo_token.json"
- errorfile="/etc/openhab2/html/netatmo_error.json"
- #los gehts
- rm ${errorfile}
- if [ ! -f $tokenfile ]; then
- echo "Get new access token"
- curl -d "grant_type=password&client_id=##########&client_secret=##########&username=##########&password=##########&scope=read_station read_camera read_thermostat write_thermostat" "https://api.netatmo.net/oauth2/token" > ${tokenfile}
- fi
- atoken=`jq -r ".access_token" $tokenfile`
- rtoken=`jq -r ".refresh_token" $tokenfile`
- expiration=`jq -r ".expires_in" $tokenfile`
- filedate=`date +%Y-%m-%d_%H:%M:%S -r $tokenfile`
- filedate=${filedate/_/ }
- filedate=`date -d "$filedate" +%s`
- limittime=`expr $filedate + $expiration`
- currenttime=`date +%s`
- #debug
- echo "currenttime=${currenttime}"
- echo "limittime=${limittime}"
- echo "filedate=${filedate}"
- #tokenfile entfernen, wenn ungültig
- if [ -z "$limittime" ] ; then
- echo "access token file empty"
- cp ${tokenfile} ${errorfile}
- rm ${tokenfile}
- fi
- if [ $limittime -lt $currenttime ]; then
- echo "Using refresh token"
- curl -s -d "grant_type=refresh_token&refresh_token=${rtoken}&client_id=##########&client_secret=##########&username=##########" "https://api.netatmo.net/oauth2/token" > ${tokenfile}
- atoken=`jq -r ".access_token" $tokenfile`
- fi
- curl -s -d "access_token=${atoken}&home_id=##########" "https://api.netatmo.net/api/homestatus?home_id=##########" > "/etc/openhab2/html/netatmo_therm_bath_data.json"
- curl -s -d "access_token=${atoken}&home_id=##########" "https://api.netatmo.net/api/homestatus?home_id=##########" > "/etc/openhab2/html/netatmo_therm_kitchen_data.json"
- curl -s -d "access_token=${atoken}&home_id=##########" "https://api.netatmo.net/api/homestatus?home_id=##########" > "/etc/openhab2/html/netatmo_therm_living_data.json"
- curl -s -d "access_token=${atoken}&home_id=##########" "https://api.netatmo.net/api/homestatus?home_id=##########" > "/etc/openhab2/html/netatmo_therm_floor_data.json"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement