Qingping2InfluxDB is a project that enables the collection of environment data from Qingping smart devices (especially the Qingping Air Monitor Light) and stores it in an InfluxDB database. The connector.py script is designed to be run in the background and pushes every 20 seconds to influxdb the power metrics of the power plugs you choose. It was build upon the Qingping OpenAPI Spec and currently (2024-05-25) working with the latest Qingping API version. It utilizes the official python InfluxDB Client in order to publish data to your InfluxDB instance. Thanks to the authors of these packages which made this little project possible. It comes ready-to-use in a docker package which can be used multi-platform. Out-of-the box the script scrapes every 20 seconds the power metrics from the chosen devices and pushes them to InfluxDB. This can be changed in the source code quite easily.
There is a multiplatform docker image for this code available on docker hub, an example setup is provided with docker-compose.yml. Just put the docker-compose.yml somewhere on your computer, change the environment variables to your setup and start the container with docker compose up -d
(older docker installation: docker-compose up -d
).
If you want to use docker run instead of docker compose (not recommended! :shipit:), you can use:
docker run -d --restart unless-stopped --name Qingping2InfluxDB \
-e QINGPING_APPKEY=QINGPING_APPKEY \
-e QINGPING_APPSECRET=QINGPING_APPSECRET \
-e API_BASE_URL=http://user-api-base-url \
-e INFLUXDB_URL=http://user-influxdb-url \
-e INFLUXDB_TOKEN=user_token \
-e INFLUXDB_ORG=user_org \
-e INFLUXDB_BUCKET=user_bucket \
quantensittich/qingping2influxdb:latest
In order to test the quingping setup and see all devices that are currently available, the script deviceinfo.py is included in this repository. After filling out the config.env file with your credentials and removing the .example file ending, run the device info script once to get an overview over all avaiable devices. For each device you want to write the data to InfluxDB, please fill the exact names into line 31 in connector.py.
Set Up Python Environment:
python -m venv quingping-env
source quingping-env/bin/activate # On Windows, use `quingping-env\Scripts\activate`
Install Dependencies:
pip install -r requirements.txt
Configuration:
config.env
file in the project directory with the following content, filling in your own details (see config.env.example):
QINGPING_APPKEY=your_QINGPING_APPKEY_account_email
QINGPING_APPSECRET=your_QINGPING_APPSECRET_account_password
API_BASE_URL=api_base_region
INFLUXDB_URL=your_influxdb_url
INFLUXDB_TOKEN=your_influxdb_token
INFLUXDB_ORG=your_influxdb_org
INFLUXDB_BUCKET=your_influxdb_bucket
DEVICE_NAMES_TO_MONITOR=your_devices_seperated_by_comma
FETCH_INTERVAL=20
#DEBUG=TRUE #comment out if shell be enabled.
Running the Script:
python connector.py
Monitoring:
fetch_interval
in the script to control how often data is fetched from the devices.There is a dockerfile provided in this repository which allows you to build your own image of QingpingToInfluxDB. If you want to build the image multi-platform, there is a buildx-example-script provided aswell.
I wrote a blog article in German about this Project. Check it out!
This project is published multi-platform on the Docker-Hub.