Compare time in different timezone (not local)

Hi everybody,

I’m trying to write a binary sensor like this:

binary_sensor:
  - platform: template
    sensors:
      abc:
        value_template: >
          {{ today_at("22:00:00") <= now() < today_at("08:00:00") or
             today_at("14:00:00") <= now() < today_at("16:00:00") }}

But I need those times in a different timezone.

The problem is that the server where HA is running on is in UTC and I need to keep it like that, so I can’t use functions like as_local()

I thought that I could use

{% set dt = as_datetime(utcnow().timestamp() + 3600) %}

But then I realized that the calculation will break with daylight saving.

Any ideas how to do it without HACS/extra integrations?

Thank you.

Dex

it’s actually in a different timezone, or if you live in one but the ha needs to be in utc, using separate timezone sensor may be useful in this and other situations…

sensor:
  - platform: worldclock
    name: time_newyork
    time_zone: America/New_York

this creates a sensor in eastern timezone. which you can then use in your binary sensor. would that work for you?