I am comparing last_updated to now() to check if one of my sensors is not updating.
But I see this is in a different timezone - now() seems to be based on my locale, while last_updated is in GMT or UTC.
Is there a configuration option that I could check to align these?
EDIT: My template uses as_timestamp to calculate the difference anyway, but it would be good to know how to get the values in the same format/timezone.
Oh, I think I wrote the template before timedelta() was available. Today I did some troubleshooting of another template and I looked up the last_updated and noticed the timezone was incorrect (or rather - it is UTC, while now() is in local TZ).
And just to drive the point home: HA / Python has no issue comparing timezone-aware datetime objects from different time zones. You don’t need to do any conversion or think about it at all.
If you have doubts, try this in the template editor: {{ '2024-06-04 12:00:00-00:00' | as_datetime == '2024-06-04 05:00:00-07:00'| as_datetime }}
It will render True because these represent the exact same time. They are merely displayed differently.