Home Assistant: Installing InfluxDB (LXC)

By default Home Assistant will store approximately 10 days worth of entity data that allows you to do cool charts, graphs and dashboards. This is called recorder data. Recorder data is stored in a SQL (relational) database, which by default is SQLite. However, if you want long term storage of your entity data for reporting, for instance, you need to use InfluxDB. InfluxDB is not a relational database, but rather a time-series database. It’s great for long term data retention and has great Grafana integration for amazing charts and graphs. Grafana can be used to chart or dashboard data spanning months or years. 

InfluxDB does NOT replace Home Assistant’s recorder (SQLite or MariaDB) database. The short term recorder database remains, but InfluxDB compliments it for long term storage of sensor and event data. Even if you configure Home Assistant to use MariaDB for recorder data, you would still use InfluxDB for long term storage and reporting. InfluxDB does not come installed out of the box with Home Assistant, unlike SQLite for recorder data. 

This post will cover installing InfluxDB 1.8 in a LXC container on Proxmox using the tteck script and integrating it with Home Assistant. Yes, you can install InfluxDB as a Home Assistant add-on and run it inside HAOS. However, the purpose of the database is long term storage of data. And that data could become large over time. So if you run InfluxDB inside HAOS, your HAOS backups can become large. And if you are using a backup add-on like Google Drive (highly recommended), that just requires even more cloud storage. Even worse, if your backups are over 1GB then restoring them is a pain. You can find the full details in my Home Assistant: Restoring your Configuration post. It doesn’t matter what type of HAOS install you have (bare metal, VM, Raspberry Pi, etc.), you can still use an “external” InfluxDB instance. We will be setting up an InfluxDB LXC instance on Proxmox, but your HAOS install can be anywhere.

Sample Grafana chart with InfluxDB Data

In this post we are going to be covering the following topics:

  • InfluxDB Tips
  • Installing InfluxDB v1.8 in a LXC container on Proxmox 7.4
  • Configuring an InfluxDB database for Home Assistant
  • Configuring Home Assistant to send data to InfluxDB
  • Validating that InfluxDB is receiving data

InfluxDB Tips

When it comes to databases, and specifically InfluxDB, there are a few things to keep in mind:

  • Databases need disk I/O. Depending on how much data you are sending to InfluxDB the I/O load will vary. If your Home Assistant instance is running on a SD card (e.g. a Raspberry Pi), don’t consider installing InfluxDB on your RPi. Proxmox isn’t supported on RPi anyway, so you couldn’t follow this tutorial if you wanted to. Run InfluxDB off a SSD or NVMe drive. 
  • Doing backups of InfluxDB is super important. I wrote a post on backing up InfluxDB: InfluxDB 1.x Automated Backups. This post walks you through how to setup ‘portable’ InfluxDB backups inside the LXC container. This works great in conjunction with Proxmox backups to ensure you have an application consistent copy of your database that you can restore from.
  • If you aren’t doing Home Assistant backups, I strongly urge you to use the Home Assistant Google Drive Backup integration. It is highly configurable and rock solid. Should you ever need to restore or migrate your HAOS instance, check out my post Home Assistant: Restoring your Configuration.
  • It is not advisable to just throw all of your HA data into InfluxDB. You will likely be storing a ton of data that is useless and will just bloat your database and backups. There’s a great article on InfluxDB configuration parameters. Specifically, you can use exclude and include options to reduce data sent to InfluxDB. Think carefully about what data you want to keep long term.
  • Beyond just filtering what data goes into InfluxDB, it is likely that for medium to long term data you can downsample your data. What is downsampling? Let’s say you record solar power production every 30 seconds. Do you really need 30 second resolution for data going back years? Probably not. You can run InfluxDB jobs that reduce that data to say 5 or 15 minute intervals. This can drastically shrink your database and make queries faster.
  • Tracking the size of your InfluxDB is tricky. Yes, if you search the HA forums or blog posts you will see HA sensor YAML configurations that try to report the database size. However, the query is often WILDLY inaccurate. Forums are full of people complaining about inaccurate DB size data. In my case, the query returned 1.4GB DB size when in fact mine was just about 30MB. So personally I would just monitor the disk free space in the LXC via the Home Assistant Proxmox integration
Proxmox HA Integration Card for the InfluxDB LXC

InfluxDB LXC Installation

  1. Login to Proxmox and select your Proxmox server in the left pane.
  2. Click on Shell in the middle pane.
  3. Enter the following command to start the InfluxDB LXC install. Press Enter on Yes.
				
					  bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/ct/influxdb.sh)"

				
			

4. Select Advanced.

5. Leave Container Type Unprivileged.
6. Enter a complex password.
7. Accept the container ID.
8. Set the Hostname.
9. Change the Disk Size as needed.
10. Change Core Count as needed.
11. Change RAM as needed (InfluxDB is not memory hungry. I’d suggest starting with 1024).
12. Leave the Bridge.
13. Optionally set a static IP (e.g. 192.168.10.45/24).
14. Set a Gateway IP.
15. Don’t disable IPv6 (unless you need to).
16. Leave MTU Size.
17. Set DNS Search Domain (if needed).
18. Set a DNS server IP.
19. Leave the MAC address blank.
20. Leave the VLAN.
21. Enable Root SSH access.

22. Don’t enable verbose mode.
23. Press enter on Yes, Create InfluxDB LXC.
24. Select your storage by using the arrow keys, then press space to select, and tab to OK.
25. Again, select the storage you want to use.
26. Select version 1 of InfluxDB.

Note: InfluxDB v2 is an entirely different beast. While it is compatible with Home Assistant, Grafana’s support for the v2 query language is in beta. And v2 Grafana queries require more manual effort to build. This post assumes v1.x. V2 requires very different setup steps.

