Question: How to Use the Scheduler / Helper Function in the 2022.9 Release

Hey there,

I know that I will kick myself but here goes… Once I have created a schedule using the new Helpers function in the 2022.9 release, how do I link it to an entity or to an automation?

Thank you.

Um… the Scheduler is the trigger, right?

Use a State Trigger to detect when the schedule entity changes state from off to on (a scheduled time period has started) and from on to off (a scheduled time period has finished).

Simple automation that turns a light on/off according to a schedule entity.

alias: example
trigger:
  - platform: state
    entity_id: schedule.your_schedule
condition: "{{ trigger.to_state.state in ['on', 'off'] }}"
action:
  - service: 'light.turn_{{ trigger.to_state.state }}'
    target:
      entity_id: light.your_light
19 Likes

That is awesome! Thank you so much.

To clarify. Are two Automation routines required? One from On-to-Off and the other from Off-to-On?

The example I posted handles both.

Thank you! I have much to learn.

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information, refer to guideline 21 in the FAQ.

@Kaizen28, did you test the solution and did it work for you? I added the following to my automations.yaml and the event did not trigger, and I don’t show any errors in the logfile.

- id: control-hot-water-heater-with-schedule
  trigger:
    - platform: state
      entity_id: schedule.hot_water_schedule
  condition: "{{ trigger.to_state.state in ['on', 'off'] }}"
  action:
    - service: 'switch.turn_{{ trigger.to_state.state }}'
      target:
        entity_id: switch.hot_water_heater_switch

Has the schedule option not been implemented in the UI yet?

My variation seems to be working

alias: Driveway Monitor Schedule
description: ""
trigger:
  - platform: state
    entity_id:
      - schedule.driveway_monitor
condition:
  - condition: template
    value_template: "{{ trigger.to_state.state in ['on', 'off'] }}"
action:
  - service: switch.turn_{{ trigger.to_state.state }}
    target:
      entity_id: switch.driveway_monitor_socket_1
mode: single

any idea how I could switch the helper apart from the schedule?
TIA

To make a minor improvement to use it with everything that can be turned on or off:

alias: Sync schedule koelingen
description: ""
trigger:
  - platform: state
    entity_id:
      - schedule.koelingschedule
condition: []
action:
  - service: homeassistant.turn_{{ trigger.to_state.state }}
    target:
      entity_id:
        - switch.spp_grotekoeling
        - switch.spp_3frigoshal
mode: single
3 Likes

@huuub I think you need to change homeassistant.{{ trigger.to_state.state }} to homeassistant.turn_{{ trigger.to_state.state }}

2 Likes

Again I don’t understand why it is so difficult to find a blueprint for this basic task. So I have created what is necessary:

1.) Create a helper with the required schedule
2.) Add this blueprint

blueprint:
  name: Schedule-activated Switch
  description: Turn on and off a switch by schedule.
  domain: automation
  input:
    schedule_entity:
      name: Schedule
      selector:
        entity:
          domain: schedule
    switch_target:
      name: Switch
      selector:
        target:
          entity:
            domain: switch

trigger:
  platform: state
  entity_id: !input schedule_entity
action:
  - service: homeassistant.turn_{{ trigger.to_state.state }}
    target: !input switch_target
mode: single

3.) Reload the blueprints
4.) Create an automation by selecting for the blueprint Schedule-activated Switch the schedule and the traget switch to opperate

1 Like

Thanks for this blueprint - it works well.

Question: we sometimes get a power cut and when restored the wi-fi plugs return to ON state. Is there a way to adapt this blueprint so that it checks the schedule on restart of HA and sets the correct on/off status?

Considering adding a ‘add to my blueprints’ button for this one.

1 Like

I had exactly the same concern (restoring the state of the switch at startup of HA, in case of power loss) and made this:

blueprint:
  name: Schedule-activated Switch
  description: Turn on and off a switch by schedule.
  domain: automation
  input:
    schedule_entity:
      name: Schedule
      selector:
        entity:
          domain: schedule
    switch_target:
      name: Switch
      selector:
        target:
          entity:
            domain: switch

mode: single

variables:
  schedule_input: !input schedule_entity

trigger:
  - id: trigger_schedule
    platform: state
    entity_id: !input schedule_entity
  - id: ha_start
    platform: homeassistant
    event: start

action:
  - service: homeassistant.turn_{{ states[schedule_input].state }}
    target: !input switch_target

It triggers both on the state change of the schedule helper and the startup of HA, and sets the state according to the current schedule state (rather than the to_state value)

I am new to HA, so this may have some unforeseen issues or side effects, but it seems to work here…