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.


  1. Make sure you have InfluxDB 2.x running and InfluxDB 2.x configured for use with Home Assistant.
  2. The InfluxDB data directory must be mapped as a volume named influxdb_data. In summary, you need to add the following to your Docker run script. For me this is homeassistant_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.


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:

    - /influxdb_data

Also make sure the following is added:

sensor: !include sensors.yaml

Exit Nano (CTRL-X) and save the changes.


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


    No comments found for this note.

    Join the discussion for this note on this ticket. Comments appear on this page instantly.


    Notes mentioning this note

    Notes Graph