Unreliable InfluxDB size sensor

I found this thread very helpful in setting up my DB size sensor.

Perhaps just a few notes on what I had to do to get it working as a noob:

In the SSH & Web Terminal addon, you have to put the init_commands into the init_commands field. You don’t use the ‘- >-’ part if doing it like this:

    while [ 1 = 1 ]; do docker exec addon_a0d7b954_influxdb du -s
    /data/influxdb/data/homeassistant | mosquitto_pub -t
    home-assistant/sensor/dbsize -r -u <user> -P <password> -l && sleep
    300; done &

Remember to change the username and password with your MQTT broker username and password. Also make sure the db name matches what you have in the command. In my case the db was called home_assistant not homeassistant.

The whole entry that goes into configuration.yaml looks like this:

mqtt:
  sensor:
    - name: InfluxDB DB Size
      unit_of_measurement: "MB"
      icon: hass:chart-line
      state_topic: "home-assistant/sensor/dbsize"
      value_template: "{{ (value.split('\t')[0]|int(0)/1000)|round(3) }}"

That worked for me.

3 Likes