Minutes until midnight dummy variable

Apologies first: After 1 year with HA, I’m a “script kiddie” at best, with barely an understanding of “script”.

I like the clicky-clicky inferface, and I’m fine copy-pasting things into my various yaml files I somewhat understand after reading, but I totally don’t get the time thing.

So, I need a “minutes until midnight” variable. And while we’re at it, a “minutes until noon” variable. And while we’re at it, same for “after”.


If you’re interested in “why”: I’m combining a new PV installation with 50yo storage heaters.

Essentially, I’m building a thermostat. It thus far works. With dozens of automations derived from a table I experimenatally found out.

But it’a not ideal. Yet. A thermostat curve has indoor/outdoor temp sensors, and 2 other variables I can’t name in English. Except that a storage heater has a 24h-delay. So I’m going step-by-step, and that minutes until/after midnight thing, I now have a table for that, too, I could clicky-clicky then.

Hoper that this doesn’t violate community rules, but I’d be willing to pay for help to get that done.

If the current time is 08:00:00 what value should the after noon variable report?


Copy-paste the following templates into the Template Editor and experiment with them. It demonstrates several ways to perform time calculations.

Minutes before noon
{{ ((today_at('12:00') - now()).total_seconds() / 60 ) | round(0) }}

Minutes before midnight (midnight is the start of the next day)
{{ ((today_at('00:00') + timedelta(days=1) - now()).total_seconds() / 60 ) | round(0) }}


Until {{ time_until(today_at('12:00')) }}

Since {{ time_since(today_at('12:00')) }}


Reference

Templating - Time

1 Like