Gardena2InfluxDB is a Python script for parsing events received on a GARDENA smart system websocket. Events are then parsed and forwarded to InfluxDB to create fancy charts and dashboards on e.g. sensor reading history
- Parsing incoming events from websocket and convert them to go into InfluxDB.
- Having an external settings.ini for comfortable changing parameters.
- Get things up and running ASAP with some docker lovin <3
Example payload of the script which is sent to InfluxDB following a GARDENA smart Sensor values update event:
[
{
"measurement": "sensor-00012345",
"tags": {
"event_type": "SENSOR",
"device_id": "2f0cd24c-9e98-4057-905d-ac0429dfdff3"
},
"fields": {
"soilHumidity": 62
},
"time": "Thu May 30 13:08:24 2019"
},
{
"measurement": "sensor-00012345",
"tags": {
"event_type": "SENSOR",
"device_id": "2f0cd24c-9e98-4057-905d-ac0429dfdff3"
},
"fields": {
"soilTemperature": 13
},
"time": "Thu May 30 13:07:51 2019"
},
{
"measurement": "sensor-00012345",
"tags": {
"event_type": "SENSOR",
"device_id": "2f0cd24c-9e98-4057-905d-ac0429dfdff3"
},
"fields": {
"ambientTemperature": 16
},
"time": "Thu May 30 14:39:12 2019"
},
{
"measurement": "sensor-00012345",
"tags": {
"event_type": "SENSOR",
"device_id": "2f0cd24c-9e98-4057-905d-ac0429dfdff3"
},
"fields": {
"lightIntensity": 688
},
"time": "Thu May 30 14:39:12 2019"
}
]
Gardena2InfluxDB uses open source libs and open data to work properly:
- husqvarnagroup.cloud - Developer Portal from Husqvarna Group along documentation on GARDENA smart system and authentication API endpoints
- InfluxDB-Python - Python client for InfluxDB.
- pickleDB - lightweight and simple key-value store.
- docker-influxdb-grafana - A Docker container which runs InfluxDB and Grafana ready for persisting data.
- Goto https://developer.husqvarnagroup.cloud/, sign in using your GARDENA smart system account and create a new application
- Connect GARDENA smart system API and Authentication API to your application
- Have
python3
andpip3
installed, no InfluxDB is involved thus dry-run - Clone this repository
- Modify settings.ini files and fill in your GARDENA credentials and API key
$ cp settings.ini.bak settings.ini
$ vi settings.ini
- Install the requirements
$ pip3 install -r requirements.txt
- Dry-run the gardena2influxdb python script
$ python3 gardena2influxdb.py --dry-run
- Goto https://developer.husqvarnagroup.cloud/, sign in using your GARDENA smart system account and create a new application
- Connect GARDENA smart system API and Authentication API to your application
- Have
docker
anddocker-compose
installed on your host - Clone this repository
- Modify settings.ini files and fill in your GARDENA credentials and API key.
$ cp settings.ini.docker.bak settings.ini
$ vi settings.ini
- Build the gardena2influxdb docker image and create some necessary data dirs to add persistency to your collected data
$ mkdir data
$ mkdir data/influxdb
$ mkdir data/grafana
$ mkdir data/gardena2influxdb
$ docker build -t gardena2influxdb .
- Run docker-compose to get everything up and running
$ docker-compose up
- Enjoy Grafana at http://localhost:3003
- Details regarding login, how to add InfluxDB as a datasource etc. can be found over here: https://github.com/philhawthorne/docker-influxdb-grafana
- Goto https://developer.husqvarnagroup.cloud/, sign in using your GARDENA smart system account and create a new application
- Connect GARDENA smart system API and Authentication API to your application
- Have
docker
installed, InfluxDB is running at some place only you know ;) - Clone this repository
- Modify settings.ini files and fill in your GARDENA credentials, API key and InfluxDB connection settings.
$ cp settings.ini.bak settings.ini
$ vi settings.ini
- Build the gardena2influxdb docker image
$ mkdir -p data/gardena2influxdb
$ docker build -t gardena2influxdb .
- Run gardena2influxdb docker image
$ docker run -d \
--name gardena2influxdb \
-v $PWD/settings.ini:/app/settings.ini \
-v $PWD/data/gardena2influxdb:/app/data/gardena2influxdb \
gardena2influxdb:latest
- Goto https://developer.husqvarnagroup.cloud/, sign in using your GARDENA smart system account and create a new application
- Connect GARDENA smart system API and Authentication API to your application
- Clone the repository to
/etc
and install requirements
$ cd /etc/gardena2influxdb
$ mkdir -p data/gardena2influxdb
$ pip3 install -r requirements.txt
- Modify settings.ini & gardena2influxdb.service files and copy service to systemd.
$ cp settings.ini.bak settings.ini
$ vi settings.ini
$ cp gardena2influxdb.service.template /lib/systemd/system/gardena2influxdb.service
- Then enable and start service
$ systemctl daemon-reload
$ systemctl enable gardena2influxdb.service
$ systemctl start gardena2influxdb.service
Optional Setup - Configure logrotation for gardena2influxdb.service
- Edit /etc/rsyslog.d/50-default.conf and append the following ling
:programname,isequal,"gardena2influxdb" /var/log/gardena2influxdb.log
- Restart Rsyslog-Daemon for changes to take effect
systemctl restart rsyslog
- Configure logrotation for gardena2influxdb.log by creating
/etc/logrotate.d/gardena2influxdb
with the following content
/var/log/gardena2influxdb.log {
su root syslog
daily
rotate 5
compress
delaycompress
missingok
postrotate
systemctl restart rsyslog > /dev/null
endscript
}
After the first events will go to the InfluxDB you can create nice Grafana dashboards.
- In case the script fails to connect to the websockets, it might be due to compatibility issues with the websocket-client library around version 0.53.0. Trying upgrade to the latest version via
pip3 install --upgrade websocket-client
if running the script locally or rebuild the docker containers.
Have fun !
MIT
Free Software, Hell Yeah!