From 284a9cdab60d06d623be8b5834ac3ad554aed3d1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 29 Jan 2026 23:41:41 -0600 Subject: [PATCH] must set TZ --- esphome/components/time/real_time_clock.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/esphome/components/time/real_time_clock.cpp b/esphome/components/time/real_time_clock.cpp index 09b242d040..4792746520 100644 --- a/esphome/components/time/real_time_clock.cpp +++ b/esphome/components/time/real_time_clock.cpp @@ -103,7 +103,12 @@ void RealTimeClock::apply_timezone_(const char *tz) { return; } - // Parse the POSIX TZ string using our custom parser + // Set TZ env var for components using libc's localtime() directly + // (e.g., sun, datetime, wireguard, deep_sleep) + setenv("TZ", tz, 1); + tzset(); + + // Parse the POSIX TZ string using our custom parser for RealTimeClock::now() if (!parse_posix_tz(tz, this->parsed_tz_)) { ESP_LOGW(TAG, "Failed to parse timezone: %s", tz); // Reset to UTC on parse failure