For some reason, if I feed utcnow() through a timestamp format, it comes out DST instead of UTC.
What am I doing wrong please?
For some reason, if I feed utcnow() through a timestamp format, it comes out DST instead of UTC.
What am I doing wrong please?
Always consult the docs
I suppose the question is⦠if it converts a UNIX timestamp into its string representationā¦and itās being fed a UTC timestamp⦠then why it is converting it into a BST timestamp at all?
timestamps are timezone agnostic. When you use them, you need to account for TZ using timestamp_custom. Lastly, timestamp_custom assumes local because most people want local.
My thinking is⦠if I feed a timestamp into a formatting tool, it formats the time that I gave it⦠not what it thinks most people want⦠but I think Iām coming at this from the wrong angle.
Thatās why itās an parameter, supply it with local=false. Itās an override. Way more people would be having the same complaint if it defaulted to UTC which is a TZ that is only meant for under the hood.
Iām going to drop it and use {{ utcnow().strftime(ā%H:%Mā) == "07:00" }} instead. I need UTC because my energy supply is āEconomy 7ā and my meter knows nothing about DST, so many of my on/off timings for heating and water have to be UTC.
You can compare datetime aware objects. You donāt need to use UTC.
Youāre having issues because youāre attempting to compare strings, not objects.
Also, keep in mind, you can create template entities in UTC or local TZās and use them in time triggers. Automations will fire at those times.
Grateful for a link to those please. I havenāt been able to find any other way of doing it other than referencing the UTC time directly.
Well, itās not straightforward. There wontā be docās that cover this. Can you post the overall goal with entities (and their states) that you plan to use?
My overall goal is to trigger automations to fire at specific UTC times in order to turn heaters on and off, to match the times that my electricity meter trips over to Economy 7⦠so that Iām generating heat and heating my water at the cheap rate to match the meter. My cheap rate is 7 hours spread over two periods⦠at UTC 22:30 is the first one which ends at 00:30 and then starts again at 02:30 and ends at 07:30. By timing my hot water heating elements and main room heaters to be active during those periods, Iām using energy at 17p per kWh rather than 31p/kWh. Thatās all Iām doing really.
EDIT - Itās just that my meter knows nothing about British Summer Time and is always operating at GMT, or UTC.
Just make a template sensor with device_class (show as in UI) as timestamp. Use the following templates
{% set time = '07:00' %}
{{ utcnow().date() ~ 'T' ~ time ~ ':00+00:00' }}
Then, whatever entity it ends up making, just use that entity to trigger things
- trigger: time
at: sensor.template_sensor_that_was_created