I have a markdown that gives me useful info on automation triggered.
I want to limit it to automation triggered during past 24 hours only.
Can someone help as I cannot figure this from what i searched.
|D|H|M||Name|
|----:|----:|----:|:--:|:----|
{% for state in states.automation
|selectattr('attributes.last_triggered')
|sort(attribute='attributes.last_triggered', reverse=true) -%}
{%- set t = now() - state.attributes.last_triggered -%}
{%- set days = t.days if t.days > 0 else ' ' -%}
{%- set hrs = t.seconds//3600 %}
{%- set hrs = hrs if hrs > 0 else ' ' -%}
|{{days}}|{{hrs}}|{{(t.seconds//60)%60}}||_{{state.name}}_|
{% endfor %}
I explained how to do that (for 12 hours) in the topic where you got that example:
What is needed is to modify the for statement with the following additional restriction (24 hours = 86400 seconds):
if (now() - state.attributes.last_triggered).total_seconds() < 86400
Example:
|D|H|M||Name|
|----:|----:|----:|:--:|:----|
{% for state in (states.automation
|selectattr('attributes.last_triggered')
|sort(attribute='attributes.last_triggered', reverse=true))
if (now() - state.attributes.last_triggered).total_seconds() < 86400 %}
{%- set t = now() - state.attributes.last_triggered -%}
{%- set days = t.days if t.days > 0 else ' ' -%}
{%- set hrs = t.seconds//3600 %}
{%- set hrs = hrs if hrs > 0 else ' ' -%}
|{{days}}|{{hrs}}|{{(t.seconds//60)%60}}||_{{state.name}}_|
{% endfor %}