core icon indicating copy to clipboard operation
core copied to clipboard

TOD (Times Of the Day) is not working correctly after daylight saving

Open bkupidura opened this issue 3 years ago • 21 comments

The problem

TOD sensor is ignoring daylight saving time.

Sensor changed state at 10:30, after CET->CEST (+1h). After HA reboot everything works correctly.

What is version of Home Assistant Core has the issue?

2021.3.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

tod

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tod/

Example YAML snippet

- platform: tod
  name: day
  after: '09:30'
  before: '22:00'

Anything in the logs that might be useful for us?

Screenshot 2021-03-29 at 11 10 28

bkupidura avatar Mar 29 '21 09:03 bkupidura

tod documentation tod source (message by IssueLinks)

I am in CEST time zone and my sensor based on TOD turns on and off as expected. I cannot reproduce this on 2021.5.x @bkupidura you still have this issue? I am not a dev. I was just trying to see what other bugs besides https://github.com/home-assistant/core/issues/50315 that are open on TOD integration

KennethLavrsen avatar May 26 '21 09:05 KennethLavrsen

Problem happens only after daylight saving (till reboot).

bkupidura avatar May 26 '21 09:05 bkupidura

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 24 '21 10:08 github-actions[bot]

Pet the gitbot. Go to sleep again.

KennethLavrsen avatar Aug 24 '21 10:08 KennethLavrsen

I experienced this bug this morning after DST change overnight. It seems like the tod sensors need to be reloaded after the DST change.

- platform: tod
  name: Morning
  after: "04:00"
  before: "08:30"

image

Ignore the 09:30 turn off, that was me making a change. You can see the two scheduled times are off by an hour.

tankdeer avatar Nov 07 '21 18:11 tankdeer

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Feb 06 '22 09:02 github-actions[bot]

Pinging the bot

KennethLavrsen avatar Feb 06 '22 09:02 KennethLavrsen

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jul 06 '22 20:07 github-actions[bot]

Ping silly bot

KennethLavrsen avatar Jul 07 '22 05:07 KennethLavrsen

I believe this is still an issue. Had a time of day sensor for 5am and another starting at 22:00 each day. They are tied to scenes. And I can see the 5am one triggered at 6am and the 2200 at 2300

psyciknz avatar Sep 25 '22 18:09 psyciknz

Can confirm - still an issue

Crunchie avatar Sep 27 '22 23:09 Crunchie

btw, I restarted home assistant, and mine seemed to come right.

psyciknz avatar Sep 27 '22 23:09 psyciknz

Encountered this issue following this morning's UK Daylight Savings change.

configuration.yaml

binary_sensor:
  - platform: tod
    name: "tod_ha_night"
    after: "22:00"
    before: sunrise
    before_offset: "-01:30"

Following clocks change binary_sensor.tod_ha_night state changed to 'on' at 21:00. Host OS and the HA Time & Date sensor both showed correct time, After a HA restart at 21:04 binary_sensor.tod_ha_night correctly showed 'off'.

TazUk avatar Oct 30 '22 21:10 TazUk

Can confirm - still an issue, used HA restart as workaround to fix (the system clock and HA time_date both showed 22:30) chrome_YIR9bIDv1Z

ech0-py avatar Oct 31 '22 11:10 ech0-py

I can confirm the issue too.

I think the issue happens because TodSensor internally tracks UTC time instead of local time. UTC is not affected by daylight saving time. https://github.com/home-assistant/core/blob/3a13ffcf1376bafff6a32df19b197083abf6e826/homeassistant/components/tod/binary_sensor.py

When we set up "after" and "before", we expect them to be our local times. TodSensor has to set up time triggers to be updated at certain times. In pseudocode, it is updated at "base_time + after" and at "base_time + before". The problem is, "base_time" is currently derived from "utcnow()" instead of "now()", and thus planned updates are oblivious of DST change.

I am not a Python programmer, but hope someone with proper skill can take a look at it.

birukoff avatar Nov 01 '22 11:11 birukoff

Same issue here. Need HA restart to get it work again.

manu3b1 avatar Nov 02 '22 06:11 manu3b1

Gusss we should make an automation that on local daylight savings restart ha...

psyciknz avatar Nov 02 '22 06:11 psyciknz

I also got the wrong starting times after switching daylight savings time. Sensor was defined as:

after: '2022-11-02T08:30:00+02:00'
before: '2022-11-02T18:00:00+02:00'

On editing the values and saving via backend, the new state is…

after: '2022-11-02T08:30:00+01:00'
before: '2022-11-02T18:00:00+01:00'

…and the time table is starting at the expected time again.

Obviously the time being stored with the time zone keeps it from changing to/from DST. The sensor starts at the correct time given the time string, but obviously it is supposed to be interpreted as local time without any time zone interpretation, like input_datetime:

hour: 8
minute: 30
second: 0

Saving it without time zone…

after: '2022-11-02T08:30:00'
before: '2022-11-02T18:00:00'

…does also not work, because obviously it is interpreted as UTC and not as local time.

fboes avatar Nov 02 '22 10:11 fboes

Daylight savings just hit in the US and I encountered this issue

matthewhadley avatar Nov 06 '22 13:11 matthewhadley

Same. First thing I did this morning was restart HA. 😒

tankdeer avatar Nov 06 '22 16:11 tankdeer

Anything? How time automation - something so basic - can be broken on home automation software?

Screenshot from 2022-12-17 21-24-49 Screenshot from 2022-12-17 21-25-07

chojnicki avatar Dec 17 '22 21:12 chojnicki

Just ran into this issue myself. Hopefully that PR can be merged...

dvick avatar Mar 13 '23 13:03 dvick

I confirm the issue. I have defined a binary_sensor as a helper with time boundaries: image

Today, 26/march/2023 time changed at 02:00h to 03:00h, however, the binary_sensor was still working in the old time. Some automations did not trigger because the sleeptime binary_sensor was still set to on. It was 07:20h, however, the binary_sensor was still thinking it was 06:20h which is not correct.

enjoylifenow avatar Mar 26 '23 06:03 enjoylifenow

I created a workaround automation that detects DST change and reboots Home Assistant:

automation:
  - id: "on_dst_change"
    alias: "On DST Change"
    description: "Triggered when Daylight Saving Time changes are detected"
    mode: single
    trigger:
      # This automation should be triggered ONLY by time.
      # Otherwise there is a risk of initiating a reboot cycle
      # that will last until the next day
      - platform: time
        at: "03:01:00"
    condition:
      condition: template
      value_template: >
        {% set c_time_utc = utcnow() %}
        {% set y_time_utc = c_time_utc - timedelta(hours=24) %}
        {% set c_time = c_time_utc | as_local %}
        {% set y_time = y_time_utc | as_local %}
        {{ c_time - y_time != timedelta(hours=24) }}
    action:
      - service: homeassistant.restart

birukoff avatar Mar 26 '23 07:03 birukoff

Also seeing this issue again. I think I'll add a calendar reminder to manually reboot every 6 months, but thanks for posting that auto restart suggestion. (I just wouldn't trust myself to remember, and would end up debugging 'unexplained' restarts every 6 months 😅)

ahaverty avatar Mar 26 '23 23:03 ahaverty

There's a fix for this issue (See #84931) . Just waiting for a review (@bdraco )

jmwhite5 avatar Mar 27 '23 20:03 jmwhite5

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

This remains an issue - proposed fix https://github.com/home-assistant/core/pull/84931 remains open

TazUk avatar Jun 25 '23 20:06 TazUk

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.