Schedy may be ignoring schedule_prepend

I’m having a problem with schedule_prepend in my schedy heating script. The relevant parts are:

schedule_prepend:
    - x: "6 if house_mode() == 'Away' or season() == 'Summer' else Next()"
# default rule to apply if no other matches
schedule_append:
    - v: 15

rooms:
  livingroom:
    rescheduling_delay: 0
    replicate_changes: true
    actors:
      climate.livingroom_thermostat:
    schedule:
      - x: "15 if simulate_bedtime() == 'on' else Next()"
      - v: 19
        rules:
          - weekdays: 1-5
            rules:
              - rules:
                  #                - x: "Next() if season() == 'Spring' else Break()"
                  #                - {v: 15, start: "23:00", end: "17:00+1d" }
                  #                - { start: "17:00", end: "23:00" }
                  - x: "Next() if house_mode() == 'Home - Normal Day' else Break()"
                  - { start: "07:00", end: "09:00" }
                  - { start: "17:00", end: "19:00" }
              - rules:
                  - x: "Next() if house_mode() == 'Home - Home Day' else Break()"
                  - { start: "07:00", end: "09:00" }
                  - { v: 19, start: "09:00", end: "17:00" }
                  - { start: "17:00", end: "22:30" }
          - weekdays: 6-7
            rules:
              - { start: "07:00", end: "09:00" }
              - { v: 19, start: "09:00", end: "17:00" }
              - { start: "17:00", end: "22:30" }

Oddly, the prepend is being ignored. From the log:

schedy_heating: --- [R:livingroom] Initializing room (name='livingroom').
schedy_heating: --- [R:livingroom] [A:climate.livingroom_thermostat] Initializing actor (entity_id='climate.livingroom_thermostat', type='thermostat').
schedy_heating: --- [R:livingroom] [A:climate.livingroom_thermostat] Fetching initial state.
schedy_heating: --> [R:livingroom] [A:climate.livingroom_thermostat] Attribute 'state' is 'heat'.
schedy_heating: --> [R:livingroom] [A:climate.livingroom_thermostat] Attribute 'temperature' is 15.0.
schedy_heating: --> [R:livingroom] [A:climate.livingroom_thermostat] Attribute 'current_temperature' is 21.6.
schedy_heating: --> [R:livingroom] [A:climate.livingroom_thermostat] Received value of 15.0��.
schedy_heating: --- [R:livingroom] [A:climate.livingroom_thermostat] Listening for state changes.
schedy_heating: --- [R:livingroom] Registering scheduling timers at: [00:00:00, 07:00:00, 09:00:00, 17:00:00, 19:00:00, 22:30:00]
schedy_heating: <-- [R:livingroom] Loading state of 'schedy_room.schedy_heating_livingroom' from Home Assistant.
schedy_heating: --> [R:livingroom]   = {'entity_id': 'schedy_room.schedy_heating_livingroom', 'state': '15.0', 'attributes': {'actor_wanted_values': {'climate.livingroom_thermostat': '15.0'}, 'scheduled_value': '6.0', 'rescheduling_time': None, 'overlay_active': False}, 'last_changed': '2022-07-17T21:39:27.711702+00:00', 'last_updated': '2022-07-17T21:39:27.711702+00:00', 'context': {'id': '01G871M6AZ9BK05R8EAN6S9BBN', 'parent_id': None, 'user_id': '0ef99f16230e4d129335978c77d3c611'}}
schedy_heating: --- [R:livingroom] Evaluating room's schedule (reset=False, force_resend=False).
schedy_heating: --- [R:livingroom] Assuming it to be 2022-07-26 19:27:27.989153.
schedy_heating: --- [R:livingroom] ������ [SUB]  <<Schedule 'livingroom'>/1:<Rule with sub <Schedule 'prepend'>>>
schedy_heating: --- [R:livingroom]     ������ [ACT]  <<Schedule 'livingroom'>/1/1:<Rule x="6 if house_mode() == 'Away' or season() "...>>
schedy_heating: --- [R:livingroom] Initializing expression helper: BasicHelper, order = 0
schedy_heating: --- [R:livingroom] Initializing expression helper: PatternHelper, order = 0
schedy_heating: --- [R:livingroom] Initializing expression helper: ScheduleHelper, order = 0
schedy_heating: --- [R:livingroom] Initializing expression helper: StateHelper, order = 0
schedy_heating: --- [R:livingroom] Initializing expression helper: ThermostatExpressionHelper, order = 0
schedy_heating: --- [R:livingroom] Initializing expression helper: CustomEnvironmentHelper, order = 1000
schedy_heating: --- [R:livingroom] Executing the expression_environment script.
schedy_heating: --- [R:livingroom]     ������ => 6
schedy_heating: --- [R:livingroom] Final result: 6.0��, markers: set()
schedy_heating: --- [R:livingroom] Result didn't change, not setting it again.
schedy_heating: <-- [R:livingroom] Sending state to HA: state='15.0', attributes={'actor_wanted_values': {'climate.livingroom_thermostat': '15.0'}, 'scheduled_value': '6.0', 'rescheduling_time': None, 'overlay_active': False}

