Timer just before midnight not running, ideas how to fix?


Dish washer is automatically timed to cheapes electricity hour. It uses couple of minutes to start up before goig full blast. Now the cheapest hour started on midnight and it didn’t run.

platform: template
value_template: >-
  {{ now() >= today_at(states('input_datetime.dish_washer_timer')) -
  timedelta(seconds =540)  }}
alias: start time helper minus lead time

I assume reason is some date mismatch for this, will probably match today slightly before midnight (but then new time has been set again by automation)

How to fix so that even midnight works?

Best idea so far was just to add another trigger with timedelta +1day to catch the midnight case. Working fine but not most elegant.

{{ now() >= today_at(states('input_datetime.dish_washer_timer')) - timedelta(seconds =540)  + timedelta(days =1) }}

Inability to meaningfully use today_at() for midnight seems like a bug though.

It’s a bug in your logic. If input_datetime.dish_washer_timer is 00:09 or earlier, then you are always comparing now() to a time from yesterday/midnight, so it will stay true.

How are you setting input_datetime.dish_washer_timer? If you include the offset in that logic (or just remove the offset) and then use a regular time based trigger then you should have no problem.

kinda, but there actually is no way to do that more correctly, as input_datetime only takes 00:00 for midnight (and not 24:00) and today_at() always assumes today.

The time is set by automation for cheapest electricity price for upcoming evening-night-morning, but also manual override provided (the input_datetime entity added to dashboard to edit at will).
Automation could of course include the timedelta at that end, but “stupid human” cannot be trusted to calculate such when manually changing.

Offset not removable, as the machine does not run at correct time without it for its lead time and program being just a tad over 1 hour long.