Timezone conversion

I am trying to write a template for converting the now() time into the time my phone is in (usually meant for travels). I only have the timezone my phone is in of the format “Europe/Berlin”.
I tried using now().replace() but there is no conversion from string to tzinfo object…

I thought you were using a python script for that… AFAIK there’s no access to timezone() in HA’s template implementation, so there’s no way to go from “Europe/Berlin” to another zone. Another issue with the designations like “Europe/Berlin” is that they don’t differentiate whether DST is in effect, so building a template macro to do it would be a pain.

If your travels are to a manageable number of zones, you could use the World Clock integration to set up a sensor for each of those zones. If you name the sensors with the zone designations it should be pretty easy to set up a template sensor to do the rest.

Another option is to use an external service to tell you the offset. You can set up a rest command with an API like to this one to get the info you need.

1 Like

want to ditch custom scripts as I had more than one problem over longer periods, more specifically when HA got big updates and stuff failed in some way or another. Hence the wish to template stuff as mostly these are migrated automatically no matter what.