From 91c07d99c201ec076d8685ab7689f6e8ad6d879b Mon Sep 17 00:00:00 2001 From: Pieter Smets Date: Mon, 30 Oct 2023 20:48:38 +0100 Subject: [PATCH] netatmo access token update --- README.md | 12 +++++++++--- thermmode-unifi.sh | 22 ++++++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6cead11..009633f 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ Usage: thermmode-unifi.sh Options: -C, --config Print a demo configuration file with all variables -h, --help Print help + -m, --mode Print the previous unifi mode" + -f, --force Ignore the stored unifi mode and force syncing the thermostat -v, --verbose Make the operation more talkative -V, --version Show version number and quit ``` @@ -87,9 +89,9 @@ UNIFI_CLIENTS = aa:aa:aa:aa:aa:aa bb:bb:bb:bb:bb:bb cc:cc:cc:cc:cc:cc NETATMO_CLIENT_ID = ... NETATMO_CLIENT_SECRET = ... -# Netatmo username and password -NETATMO_USERNAME = ... -NETATMO_PASSWORD = ... +# Netatmo access token. +NETATMO_ACCESS_TOKEN = ... +NETATMO_REFRESH_TOKEN = ... # Netamo home id (optional, defaults to the first of your homes) # NETATMO_HOME_ID = ... @@ -109,3 +111,7 @@ Scan the syslog output ``` cat /var/log/syslog | grep netatmo ``` + +## Netatmo access + +Create an app to obtain the cliend ID and secret (App Technical Parameters) and a non-expiring token (Token generator with scopes `read_thermostat` and `write_thermostat`). diff --git a/thermmode-unifi.sh b/thermmode-unifi.sh index 8f496be..d1f8c9a 100755 --- a/thermmode-unifi.sh +++ b/thermmode-unifi.sh @@ -23,7 +23,7 @@ set -e SCRIPT=$( basename "$0" ) # Current version from git -VERSION="v0.3.2" +VERSION="v0.4.0" #------------------------------------------------------------------------------- @@ -44,7 +44,8 @@ function usage { "Options:" " -C, --config Print a demo configuration file with all variables" " -h, --help Print help" -" -m, --mode Print previous unifi mode" +" -m, --mode Print the previous unifi mode" +" -f, --force Ignore the stored unifi mode and force syncing the thermostat" " -v, --verbose Make the operation more talkative" " -V, --version Show version number and quit" ) @@ -125,9 +126,9 @@ function config "NETATMO_CLIENT_ID = ..." "NETATMO_CLIENT_SECRET = ..." "" -"# Netatmo username and password" -"NETATMO_USERNAME = ..." -"NETATMO_PASSWORD = ..." +"# Netatmo access token" +"NETATMO_ACCESS_TOKEN = ..." +"NETATMO_REFRESH_TOKEN = ..." "" "# Netamo home id (optional, defaults to the first of your homes)" "# NETATMO_HOME_ID = ..." @@ -285,7 +286,7 @@ function netatmo_access_token { --silent \ --show-error \ --header "accept: application/json" \ - --data grant_type=password \ + --data grant_type=authorization_code \ --data client_id=$NETATMO_CLIENT_ID \ --data client_secret=$NETATMO_CLIENT_SECRET \ --data username=$NETATMO_USERNAME \ @@ -450,6 +451,8 @@ do ;; -m|--mode) echo "unifi_mode=$previous_mode" && exit 0 ;; + -f|--force) previous_mode="__NONE__" + ;; -v|--verbose) DO_VERB=1 ;; -V|--version) version @@ -482,20 +485,19 @@ then parse_config $1 \ UNIFI_ADDRESS UNIFI_USERNAME UNIFI_PASSWORD UNIFI_SITENAME \ UNIFI_CLIENTS UNIFI_CLIENTS_OFFLINE_SECONDS UNIFI_CLIENTS_IGNORE_SECONDS \ - NETATMO_CLIENT_ID NETATMO_CLIENT_SECRET NETATMO_USERNAME NETATMO_PASSWORD \ + NETATMO_CLIENT_ID NETATMO_CLIENT_SECRET NETATMO_ACCESS_TOKEN NETATMO_REFRESH_TOKEN \ NETATMO_HOME_ID fi # Check if mandatory variables are set check_config UNIFI_ADDRESS UNIFI_USERNAME UNIFI_PASSWORD UNIFI_SITENAME UNIFI_CLIENTS -check_config NETATMO_CLIENT_ID NETATMO_CLIENT_SECRET NETATMO_USERNAME NETATMO_PASSWORD +check_config NETATMO_CLIENT_ID NETATMO_CLIENT_SECRET NETATMO_ACCESS_TOKEN NETATMO_REFRESH_TOKEN # Construct derived variables UNIFI_COOKIE=$(mktemp) UNIFI_API="${UNIFI_ADDRESS}/proxy/network/api" UNIFI_SITE_API="${UNIFI_API}/s/${UNIFI_SITENAME}" NETATMO_API="https://api.netatmo.com/api" -NETATMO_ACCESS_TOKEN="" #------------------------------------------------------------------------------- @@ -504,7 +506,7 @@ NETATMO_ACCESS_TOKEN="" # #------------------------------------------------------------------------------- -netatmo_access_token +#netatmo_access_token if [ "$NETATMO_HOME_ID" == "" ]; then