History_stats: make the "state" configuration variable accept template

Hi,
Hello, as per the title, it would be perfect if the “state” configuration variable accepted a template. In my case, I would use this type of information to prevent some automations from changing the state of the air conditioners if it has already been changed in the last hour.

What I have in mind is something like this:

  • platform: history_stats
    unique_id: statechange_clima_studio
    name: Clima Studio(disponibile per automazione)
    entity_id: climate.153931628036068_climate
    state: “{{ states(‘climate.153931628036068_climate’)}}”
    type: time
    end: “{{ now() }}”
    duration: “01:00”

You can do this with a template condition in your automations.

condition:
  - condition: template
    value_template: "{{ now() - states.climate.153931628036068_climate.last_changed > timedelta(hours=1) }}"

Hi @tom_l,
I really like more your solution.

Thanks!

1 Like