Skip to content

How to add InfluxDB 2.x database size sensor to Home Assistant

Introduction

How to add a sensor to Home Assistent to monitor the size of the InfluxDB 2.x database with a scan interval of one hour. This topic helped me on my way.

Requirements

Make sure you have:

  • InfluxDB 2.x running on the same machine as your Home Assistant instance
  • Home Assistant configured
  • Home Assistant must have access to the data folder of InfluxDB. So if you are using the InfluxDB docker container then the InfluxDB data folder must be added as volume influxdb_data. Add the following to your docker container variables:
# To edit use your text editor application, for example Nano
-v /home/<username>/docker/influxdb/data:/influxdb_data \
# IMPORTANT: Please read the instructions below
Instructions:
  • Required Replace /home/<username>/docker/influxdb/data with the full path of the InfluxDB data directory

How To

  1. Modify configuration.yaml

    Go to the config folder of Home Assistant and add the following to configuration.yaml:

    homeassistant/config/configuration.yaml
    # To edit use your text editor application, for example Nano
    homeassistant:
    allowlist_external_dirs:
    - /influxdb_data
    sensor: !include sensors.yaml
  2. Add the sensor to sensors.yaml

    Add the following to sensors.yaml:

    homeassistant/config/sensors.yaml
    # To edit use your text editor application, for example Nano
    - 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: "{{ value }}"
    # IMPORTANT: Please read the instructions below
    Instructions:
    • Optional Replace <3600> with the scan interval in seconds. In this example the scan interval is one hour
  3. Check the results

    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 then 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).

Favorites

Comments

    No comments found for this note.

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

    Copyright 2021- Fiction Becomes Fact