Multiple timezones

Hi, Im trying to make a wall clock using ESP home and a e-ink display. This has worked well for a single time zone, but i wanted to add a second page to show some world times, so i added these time components to the config

time:
  - platform: homeassistant
    id: time_hass
  - platform: sntp
    id: time_nz
    timezone: "Pacific/Auckland"
  - platform: sntp
    id: time_pst
    timezone: "America/Los_Angeles"
  - platform: sntp
    id: time_est
    timezone: "America/New_York"
  - platform: sntp
    id: time_cst
    timezone: "America/Chicago"

This hasn’t done what i thought it would do and has made all of the time components CST. Is this intended behaviour, or am i missing a way to do this?

The timezone and time value are global, so that isn’t going to work. The way around that is it to set the timezone before you want to use it.

      setenv("TZ", "PST8PDT7,M3.2.0/2,M11.1.0/2", 1);
      tzset();
      auto time = id(my_time).now();
      if (time.is_valid())
        it.strftime(0, 2, "%Y:%m:%d %H:%M:%S", time);
      setenv("TZ", "CST6CDT5,M3.2.0/2,M11.1.0/2", 1);
      tzset();
      time = id(my_time).now();
      if (time.is_valid())
        it.strftime(0, 3, "%Y:%m:%d %H:%M:%S", time);
1 Like

Thank you, that worked. Here is a video of it working https://youtu.be/zefinzkNt9E