uccwhity

Untitled

Mar 1st, 2021
423
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/sh
  2. set +x
  3.  
  4. #EInstellungen
  5. tokenfile="/etc/openhab2/html/netatmo_token.json"
  6. errorfile="/etc/openhab2/html/netatmo_error.json"
  7.  
  8. #los gehts
  9. rm ${errorfile}
  10. if [ ! -f $tokenfile ]; then
  11.     echo "Get new access token"
  12.     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}
  13. fi
  14.  
  15. atoken=`jq -r ".access_token" $tokenfile`
  16. rtoken=`jq -r ".refresh_token" $tokenfile`
  17. expiration=`jq -r ".expires_in" $tokenfile`
  18.  
  19. filedate=`date +%Y-%m-%d_%H:%M:%S -r $tokenfile`
  20. filedate=${filedate/_/ }
  21. filedate=`date -d "$filedate" +%s`
  22. limittime=`expr $filedate + $expiration`
  23. currenttime=`date +%s`
  24.  
  25. #debug
  26. echo "currenttime=${currenttime}"
  27. echo "limittime=${limittime}"
  28. echo "filedate=${filedate}"
  29.  
  30. #tokenfile entfernen, wenn ungültig
  31. if [ -z "$limittime" ] ; then
  32.     echo "access token file empty"
  33.     cp ${tokenfile} ${errorfile}
  34.     rm ${tokenfile}
  35. fi
  36.  
  37. if [ $limittime -lt $currenttime ]; then
  38.     echo "Using refresh token"
  39.     curl -s -d "grant_type=refresh_token&refresh_token=${rtoken}&client_id=##########&client_secret=##########&username=##########" "https://api.netatmo.net/oauth2/token" > ${tokenfile}
  40.     atoken=`jq -r ".access_token" $tokenfile`
  41. fi
  42.  
  43. curl -s -d "access_token=${atoken}&home_id=##########" "https://api.netatmo.net/api/homestatus?home_id=##########" > "/etc/openhab2/html/netatmo_therm_bath_data.json"
  44. curl -s -d "access_token=${atoken}&home_id=##########" "https://api.netatmo.net/api/homestatus?home_id=##########" > "/etc/openhab2/html/netatmo_therm_kitchen_data.json"
  45. curl -s -d "access_token=${atoken}&home_id=##########" "https://api.netatmo.net/api/homestatus?home_id=##########" > "/etc/openhab2/html/netatmo_therm_living_data.json"
  46. curl -s -d "access_token=${atoken}&home_id=##########" "https://api.netatmo.net/api/homestatus?home_id=##########" > "/etc/openhab2/html/netatmo_therm_floor_data.json"
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×