house_mode is set to away.

As you can see, it comes to the correect conclusion that the target should be set to 6C, but then does nothing about it.

Any ideas?

Hi,

The schedule is working as expected. However, Schedy only sets a value calculated by the schedule if it differs from the result of the previous schedule evaluation.
If you want to force it to re-send unchanged values on startup, set reset_at_startup: true, here is the relevant docs:

  # By default, Schedy tries to restore its previous state at startup
  # from the records stored in Home Assistant. This includes scheduled
  # values, manual adjustments and re-scheduling times - just everything.
  # When this behaviour is not desired, change this setting to true
  # and Schedy will just apply the schedules at startup, no matter what
  # the previous actor states were.
  #reset_at_startup: false

Best regards
Robert

Thanks, Robert
I’ll set that and see what happens.

{EDIT}
It seems to have fixed the problem.

Gareth

Hello all,
I have a similar issue with my schedule_prepend rule. Normal schedule works fine. The problem is that Schedy recognizes opening/closure of a window but doesn’t do anything. Any advice is appreciated.

schedy_heating.yaml:

schedy_heating:
  module: hass_apps_loader
  class: SchedyApp
  reset_at_startup: true

  actor_type: thermostat
  actor_templates:
    default:
      off_temp: 5
      supports_hvac_modes: false

  expression_environment: |
    def heating_mode():
        return state("input_select.heating_mode")

  schedule_snippets:
    ss_aus:
      - v: 5

    ss_durchgehend_wohnen:
      - v: 19

    ss_abwesend:
      - v: 18
        start: "10:00"
        end: "20:00"

    ss_wz:
      - v: 19
        rules:
          - weekdays: 1-5
            rules:
              - { start: "05:30", end: "21:59" }
      - v: 20
        rules:
          - weekdays: 6-7
            rules:
              - { start: "06:30", end: "22:59" }
      - v: 18

  watched_entities:
    - input_select.heating_mode

  schedule_prepend:
    - x: "Mark(OFF, Mark.OVERLAY) if not (is_empty(filter_entities('binary_sensor', state='on', window_room=room_name))) else Next()"
    - x: "IncludeSchedule(schedule_snippets['ss_abwesend']) if heating_mode() == 'abwesend/zeitgesteuert' else Next()"
    - x: "IncludeSchedule(schedule_snippets['ss_aus']) if heating_mode() == 'aus' else Next()"

  rooms:
    wz:
      allow_manual_changes: true
      rescheduling_delay: 30
      actors:
        climate.zb_thermostat_eg_wz_1:
        climate.zb_thermostat_eg_wz_2:
      watched_entities:
        - binary_sensor.wz_all_windows
      schedule:
        - x: "IncludeSchedule(schedule_snippets['ss_wz']) if heating_mode() == 'anwesend/zeitgesteuert' else Next()"
        - x: "IncludeSchedule(schedule_snippets['ss_durchgehend_wohnen']) if heating_mode() == 'durchgehend aktiv' else Next()"

customize.yaml:

binary_sensor.wz_all_windows:
  window_room: wz

Log:

2022-12-04 11:02:31.162560 INFO schedy_heating: --> Attribute 'state' of 'binary_sensor.wz_all_windows' changed from 'off' to 'on', reevaluating <Room R:wz>.
2022-12-04 11:02:38.283524 INFO schedy_heating: --> Attribute 'state' of 'binary_sensor.wz_all_windows' changed from 'on' to 'off', reevaluating <Room R:wz>.

I want the temperature to be adjusted to 5°C while any window is open.

Thermostats are TuYa TV02-Zigbee connected via ZigBee2MQTT.

Thanks in advance
Florian

I think it’s because you aren’t “watching” the window state sensor.

Thanks for the input but it didn’t change the behaviour:

2022-12-05 14:08:35.425716 INFO schedy_heating: --> Attribute 'state' of 'binary_sensor.wz_all_windows' changed from 'off' to 'on', reevaluating <Room R:wz>.
2022-12-05 14:08:35.448884 INFO schedy_heating: --> Attribute 'state' of 'binary_sensor.wz_all_windows' changed from 'off' to 'on', reevaluating 7 rooms.
2022-12-05 14:09:02.984949 INFO schedy_heating: --> Attribute 'state' of 'binary_sensor.wz_all_windows' changed from 'on' to 'off', reevaluating <Room R:wz>.
2022-12-05 14:09:03.008022 INFO schedy_heating: --> Attribute 'state' of 'binary_sensor.wz_all_windows' changed from 'on' to 'off', reevaluating 7 rooms.

Maybe the prepend is wrong somehow as the thermostats do not know the condition “OFF”.

Regards
Florian

Have you checked the actual values that heating_mode() returns? You are checking for German language values, is that what is returned?

You could try checking the actual values in the Developer panel.

Hello @Guff666,
I checked the value that heating_mode returns and it is “anwesend/zeitgesteuert”.
The normal schedule that comes with this setting works fine. Only the open window detection in the prepend just does nothing exept reevaluating.

Regards
Florian