This script fetches a Gadgetbridge database export from a WebDAV server (in my case, Nextcloud) and then queries it to extract stats from Huami devices such as the Amazfit Bip so that they can be written onwards into InfluxDB.
Original design and build notes are in MISC#34.
The project actually initially had to be abandoned because it was found that the Bip3 didn't work with Gadgetbridge. However, that has since changed and development resumed.
Gadgetbridge needs to be configured to periodically export its database to a WebDAV target.
An example can be found here of doing that using Nextcloud.
The script is designed to be run in an ephemeral container, so pulls configuration from environment variables
WEBDAV_URL
: The webdav server URL. If you're using nextcloud, this will behttps://[nextcloud domain]/remote.php/dav/
WEBDAV_USER
: WebDAV usernameWEBDAV_PASS
: WebDAV PasswordWEBDAV_PATH
: Path to the export directory on the webdav server (in my case it wasfiles/service_user/GadgetBridge/
EXPORT_FILENAME
: The filename of the export file on the webdav server (I called minegadgetbridge
)QUERY_DURATION
: What time period (in seconds) should we query? Default is86400
INFLUXDB_URL
: URL of your InfluxDB serverINFLUXDB_TOKEN
: Your influxDB token (oruser:pass
if you're on 1.x)INFLUXDB_ORG
: Your InfluxDB org name or IDINFLUXDB_BUCKET
: The bucket/database to write intoINFLUXDB_MEASUREMENT
: The measurement to write into (Defaultgadgetbridge
)SLEEP_HOURS
: Comma seperated list of hours to consider as sleeping hours for stress averaging purposes (default0,1,2,3,4,5,6
)
The script is designed to be run from a container, so the easiest invocation route is
docker run --rm \
-e WEBDAV_URL=https://nextcloud.example.invalid/remote.php/dav \
.. etc .. \
bentasker12/gadgetbridge_to_influxdb:latest
However, if you want to run directly, install the dependencies
pip install webdavclient3 influxdb-client
Then, having exported the necessary env vars, simply invoke the script
./app/gadgetbridge_to_influxdb.py
If, instead, you want to schedule runs in Kubernetes see the examples here.
Copyright (c) 2023 B Tasker Released under BSD 3-Clause License