Recorder purge keep some entities longer

I have the recorder set to purge every day, keeping 7 days of history. I’d like to add a speed test sensor, but would like to keep this history permanently (or at least several months). Is it possible to treat this sensor differently?

Not in the standard sql database at the moment. I keep my long term data using influxdb.

1 Like

Ah, is it possible to have multiple recorder instances with different entities included and excluded? Then they could have different purge times.

So I installed InfluxDB and now I have HA run speed test a few times a day and output to the influx database. I can now exclude these sensors from the normal record if I want (but I’ll probably just keep them in HA so I can quickly get a graph).

My yaml is as follows, for anyone interested. configuration.yaml:

influxdb:
  default_measurement: "measure_unknown"
  override_measurement: "%"
  component_config:
    sensor.speedtest_download:
      override_measurement: "Mbps"
    sensor.speedtest_upload:
      override_measurement: "Mbps"
    sensor.speedtest_ping:
      override_measurement: "ms"
  include:
    entities:
      - sensor.load15
      - sensor.speedtest_download
      - sensor.speedtest_upload
      - sensor.speedtest_ping

Sets up the connection to influxdb and adds those entities into that database.

sensors.yaml:

- platform: speedtest
  monitored_conditions:
    - ping
    - download
    - upload
  minute: 17
  hour:
    - 0
    - 4
    - 8
    - 12
    - 16
    - 20
- platform: influxdb
  queries:
    - name: Mean download speed
      measurement: '"Mbps"'
      where: '"entity_id" = ''speedtest_download'' and time > now() - 7d'
      unit_of_measurement: 'MBit/s'
      value_template: '{{ value | round(1) }}'
    - name: Mean upload speed
      measurement: 'Mbps'
      where: '"entity_id" = ''speedtest_upload'' and time > now() - 7d'
      unit_of_measurement: 'MBit/s'
      value_template: '{{ value | round(1) }}'
    - name: Mean ping
      measurement: '"ms"'
      where: '"entity_id" = ''speedtest_ping'' and time > now() - 7d'
      unit_of_measurement: 'ms'
      value_template: '{{ value | round(1) }}'

Sets up the speedtest to run every 4 hours and then HA fetches the mean value from influxdb. One thing to note that I didn’t see documented is that the where parameter has very specific syntax. The whole thing should be wrapped in single quotes, the key (entity_id above) is in double quotes, and the value (speedtest_download above) needs to be wrapped in two single quotes (one set for the actual query and one set to escape it in yaml language).

groups.yaml:

speedtest:
  name: Internet Monitor
  control: hidden
  entities:
    - sensor.mean_download_speed
    - sensor.mean_upload_speed
    - sensor.mean_ping
    - weblink.stats

Sets up a group with a link to Grafana in case I want more detail.

All seems to be working perfectly!

2 Likes