How to activate a scene when a light turns on

I am trying to trigger a different scene based on the time of day. Right now I have an automation that triggers whenever a light turns on, it will check the time of day and then activate the approriate scene. The automation and scene both triggers, but the scene is not changing the lights. When I debug, both the automation runs and the scene activates when I turn on the lights, but nothing changes. Is this a thing with scenes that it wont work unless the lights have been on for a set period of time?

Few things I noticed.

  • if I activate the scene manually then it just turns on the lights in the last state.
  • if I wait only a few seconds after the lights turn on, and then activate the scene, nothing happens.
  • if I wait around 5-10seconds before activating the scene, then the scene will work and change the colors.

Automation:

alias: Upstairs Hall Lights - Set Scene
description: ""
triggers:
  - type: turned_on
    device_id: e3e758a30412389ea35a2b9cd12349a04e435b
    entity_id: 478713e51971b12b5615accdbb04777f2b4eda
    domain: light
    trigger: device
conditions: []
actions:
  - action: scene.turn_on
    target:
      entity_id: scene.upstairs_hall_day
    data: {}
alias: Upstairs Hall Lights - Set Scene
description: ""
triggers:
  - type: turned_on
    device_id: e3e758a30412389ea35a2b9cd12349a04e435b
    entity_id: 478713e51971b12b5615accdbb04777f2b4eda
    domain: light
    trigger: device
    for:
      hours: 0
      minutes: 0
      seconds: 5
conditions: []
actions:
  - action: scene.turn_on
    target:
      entity_id: scene.upstairs_hall_day
    data: {}

Does this work?

possibly

alias: Upstairs Hall Lights - Set Scene
description: ""
triggers:
  - type: turned_on
    device_id: e3e758a30412389ea35a2b9cd12349a04e435b
    entity_id: 478713e51971b12b5615accdbb04777f2b4eda
    domain: light
    trigger: device

conditions: []
actions:
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - action: scene.turn_on
    target:
      entity_id: scene.upstairs_hall_day
    data: {}

yeah, when I put a 10 second delay it works. but was hoping there was a way to not have to wait for the transition. im basically trying to have different scenes based on the time of day, so whenever a light turns on, i want it to switch to the proper scene based on time of day.

Sound like you need multiple automations that update per the time that are dictating the color of the light no matter its on off status and then when the light is turned on it will need to be instantly referring to something on the automations to instantly choose its color or settings.

1. Why the Delay Happens




The delay you’re encountering likely stems from the smart lights needing time to fully initialize after turning on before they can accept scene changes. This is common with certain smart lights that:

  • Require a brief period to sync their state with the hub/controller.
  • Might default to their last state upon turning on, especially if not explicitly configured to change color or brightness immediately.

2. Solution Overview




To ensure your lights instantly switch to the correct scene without waiting:

  1. Use time-based automations to predefine the light settings for each time period.
  2. Ensure the lights are always in the correct state when turned on by dynamically updating their settings in the background (even when they’re off).
  3. Eliminate the dependency on the initial state of the lights by decoupling scene activation from the light’s “on” event.

3. Implementation




A. Create Time-Based Automations

These automations will adjust the light’s state throughout the day. This ensures that when the light is turned on, it references the correct settings immediately.

Example Time-Based Automation (Daylight Scene):

alias: Set Daylight Scene
description: "Automatically adjusts the scene based on the time of day."
trigger:
  - platform: time
    at: "07:00:00"  # Start of the day scene
condition: []
action:
  - service: scene.turn_on
    target:
      entity_id: scene.upstairs_hall_day
    data: {}

Repeat for Other Time Periods: Create similar automations for other times (e.g., evening, night). Adjust the trigger times and scenes accordingly.


B. Update Lights When Turned On

Modify your light automation to refer to the current time and apply the appropriate settings immediately when turned on.

Example Light Automation:

alias: Upstairs Hall Lights - Adaptive Scene
description: "Change light scene based on time of day when turned on."
trigger:
  - platform: state
    entity_id: light.upstairs_hall
    to: "on"
condition: []
action:
  - choose:
      - conditions:
          - condition: time
            after: "07:00:00"
            before: "19:00:00"  # Daytime
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.upstairs_hall_day
      - conditions:
          - condition: time
            after: "19:00:00"
            before: "22:00:00"  # Evening
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.upstairs_hall_evening
      - conditions:
          - condition: time
            after: "22:00:00"
            before: "07:00:00"  # Night
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.upstairs_hall_night
    default: []

C. Optional: Preload Scene States

For lights that require preloading scene states (even when off), create a separate automation to continually update their state.

Example Preload Automation:

alias: Preload Scene States
description: "Ensure lights are ready to apply the correct scene when turned on."
trigger:
  - platform: time_pattern
    minutes: "/5"  # Runs every 5 minutes
condition: []
action:
  - choose:
      - conditions:
          - condition: time
            after: "07:00:00"
            before: "19:00:00"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.upstairs_hall
            data:
              brightness: 255
              color_name: "warm_white"  # Example settings for day
      - conditions:
          - condition: time
            after: "19:00:00"
            before: "22:00:00"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.upstairs_hall
            data:
              brightness: 150
              color_name: "soft_white"  # Example settings for evening
      - conditions:
          - condition: time
            after: "22:00:00"
            before: "07:00:00"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.upstairs_hall
            data:
              brightness: 50
              color_name: "cool_white"  # Example settings for night

4. Key Benefits of This Approach




  • No Delay: Lights instantly reflect the desired state upon turning on because they are dynamically set to the correct scene.
  • Adaptive: Automations dynamically adjust based on the current time and conditions.
  • Consistent Experience: Users don’t notice initialization quirks or incorrect states when lights are turned on.

5. Debugging Tips




If the automation doesn’t behave as expected:

  • Check logs: Confirm that the automation triggers and scenes are activated without errors.
  • Verify light capabilities: Some lights may not support immediate state changes or might require additional configuration.
  • Test manual commands: Use the Developer Tools in Home Assistant to manually activate scenes and verify the lights’ response.