Finally, here is my solution;
you need create two python files.
STEP 1
create new file like “netatmo_token_request.py” and run with “python3 netatmo_token_request.py”
import requests
payload = {'grant_type': 'password',
'username': "YOUR_NETATMO_MAIL_ADDRESS",
'password': "YOUR_NETATMO_PASSWORD",
'client_id':"YOUR_NETATMO_CLIENT_ID",
'client_secret': "YOUR_NETATMO_CLIENT_SECRET",
'scope': 'read_homecoach'}
try:
response = requests.post("https://api.netatmo.com/oauth2/token", data=payload)
response.raise_for_status()
access_token=response.json()["access_token"]
refresh_token=response.json()["refresh_token"]
scope=response.json()["scope"]
print("Your access token is:", access_token)
print("Your refresh token is:", refresh_token)
print("Your scopes are:", scope)
except requests.exceptions.HTTPError as error:
print(error.response.status_code, error.response.text)
It will generate access token and refresh token.
STEP 2
create new file like “netatmo_refresh_token.py” and copy to /config/python_scripts/ folder. If folder not exist, create it.
import http.client
conn = http.client.HTTPSConnection("api.netatmo.com")
payload = "refresh_token=<COPY_YOUR_REFRESH_TOKEN_FROM_STEP1>&client_id=<YOUR_NETATMO_CLIENT_ID>&client_secret=<YOUR_NETATMO_CLIENT_SECRET>&grant_type=refresh_token"
headers = { 'content-type': "application/x-www-form-urlencoded;charset=UTF-8" }
conn.request("POST", "/oauth2/token", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
STEP 3
Create an automation file like “netatmo_refresh_token.yaml”
- alias: Netatmo Refresh Token
trigger:
platform: time
# Matches every 150 minutes, netatmo token expires every 3h.
minutes: '/150'
seconds: 00
action:
- service: python_script.netatmo_refresh_token
Don’t forget to change ACCESS TOKEN in your sensor file. (not refresh token)
I’m not developer. I created the codes by bringing the codes I found from Google.
I hope it works out to you.