Automation of Netatmo thermostat mode (away/schedule) based on a GPIO input of a Raspberry PI
This project was born because the Netatmo smart thermostat does not have any sort of geofencing functions in the mobile app and therefore you must remember to manually set the absent mode so as not to waste energy unnecessarily.
The core is a python script inside a Raspberry PI that sets the away/schedule mode of the thermostat through the Netatmo API based on a GPIO input of the Raspberry PI. I named this project Bentel Netatmo connect because i use an Open Collector output from the Bentel Absoluta home security system. If GPIO is high the script set the thermostat mode to schedule or do nothing if the mode is manual (typically if you set a manual temperature before go home that is higher of the scheduled temperature); if GPIO is low the script set the thermostat mode to away. A Telegram notification is also sent.
Note
The OAuth2 tokens required by the Netatmo API, access_token and refresh_token are stored in a config file; other parameters are hard-coded into the script; customize them to your needs. (see Setup section)
- RPi.GPIO python library -
pip install RPi.GPIO
- Requests python library
pip install requests
- Requests OAuth2 python library
pip install requests-oauth2
- Telegram BOT for notifications - see here
- Create an app in Netatmo developer console.
- Set the variables
client_id
andclient_secret
- Set the variable
input
with the correct GPIO input used (see pinout here) - Set the variables
home_id
with your home_id: for retrieve it, go to https://dev.netatmo.com/apidocumentation/energy#homesdata, and execute homesdata API request (https://api.netatmo.com/api/homesdata) and get home_id in the response - Set the variables
telegram_chat_id
andtelegram_bot_token
- edit the full path of the settings file in
config.read('/home/user/netatmo.ini')
- go to https://dev.netatmo.com/, enter your app, scroll to token generator, choose the scopes write_thermostat and read_thermostat and click generate; accept the authorization page and then copy/paste the tokens in the config file netatmo.ini.
Edit the file bentel_netatmo_connect.service with your path in line ExecStart=/usr/bin/python3 /home/user/bentel_netatmo_connect_v5.py
and place it to /etc/systemd/system and enable the service with sudo systemctl enable bentel_netatmo_connect.service
.
sudo service bentel_netatmo_connect start