Just for fun, paste this into the Template Editor:
{% set t = as_datetime('1970-01-01T08:45').astimezone()%}
{{ t }}
{{ t.timestamp() }}
{{ now().fromtimestamp(t.timestamp(), now().tzinfo) }}
There’s a potential hitch with the idea of storing the time (for a time-only input_datetime) on the day of the Unix Epoch plus one’s timezone. The hitch is DST.
The result of the three templates is this (for my timezone):
What I showed is a proposal for a change that I implemented
Indeed, currently, neither as_datetime nor as_timestamp work for a time-only input_datetime…
Almost, the result is offset-naive (no timezone) so you can’t use it in a comparison with an offset-aware datetime object like what’s produced by now() or in date math.
(Not so) fun fact:
If the timezone is not explicit, it’s the TZ of the machine (or container) that is picked up, via python I guess.
The vscode dev container is in UTC, even though the machine is in UTC+2, and I get timestamps in UTC. The TZ setting of HA is ignored, then, but now() still returns a datetime with the HA TZ
Can someone help me with something similar like this?
I have a few time sensors and i want to make sensor which is - 15 minutes of the sensor.
So if it is 15.15 then i want the second sensor 15.00 and then i can trigger them for automations.
Any idea?
I have tried those things above but i cant program and just edited but with no luck sadly…