Template condition to check whether entity state last_changed yesterday or earlier, ignoring same day

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!

{{ is_state('input_boolean.clean_filter', 'on') and states.input_boolean.clean_filter.last_changed < today_at() }}

today_at() represents the current date at 00:00:00.

Thank you, that’s a lot neater!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.