State Data to InfluxDB

Hello fellow automation geeks!

I needed a solution for my very large Home Assistant database of 27 GB (growing by the minute).
After a quick search I decided to go with InfluxDB and Grafana.
Unfortunately, Home Assistant doesn’t have a built-in way to migrate historical data to InfluxDB. Since I couldn’t find any recent discussions or solutions for this, I teamed up with ChatGPT to create a Python script that copies Home Assistant historical data from an SQLite database to an InfluxDB bucket.
Tested with Home Assistant Core 2024.10.1 and InfluxDB v2.7.10.

I run both HA, Influx and Grafana in separate Dockers.

You can check it out on GitHub:

My next step is to create a nice Grafana Dashboard.
Comments or hits are welcome!

For setting up InfluxDB and Grafana with HA, I used this reddit post for reference:
https://www.reddit.com/r/homeassistant/comments/oje65v/home_assitant_with_grafana_and_influxdb_2x_basic/

Hello eldigo,

Put this string into your search engine…

site:home-assistant.io migrate old data to influx

It’s amazing what a small search will do,

Like I’d said, no recent solution that works with the new ha database changes early 2023.

If you have the schema from that search, can you do something? Tye it together with the process in other posts maybe?
Long- and short-term statistics | Home Assistant Data Science Portal.

Not sure what you pointing out, but my script already works with the new database schema.
It insert values into influxdb nicely.

I’m just mentioning it on the forum so people can find it :slightly_smiling_face:

Edit: note that I had a 600 days retention in HA
The real reason why my database is that large.

do this script extract only short term data or also long term historical data?

No only short term.
Haven’t figured out to get all the attributes you have in short term states table, on the the long term statistics table.

If this doesn’t match up, it’s almost pointless to load the long term stats as they won’t “connect” to the live data that is inserted by HA.

Hi Eldigo,

I’ve been using influxdb for more than a year now. Could I use your script to import only the data that aren’t in influx db yet? Does your script check the existing data in influx, or it duplicates them?

Thx in advance.

The script looks at the earliest date in influx and gets data from HA earlier than that. So no duplicate data.

Note that it only gets data from states table in HA not historical tables.