Home Assistant - Setup InfluxDB 2.x Database Size Sensor
Here I describe how to create a sensor for Home Assistant that will monitor the size of the InfluxDB 2.x database with a scan interval of one hour.
This topic helped me on my way.
Dependencies
- Make sure you have InfluxDB 2.x running and InfluxDB 2.x configured for use with Home Assistant.
- The InfluxDB
data
directory must be mapped as a volume namedinfluxdb_data
. In summary, you need to add the following to your Docker run script. For me this ishomeassistant_run.sh
:-v /home/USER/docker/influxdb/data:/influxdb_data \
Replace the following:
-v /home/USER/docker/influxdb/data:/influxdb_data
Replace/home/USER/docker/influxdb/data
with the full path to the InfluxDB data directory
This will only work if InfluxDB is on the same machine as your Home Assistant instance.
Configuration
I run the following on the CLI of my Ubuntu VM.
Go to the config
directory of Home Assistant and edit configuration.yaml
with the Nano text editor:
sudo nano configuration.yaml
Make sure the following is added to the configuration.yaml
:
homeassistant:
allowlist_external_dirs:
- /influxdb_data
Also make sure the following is added:
sensor: !include sensors.yaml
Exit Nano (CTRL-X) and save the changes.
Sensor
Edit sensors.yaml
:
sudo nano sensors.yaml
Add the following:
- platform: command_line
name: InfluxDB size
scan_interval: 3600
command_timeout: 30
command: "du -shm /influxdb_data | cut -f1"
unit_of_measurement: MB
value_template: ""
If needed replace the following:
scan_interval: 3600
The scan interval in seconds. In this example the scan interval is one hour
Exit Nano (CTRL-X) and save the changes.
Using the Sensor
Now go to the Home Assistant UI and check your configuration via Configuration
> Settings
> Server Controls
> Check Configuration
(the button).
When the configuration is valid restart the server and you can use the sensor.
The sensor is also added to the Overview
dashboard if it is still maintained by Home Assistant (which is default).
Read other notes
Tags
Notes mentioning this note
- Docker - Home Assistant Container Setup with MariaDB and InfluxDB 2.x
Here I describe my setup of the Home Assistant container with MariaDB and InfluxDB 2.x.
Comments
No comments found for this note.
Join the discussion for this note on this ticket. Comments appear on this page instantly.