A robust Python service to ingest ESPHome MQTT data into a TimescaleDB multi-table schema.
Project description
ESPHome MQTT to TimescaleDB Ingestor
A robust Python service that listens for ESPHome data on an MQTT broker and persists it into a structured, multi-table TimescaleDB database.
This project is designed to work with the standard ESPHome and Home Assistant discovery protocols, handling various message types including device discovery, entity configurations, real-time state updates, and commands.
Features
-
Connects to an MQTT broker and subscribes to all relevant ESPHome and Home Assistant topics.
-
Intelligently processes and stores five distinct types of messages.
-
Automatically creates the necessary database tables on the first run.
-
Uses a multi-threaded, queue-based architecture for high performance and resilience.
-
Supports intelligent batch processing for efficient database writes.
Installation
Install the package directly from PyPI:
pip install esphome-mqtt-timescaledb-ingestor
Configuration
The ingestor is configured using environment variables. Before running, you must set the following:
-
MQTT_BROKER_HOST: The hostname or IP address of your MQTT broker. -
MQTT_BROKER_PORT: The port number of the MQTT broker (default is1883). -
MQTT_USERNAME: The username for the MQTT broker (if required). -
MQTT_PASSWORD: The password for the MQTT broker (if required). -
DB_HOST: The hostname or IP address of your PostgreSQL/TimescaleDB server. -
DB_PORT: The port number of the database (default is5432). -
DB_NAME: The name of the database to use. -
DB_USER: The username for the database. -
DB_PASSWORD: The password for the database user.
Usage
Once the package is installed and your environment variables are configured, you can run the ingestor using the console script created during installation:
mqtt-ingestor
The service will start, connect to MQTT and the database, and begin processing messages.
Testing
To run the tests, clone the repository, install the development dependencies, and run pytest:
git clone [https://github.com/paandayankur/mqtt-to-timescaledb-ingester.git](https://github.com/paandayankur/mqtt-to-timescaledb-ingester.git)
cd mqtt-to-timescaledb-ingester
poetry install --with dev
poetry run pytest
Contributing
Contributions are welcome! Please feel free to open an issue or submit a pull request for any improvements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file esphome_mqtt_timescaledb_ingestor-0.1.2.tar.gz.
File metadata
- Download URL: esphome_mqtt_timescaledb_ingestor-0.1.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.11.0 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f3b3cedca06a940f1e082034e374fcab6e7544535a14fb929de9eb657434011
|
|
| MD5 |
f6c5e77df8583b4aea201d68ac84983e
|
|
| BLAKE2b-256 |
f654e1d3db4fbb11d05b213103d3ba8e684ca8a8ce4d0a235df9eaeaa02f1b3f
|
File details
Details for the file esphome_mqtt_timescaledb_ingestor-0.1.2-py3-none-any.whl.
File metadata
- Download URL: esphome_mqtt_timescaledb_ingestor-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.11.0 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6178bfaab559b24ba27c34b2488147c5987250d55e93b7c6348539707b17ec5d
|
|
| MD5 |
734f80ae367f6a73a9f566ddaed183bc
|
|
| BLAKE2b-256 |
77cd396425f34a1e4c659c5554b33f4976cfbfa108b48191ecdacfe48f6d0615
|