This script transfers historical data from a Home Assistant SQLite database to InfluxDB. It retrieves the earliest records from the InfluxDB bucket and extracts the states, attributes, and friendly names from the Home Assistant database for records prior to that. Created using ChatGPT and tested with Home Assistant Core 2024.10.1 and InfluxDB v2.7.10. Follow the steps below to set up the environment and run the script.
- Python 3.6 or higher
- A SQLite database file you wish to import data from
- An InfluxDB instance running and accessible
Clone the repository or download the script files to your local machine.
git clone https://github.com/eldigo/ha-sqllite-2-influxdb
cd ha-sqllite-2-influxdb
Create a Python virtual environment to isolate the project dependencies.
python3 -m venv myenv
Activate the virtual environment:
source myenv/bin/activate
Install the required packages using the requirements.txt
file provided.
pip install -r requirements.txt
Copy the .env.example
file to a new file named .env
and fill in the required values. You can use the following command:
cp .env.example .env
Open the .env
file in a text editor and provide the necessary configurations for your InfluxDB connection.
INFLUXDB_URL=http://localhost:8086
INFLUXDB_TOKEN=your_token
INFLUXDB_ORG=your_organization
INFLUXDB_BUCKET=your_bucket
SQLITE_DB_PATH=/path/to/your/sqlite.db
DEBUG_MODE=false
When DEBUG_MODE is true. The script will insert into Influx point by point
Run the script using the following command:
python3 sqllite2influxdb.py
Make sure that your SQLite database file is correctly specified in the .env
file, and that your InfluxDB instance is running and accessible.
This project is licensed under the MIT License - see the LICENSE file for details.