Need help: Schedule and Template Switch helpers

Hi community!

I have the below issue I need help with. I have a say a schedule helper: schedule.mylight_schedule and a Template switch helper where
Value template:
{{is_state ('schedule.mylight_schedule', 'on') }}

Actions on turn on:

action: light.turn_on
data: {}
metadata: {}
target:
  entity_id: light.ikea_bulb_my_light

Actions on turn off:

action: light.turn_off
data: {}
metadata: {}
target:
  entity_id: light.ikea_bulb_my_light

Though the light state does not change with the schedule. What am I missing here?

I think you have misunderstood how this integration works.

The “value template” will never cause your light to turn on, it’s just a way to establish the state value for the switch entity. The turn on/turn off actions are only executed when a user or script/automation turns the switch entity on or off.

If you want your schedule entity to turn the light on, use an automation.

Thank you Didgeridrew.

I was hoping that the light would get the schedule state after a restart - either of the bulb (physical switch) or a total power loss. Could an automation or script achieve this somehow?

Yes, an automation can do that if you add a trigger for restart and the appropriate conditions to check the schedule entity’s state.

Thanks for you help here! I asked GPT to prep something which I’ll test now. Sharing below:

EDIT: fixing the condition and adding a delay to ensure bulb is controllable upon availability

automation:

alias: Moonlight Schedule Enforcer
description: Ensures light always matches schedule (startup/power loss/schedule changes)
triggers:
  - event: start
    trigger: homeassistant
  - entity_id: light.ikea_bulb_my_light
    from: unavailable
    to: "on"
    trigger: state
  - entity_id: schedule.my_light_schedule
    trigger: state
condition: >
  {{ not is_state('light.ikea_bulb_my_light', 'unavailable') }}
actions:
  - delay: "00:00:05"
  - choose:
      - conditions:
          - condition: state
            entity_id: schedule.my_light_schedule
            state: "on"
        sequence:
          - target:
              entity_id: light.ikea_bulb_my_light
            action: light.turn_on
            data: {}
      - conditions:
          - condition: state
            entity_id: schedule.my_light_schedule
            state: "off"
        sequence:
          - target:
              entity_id: light.ikea_bulb_my_light
            action: light.turn_off
            data: {}
mode: restart