nielsfaber / scheduler-component

Custom component for HA that enables the creation of scheduler entities
GNU General Public License v3.0
622 stars 40 forks source link

condition re-evaluation doesn't work after core restart #305

Closed luka6000 closed 7 months ago

luka6000 commented 9 months ago

Condition re-evaluation doesn't work after HA core restart as described here

Checklist

Expected behavior

[What you expected to happen]

set schedule with conditions. Mark "re-evaluate conditions". Schedule should re-evaluate conditions all the time.

Actual behavior

[What actually happened] Schedule is not re-evaluating conditions after HA core restart. One needs to disable and reenable schedule to make it work.

Only thing I can find in the logs is this

2023-10-22 20:53:38.865 DEBUG (MainThread) [custom_components.scheduler.switch] Schedule 407d37 was already executed before shutdown, initial timeslot is skipped.

So maybe the slot that schedule is in after restart is skipped?

Steps to Reproduce

[Explain how to see the behaviour]

  1. set schedule with conditions. Mark "re-evaluate conditions".
  2. check if re-evaluation works (like use input_boolean of similar to easily trigger conditions change)
  3. restart ha
  4. check if re-evaluation still works
patriiiiiiiiiick commented 9 months ago

The issue is with the active schedules, right? I mean, if I restart HA at 23.30, will conditions be evaluated again after midnight?

luka6000 commented 9 months ago

Yes ofc. The schedule is active and does not work after ha restart. I’m not sure about it working on next timeslot. I already have automation restarting every scheduler after restart

github-actions[bot] commented 8 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

johndfoss commented 8 months ago

I have the same problem of schedules not re-evaluating conditions even without HA restart.

devildant commented 8 months ago

hello, I see the same problem, I did an automation to temporarily overcome the problem:

description: ""
mode: single
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
  - repeat:
      sequence:
        - if:
            - condition: template
              value_template: "{{ states(repeat.item) == 'on' }}"
          then:
            - service: scheduler.run_action
              data:
                entity_id: "{{ repeat.item }}"
              enabled: true
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
      for_each: |
        {{ integration_entities('scheduler') }}
    enabled: true
devildant commented 8 months ago

I will detail the problem (I just tested it) after a restart, the schedule works well, however it is just the condition evaluation part that no longer works, for it to work again you have to restart the schedules or call the service

exemple with 2 scheduler with boolean condition.

after restart if i passe the boolean test at false or true nothing is happening but if i disable and enable all scheduler, it's work again

V3L commented 7 months ago

I have the same issue, I use booleans for a number of things, time of year, kids away, boost mode etc. I noticed after a restart earlier these no longer worked.

I manually turned all my schedules off then back on, the booleans appeared to be working again.

I’ve also added the Automation created by @devildant restarted again and the booleans still appear to be functional.

nielsfaber commented 7 months ago

I can confirm this bug and made changes to fix this. @luka6000

So maybe the slot that schedule is in after restart is skipped?

This was indeed the case. Thank you for pinpointing the issue, you made it really easy for me to identify and fix it.

I will post back when the changes are released.

nielsfaber commented 7 months ago

I just made release v3.3.0 of scheduler component which includes this bugfix. I assume this solves the issue for everyone. If not, please let me know.