question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TOD incorrect after midnight restart

See original GitHub issue

The problem

binary sensor TOD set to off when should be on after 2am restart

- platform: tod
   name: lateNightTime
   after: '21:30'
   before: sunrise

What version of Home Assistant Core has the issue?

2022.2.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

TOD

Link to integration documentation on our website

here

Diagnostics information

No response

Example YAML snippet

- platform: tod
    name: lateNightTime
    after: '21:30'
    before: sunrise

Anything in the logs that might be useful for us?

No response

Additional information

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:12

github_iconTop GitHub Comments

2reactions
DmytroKorniienkocommented, Nov 9, 2022

@ahaverty

Does anyone have a workaround or alternative integration that follows the sun? I’m hitting this regularly, as I’m doing a good bit of late night tweaking recently.

  - binary_sensor:
    # tod workaround
    - name: "Night"
      unique_id: tod_night
      state: >
        {% set cur_sunset = iif(state_attr("sun.sun", "next_setting")>state_attr("sun.sun", "next_rising")
        ,as_datetime(state_attr("sun.sun", "next_setting"))-timedelta(days=1)
        ,as_datetime(state_attr("sun.sun", "next_setting")))%}

        {% if 
        now()>cur_sunset
        and now()<as_datetime(state_attr("sun.sun", "next_rising"))
        -%}
          on
        {%- else -%}
          off
        {%- endif %}

0reactions
DmytroKorniienkocommented, Dec 28, 2022

@DmytroKorniienko thanks for sharing! I’m stuck though with some more complex TOD’s that are important to me for outdoor light automations. I had a go at modifying your code for evening for example, but couldn’t find a way to get the after_offset working properly.

after_offset requires more complex logic and I’m not implemented it for my automations, but can share one more example:

  - binary_sensor:
    # from 21:00 to 5 minutes before next_rising
    - name: "Light Control"
      unique_id: tod_light_control
      state: >
        {% set cur_sunset = iif(state_attr("sun.sun", "next_setting")>state_attr("sun.sun", "next_rising")
        ,as_datetime(state_attr("sun.sun", "next_setting"))-timedelta(days=1)
        ,as_datetime(state_attr("sun.sun", "next_setting")))%}
        {% set cur_start = strptime(as_timestamp(cur_sunset) | timestamp_custom('%Y-%m-%d 00:00:00%z'),'%Y-%m-%d %H:%M:%S%z') %}

        {% if 
        now()>cur_start+timedelta(hours=21, minutes=00)
        and now()<as_datetime(state_attr("sun.sun", "next_rising"))-timedelta(hours=0, minutes=5)
        -%}
          on
        {%- else -%}
          off
        {%- endif %}
Read more comments on GitHub >

github_iconTop Results From Across the Web

TOD - FAQs
How do I create an account on TOD? How can I change/reset my password? How can I reset/remove my parental PIN? How can...
Read more >
COMMON ERRORS IN KRONOS AND HOW TO FIX THEM
Incorrectly recording overtime hours. Non-exempt employees who have approval to work overtime should record their total hours worked each day without using any ......
Read more >
PJ36846: TIMEC MAY RETURN INCORRECT SECONDS IN THE ...
The result is that TIMEC may return a value for seconds that is not correct. Second, when ZDTIM TOD displays the local time...
Read more >
Reported Known Issues - FlyByWire Simulations Documentation
Initialization timing issue of MSFS. Possible Solution or Workaround. Workaround: Restart the flight. Unexpected Out of Fuel - No Fuel Transfer ...
Read more >
Untitled
The TOD associated with that pay period was incorrect, therefore making the ... TOD to be created to reset the TOD back to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found