Is there a way to define from&to values in a schedule once and assign it to all the days?

I’m creating a schedule and want to use the same schedule for all the 7 days of the week.
Because there is many small time frames in the schedule (which is why I’m defining the schedule in yaml instead of UI) it is really combersome to see and mainaint the schedule because I have 7 copies of it in the file for each day.
Is there any way to define the “from: | to:” values once and somehow set it for all the 7 days?

I haven’t tried them specifically with the schedule integration, but you should be able to use YAML Anchors

They seems to not work with yaml arrays and in the schedule each day is an array of from/to so I cannot make an anchor for them.

But thanx for the tip anyway.

Since YAML-configured schedules don’t provide the visual confirmation of those created in the GUI, I can’t be 100% sure, but it seems to be working for me… at least, the sensor is ‘on’ and ‘off’ when it should be and the next_event data is populating correctly:

schedule:
  anchored_test_schedule:
    name: "Anchored Test schedule"
    monday:
      <<: &sched_times  
        - from: "07:00:00"
          to: "09:30:00"  
        - from: "11:00:00"
          to: "19:00:00"  
        - from: "21:00:00"
          to: "23:30:00"   
    tuesday:
      <<: *sched_times
    wednesday:
      <<: *sched_times
    thursday:
      <<: *sched_times
    friday:
      <<: *sched_times
    saturday:
      <<: *sched_times      
    sunday:
      <<: *sched_times

I used a slightly different syntax from the guide you have linked which wasn’t working.
I’m give this a try, thanks for the example. I will report back with my experience.

I have tried it but it didn’t work. I don’t really know why.

Here is my schedules.yaml

anchored_test_schedule_example:
    name: "Anchored Test schedule example"
    monday:
      <<: &sched_times  
        - from: "19:44:00"
          to: "19:45:00"  
        - from: "19:47:00"
          to: "19:48:00"  
        - from: "19:50:00"
          to: "19:51:00"  
        - from: "19:53:00"
          to: "19:54:00"  
        - from: "19:56:00"
          to: "19:57:00"  
        - from: "19:59:00"
          to: "20:00:00"  
    tuesday:
      <<: *sched_times
    wednesday:
      <<: *sched_times
    thursday:
      <<: *sched_times
    friday:
      <<: *sched_times
    saturday:
      <<: *sched_times      
    sunday:
      <<: *sched_times

And the part in the configuration.yaml where I include it:

schedule: !include schedules.yaml

When I reload the schedules under the Developer Options menu the Helper schedule do appear but its status do not change.

Here how its history looks like:

Expand for the screenshot

I have created a dummy automation to have something which listens for the schedule just for good measure:

alias: Test
description: ""
trigger:
  - platform: state
    entity_id:
      - schedule.anchored_test_schedule
    from: "off"
    to: "on"
condition: []
action:
  - service: notify.mobile_app_XYZ
    data:
      message: Schedule is ON
mode: single

But despite all the things above the schedule status does not changes.

Ok, I think I figured it out… when using the merge key it was only picking up the first list item.

schedule:
  ztest_anchored_schedule:
    name: "Anchored Test schedule"
    monday: &sched_times
        - from: "17:14:00"
          to: "17:15:00"
        - from: "17:16:00"
          to: "17:17:00"
        - from: "17:18:00"
          to: "17:19:00"
        - from: "17:20:00"
          to: "17:21:00"
    tuesday: *sched_times
    wednesday: *sched_times
    thursday: *sched_times
    friday: *sched_times
    saturday: *sched_times      
    sunday: *sched_times

1 Like

Hey.

Sorry for the late response. I managed to update my schedule the other day based on your example. It works flawlessly ever since.
Thank you very much for your help, hope this thread will be usefull for others as well in the future.

1 Like