Can someone share insight why Influxdb wasn’t used for the Energy work?
Im not reading HA devs minds, but here are two likely reasons:
-
Influx support of the SQL language is either “none” or “SELECT only” depending on version. HA uses SQLAlchemy to talk to the database, and that needs SQL.
-
Need to ship a lightweight database and SQLite is absolutely fine for this use. Makes for simple installation.
If you only intend to log energy use, once per hour is fine, and SQLite will handle that.
I realize this is a vague question but am curious if people have gone down this thought-path and where they landed?
I installed solar panels (12kW), inverters, batteries, and an EV charger. Here’s the EV charger (pink) responding to clouds.
All the hardware speaks Modbus, so this is controlled by an Orange Pi Lite with Waveshare USB-RS485 interfaces. There are 8 RS485 ports.
It’s a bunch of python scripts talking to each other via MQTT.
Most of the stuff is queried 2-10 times/s and published to MQTT with slight rate limiting so it results in a very low throughput of 50-100 messages/s.
This tiny Pi has redundant power supply (AC mains and PV battery via 48V isolated DC-DC). I didn’t find any package to persist MQTT traffic so another python script grabs all the MQTT traffic, timestamps it and stuff it into zstd compressed files, which it stores and serves.
The Linux PC serving as house NAS queries that and stores everything into Clickhouse. If it is shut down, it will grab the MQTT backlog from the Pi on power up and update.
I considered InfluxDB, in the end I went with Clickhouse for the compression features. Each MQTT message as a row in the table uses about 1 byte of disk space, so keeping all the data costs basically nothing.
I used automatic materialized views to compute hourly/daily min/max/avg, another convenient feature. These are mostly to avoid overwhelming the plotting engine when zooming out.
I used bokeh for plotting. Couldn’t figure out how to tell grafana to combine streaming MQTT data with older data from SQL and switch to different queries depending on zoom levels to use the materialized views to keep it fast.
This uses about 4% cpu on the Pi and 0.5% on the NAS.
Now you ask, which one should you use?
I think if you just want to log energy, once per hour is fine, that’s 8760 rows/year. SQLite will work absolutely fine. 1 state row uses about 80 bytes, let’s say 1MB/year/sensor. No problem at all.
If you want real time then you will need a time series database like clickhouse or influx, and a functional plotting package (ie, not HA default one).
But iotawatt only updates every 5 seconds so it’s not exactly “real time”, not optimal for solar power routing for example. And unless you want to control devices in real time, then why would you care about plotting power at 1 second granularity? 1 hour is fine. The reason I store everything in the database is to debug the stuff, and controlling the damn EV charger took a lot of debugging.
I also display the solar stuff in HA, but I excluded it from the recorder. So all the display updates in real time, but it doesn’t choke out the poor SQLite. The use of my energy dashboard is mainly to check if everything is fine, look at home battery state, and input settings for the EV charger.