Run automation if input_datetime sensor is older than 5 days

Hi folks,

I am getting a bit crazy here. I want to create an easy automation that reminds us how dirty our house is (if our robot vaccum didn’t run for 5 or more days). The last_run_date of the vacuum is stored in a datetime sensor called input_datetime.vacuum_last_run (only days, no time).
I am looking to compare this input_datetime sensor to now().date() and see if the difference is >= 5 days but I am virtually unable to achieve it.

As automation trigger, I’d just run it once daily at a fixed time, but the condition to pass would be exactly what I described above: input_datetime.vacuum_last_run was set 5 days (or longer) than today (now()). If true; send a notification to my phone and shame me properly.

Any help would be appreciated - I did thoroughly search forums, google & now() documentation but I fail to achieve it.

Thanks!

1 Like

Is the Input datetime type date-only or time and date?

alias:  "Test if it is 5 days after last cleaning (Date Only)"
condition: template
value_template: |
  {{ today_at() >= states('input_datetime.vacuum_last_run')|as_datetime|as_local 
  + timedelta(days=5) }}
alias:  "Test if it is 5 days after last cleaning (Time & Date)"
condition: template
value_template: |
  {{ now() >= states('input_datetime.vacuum_last_run') | as_datetime | as_local + timedelta(days=5) }}