Hi, I’m using this as a condition in an automation to check if an entity state last changed during the previous calendar day or anytime before that (basically same day last_changed
is ignored).
I found examples of how I could check if something occurred Xhrs+ ago, but that wasn’t what I was looking for.
I’ve cobbled together this template, and it appears to work. But just wanted to double check I haven’t missed anything or if there’s a tidier way to achieve this?
{% set last_timestamp = as_timestamp(states.input_boolean.clean_filter.last_changed) | timestamp_custom("%Y-%m-%d", True) %}
{% set current_timestamp = now().timestamp() | timestamp_custom("%Y-%m-%d", True) %}
{{ is_state("input_boolean.clean_filter", "on")
and last_timestamp < current_timestamp }}
Also I’m not clear what the True
does in timestamp_custom("%Y-%m-%d", True)
can anyone explain that to me? Thanks in advance for any help or advice offered!