27. Answer YES to Telegraf (Not required for HA, but can useful if you expand InfluxDB use cases).
28. Check the Proxmox UI and verify the LXC container was created.
29. Go to InfluxDB Downloads, go down to Are You Interested in InfluxDB 1.x Open Source? Go down to Chronograf and select Ubuntu & Debian.
30. In Proxmox open the console for the InfluxDB LXC. Use the commands shown on their web page. And example is shown below:

				
					wget https://dl.influxdata.com/chronograf/releases/chronograf_1.10.1_amd64.deb
sudo dpkg -i chronograf_1.10.1_amd64.deb
				
			

31. If you don’t know the IP of your container type ip a
32. Open a web browser and go to http://IP:8888. You should get the Chronograf welcome screen.

InfluxDB Configuration

  1. On the welcome screen click Get Started.
  2. Accept the defaults on the InfluxDB Connection.
  3. Skip the dashboard creation.
  4. Skip Capacitor Connection.
  5. Click View All Connections. You should now see a screen similar to the one below.

6. Click on the crown looking icon (InfluxDB Admin) in the left toolbar. 
7. In the upper right click on Create Database.
8. Name your database (e.g. home_assistant) and click the green check box.
9. You should now see your database created with infinite Duration.

10. Click on the Users tab (next to Databases at the top).
11. Click on Create User in the upper right corner.
12. Enter a username (e.g. homeassistant) and a complex password. Keep this password safe.
13. Click on Grant Admin in the upper right. Click on Grant ALL Privileges.
14. Click on the Databases tab then click on Users again. Your screen should now look like the one below.

15. In Home Assistant open your configuration.yaml file (recommend using Studio Code Server).
16. Copy the YAML below and change the host IP address. Everything else can stay the same, unless you have other preferences. Save the YAML file.

				
					
influxdb:
  host: 192.168.10.10
  port: 8086
  api_version: 1
  max_retries: 3
  password: !secret influxdb_password
  username: homeassistant
  database: home_assistant
  measurement_attr: unit_of_measurement
  default_measurement: units
  ssl: false
  verify_ssl: false
  tags:
    source: HA
  tags_attributes:
    - friendly_name
    - unit_of_measurement
				
			

17. Open the secrets.yaml file.
18. Add a line using the following syntax and paste in your complex password. Save the YAML file.

				
					influxdb_password: your_password_here
				
			

19. Go to Developer Tools, click on YAML at the top, then click on Check Configuration. Verify everything is good.
20. Click on the red RESTART.

Verifying InfluxDB Data Connection

  1. In the InfluxDB UI click on Explore icon (under the eyeball).
  2. Expand Query 1 and on the left click on home_assistant.autogen.
  3. The Measurements & Tag column should populate with items.
  4. Depending on what integrations and sensors you have, you should be able to find some data values. 
  5. You might try units under Measurements & Tags, expand domain, and click on sensor. Then click on value in the right most column.
  6. It’s likely you will now see data values in the upper pane. You may need to change the timeframe in the upper right to a longer period such as Past 24h.
Below is a sample query that in my case returned valid HA data:
				
					SELECT mean("value") AS "mean_value" FROM "home_assistant"."autogen"."units" WHERE time > :dashboardTime: AND time < :upperDashboardTime: AND "domain"='sensor' GROUP BY time(:interval:) FILL(null)
				
			

Summary

Setting up InfluxDB as a LXC container is fairly straight forward thanks to the tteck script. Configuring Home Assistant to use InfluxDB is also not too difficult, even though it does require manual YAML editing.

Be sure to also check out my InfluxDB 1.x Automated Backups post. This post walks you through how to setup ‘portable’ InfluxDB backups inside the LXC container. This works great in conjunction with Proxmox backups to ensure you have an application consistent copy of your database that you can restore from. After you have InfluxDB setup and receiving data, you can now Install Grafana in a LXC to do awesome graphs and dashboards.

Print Friendly, PDF & Email

Related Posts

Subscribe
Notify of
8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Chris
May 8, 2023 9:45 am

Thank you for this great article!
I’d like to give it a try. So far I’ve only used Docker (never LXC) and when I run a InfluxDB in Docker I would create a volume to make the data persistent. How does it work with LXC? It seems you didn’t mention anything about it. So what happens if the LXC container stops or if I simply restart my Proxmox server? The data in the database is not lost, I hope?

August 26, 2023 5:30 am

Thanks for this article. I followed all the steps painstakingly. Al went well until verfying the data connection.
The homeassistant autogen stays completely empty…….

John M
September 14, 2023 8:47 am

Thanks for all the guides. I am getting my HA setup and your guides helped me get into this very quickly. Can you clarify step 29? I select Ubuntu and Debian from the InfluxDB download web page but not sure what I do next.

Dan
November 21, 2023 7:41 am

Thanks for this guide. I have InfluxDB running as a HAOS add-on, but I’d like to factor it out to an LXC container so it can run as a metric server for PVE keep running even when I take down HAOS for maintenance.

How should I go about migrating the InfluxDB database in the HAOS addon to LXC?

Dan
November 21, 2023 10:39 am
Reply to  Derek Seaman

I found this: https://community.home-assistant.io/t/howto-migrate-influxdb-data-to-another-server-on-hassio/164405/5 👍 but I’ve yet to try it.

In particular, I am moving HAOS from arm to intel, so even using your simple HAOS backup/restore guide, I’ll have to force-rebuild (?) the influxdb docker container https://github.com/hassio-addons/addon-influxdb/blob/6372a635135e5b7154d8b6d43aee39133860568b/influxdb/Dockerfile#L27

Or will docker know to rebuild after HAOS restore?