Reduce/delete values

Hello

I have a power plug which records the power consummation. This works fine. The problem is, that this plug displays every 5 seconds a new value. I tried to reduce, but it seams not to work. So at the end I have about 50’000 values a day. This is too much to display as a chart.

So I created a sql sensor which runs every 5 minutes:

  - platform: sql
    scan_interval: 600
    queries:
      - name: Power History Total
        query: "SELECT * FROM states WHERE entity_id = 'sensor.power_total' ORDER BY state_id DESC LIMIT 1;"
        column: 'state'

This works very well. I see my chart and I am happy. But now how can I delete after this 5 minutes the values?
At the moment I am storing values for 2 days. I want to increase to maybe a week. So I need to delete all this garbage/source values.

Thanks for any ideas
Gilbert

you can decide when to purge values from your recorder


there are also options to exclude/include specific domains/entities…

I tried, but it ignores the value. I tried:

  - platform: template
    sensors:
      power1:
        friendly_name: "Waschmaschine"
        unit_of_measurement: "W"
        value_template: "{% if states.switch.esszimmer_luftbefeuchter.attributes.current_power_w %} {{ states.switch.esszimmer_luftbefeuchter.attributes.current_power_w }} {% else %} 0 {% endif %}"
        scan_interval: 120

which gives an error. then i tried

  - platform: template
    scan_interval: 120
    sensors:
      power1:
        friendly_name: "Waschmaschine"
        unit_of_measurement: "W"
        value_template: "{% if states.switch.esszimmer_luftbefeuchter.attributes.current_power_w %} {{ states.switch.esszimmer_luftbefeuchter.attributes.current_power_w }} {% else %} 0 {% endif %}"

gives no error, but still a lot values.

thanks for the fast answer. I already have studied the component recorder.

My problem is that

  • the source template sensor has a lot of values.
  • the destination sql sensor updates every 5 minutes.

So I think if I exclude the source sensor, the sql sensor has no values to read. Or did I understand something wrong?

You will still get the same amount of data, but it won’t fill your db if you purge often. you could set a statistics sensor to help reduce the data to be displayed on your chart