History_stats - unknown

Hi,

I have:

  - platform: history_stats
    name: Water this week
    entity_id: switch.water
    state: "on"
    type: time
    end: "{{ now()}}" 
    duration:
      days: 7
      
  - platform: history_stats
    name: Water last week
    entity_id: switch.water
    state: "on"
    type: time
    end: "{{(as_timestamp(now()) - 604800)}}" 
    duration:
      days: 7

The first gives an output, but the 2nd is unknown. how is this unknown?

image

For the second one try this instead:

end: "{{(now() -  timedelta(days=7)}}" 

Also, is your recorder configured to store 14 days?

The default is 10. https://www.home-assistant.io/integrations/recorder/#purge_keep_days

Hi Tom,

thanks for helping out.

I tried:
end: "{{(now() - timedelta(days=7))}}" with an extra ‘)’.

But that does not do it no. And indeed I have:

recorder:
  purge_keep_days: 2

And I remember from a long time ago, it did not make homeassistant fast when using more days. But not sure if that is nowadays still the case since this is a very old config I think. i use influxdb and grafana for my graphs…

Any tip?

History stats only uses what’s stored. You delete older than 2 days and it will only be able to use the past 2 days and nothing more.

Is there a possibility to selectively allow longer purge days for specific entities? I don’t know how to achieve else tot set 14 days and exclude “all but” for now and the future.

No, you can only exclude entities (or domains). You cant set entity specific keep_days values.

I now have below. It’s a “wise” :slight_smile: collection of all kinds of legacy stuff that I once added to make my system run more smooth. But I think it is outdated and I have to look up the article of reading mysql and exclude stuff. Any tip on how to globally set to 14 days and locally exclude all other.

I guess I am looking to some easy way to inverse the logic of instead of excluding a huge list of who knows what to include specific items… I may want to start a feature request / vote topic for that.

recorder:
  purge_keep_days: 2
  exclude:
    domains:
      - automation
      - weblink
      - updater
      - camera
    entities:
      - sun.sun # Don't record sun data
      - sensor.last_boot # Comes from 'systemmonitor' sensor platform
      - sensor.date
      - sensor.long_power_failure_count
      - sensor.power_tariff
      - sensor.short_power_failure_count
      - sensor.voltage_sags_phase_l1
      - sensor.voltage_swells_phase_l1
      - sensor.frontdoor_process_fps
      - sensor.detection_fps
    entity_globs:
      - sensor.nextion*
      - sensor.synology*
    event_types:
      - call_service # Don't record service calls

Use includes instead.

https://www.home-assistant.io/integrations/recorder/#configure-filter

Hi Tom,

that’s half way then? How do I get:

  • Include all for 2 days (except some) → my current config
  • Exclude all but above…

How do I combine them 2?

As I said:

It’s all or nothing. In the recorder or not.