Influxdb: write to db only every <time>

Hi everybody,

I used to have influxdb set up like this

influxdb:
  host: !secret influxdb_host
  port: !secret influxdb_host
  database: !secret influxdb_database
  username: !secret influxdb_username
  password: !secret influxdb_password
  ssl: false
  verify_ssl: false
  max_retries: 3
  default_measurement: state

  include:
    entities: 
    # (...)
    domains:
    # (...)

  tags:
    instance: prod
    source: hass

This does exactly what it should for, let’s say binary_sensor / input_boolean entities. Their status changes, it gets logged. However, when I have something like sensor.temperature_printer (in this case, a DS18B20 on ESPHome), the state might change by the minute (or even 6 times per minute or so), which generates a lot of data.

Is there a way to limit this? I am looking for something in the likes of

# (...)
  include:
    entities:
      - entity: sensor.tempearature_printer
        interval: 2m # / 120s
        only_on_change: true

This is arbitrary yaml, but what I mean is: for entity sensor.temperature_printer log value every 2m; if value has not changed, don’t log it (otherwise do log it).

Prior to ESPHome, I had every single sensor integrated via zigbee2mqtt, so I could just let node-red take care of this; however, I don’t think it is the best solution to generate automations to send changes from the ESPHome entities to mqtt just so that node-red can work with them. There ought to be a better solution. Is there and I just missed it?

Thank you for your ideas :slight_smile:

1 Like

I don’t believe that is possible at the moment.

Ideas:

  • Use Influxdb continuous queries to filter/aggregate the data
  • Create template sensors with a lower update frequency and push those to influx
  • Use a lower update frequency in your ESPHome nodes (they don’t push updates without change anyway (by default))

Also:

  • Open a feature request for your desired filter configuration

From personal experience: Data updates in Influx DB use less space than I expected.

There solution by using python_script integration

This is not a solution for the problem mentioned here.

There are multiple problems when only writing to influx on state changes

  1. states which update very frequently are written too frequently to influxdb, this causes data bloating because usually influxdb is used for long term recording. You can have a home-assistant dashboard with sensors which update every second, but it would be enough for influx to store a value every 5 minutes.
  2. states which update rarely are rarely written to influxdb and can make the series to look outdated as no new data can be pushed for days while the sensor state is still valid.

The proposed solution by you only addresses problem 2, not problem 1.

I am also looking for a solution as prankousky proposed.