Simplifying automation of lighting scenes

Hello!

I’m trying to automate some lighting scenes depending on the time of day. I managed to add 4 automations with time conditions, which seem to work fine. My problem is that when the lights are off and I switch them on, the lights go crazy and it seems that it’s going through all the different scenes I have set up. Can anyone help me maybe simplify the configuration or fix my issue?

Here’s the code:

scene:
  - name: Late Evening
    entities:
      light.left_living_room_light:
        state: on
        brightness: 191
        color_temp: 154
        rgb_color: [255,140,33]
      light.right_living_room_light:
        state: on
        brightness: 191
        color_temp: 154
        rgb_color: [255,140,33]
      light.living_room_ceiling_light:
        state: on
        brightness: 51
        color_temp: 447
        rgb_color: [161,107,146]
      light.bedroom_light:
        state: on
        brightness: 114
        color_temp: 447
        rgb_color: [19,180,255]
      light.kitchen_light:
        state: on
        brightness: 206
        color_temp: 443
        rgb_color: [255,184,85]

  - name: Evening
    entities:
      light.left_living_room_light:
        state: on
        brightness: 254
        color_temp: 455
        rgb_color: [255,183,84]
      light.right_living_room_light:
        state: on
        brightness: 254
        color_temp: 455
        rgb_color: [255,183,84]
      light.living_room_ceiling_light:
        state: on
        brightness: 77
        color_temp: 447
        rgb_color: [165,145,115]
      light.bedroom_light:
        state: on
        brightness: 73
        color_temp: 370
        rgb_color: [160,141,112]
      light.kitchen_light:
        state: on
        brightness: 254
        color_temp: 376
        rgb_color: [255,198,113]

  - name: Daytime
    entities:
      group.home_lights:
        state: on
        brightness: 254
        color_temp: 231
        rgb_color: [255,231,192]

  - name: Nightlights
    entities:
      group.sensor_lights:
        state: on
        brightness: 52
        color_temp: 370
        rgb_color: [113,26,14]
-  alias: Nightlights
   trigger:
     -  platform: state
        entity_id: group.sensor_lights
        state: 'on'
     -  platform: state
        entity_id: group.sensor_lights
        to: 'on'
   condition:
     condition: time
     after: '00:00:00'
   action:
     service: scene.turn_on
     entity_id: scene.nightlights

-  alias: Day Scene
   trigger:
     -  platform: state
        entity_id: group.home_lights
        state: 'on'
     -  platform: state
        entity_id: group.home_lights
        to: 'on'
   condition:
     condition: time
     after: '07:00:00'
   action:
     service: scene.turn_on
     entity_id: scene.daytime

-  alias: Evening Scene
   trigger:
     -  platform: state
        entity_id: group.home_lights
        state: 'on'
     -  platform: state
        entity_id: group.home_lights
        to: 'on'
   condition:
     condition: time
     after: '17:00:00'
   action:
     service: scene.turn_on
     entity_id: scene.evening

-  alias: Late Evening Scene
   trigger:
     -  platform: state
        entity_id: group.home_lights
        state: 'on'
     -  platform: state
        entity_id: group.home_lights
        to: 'on'
   condition:
     condition: time
     after: '20:00:00'
   action:
     service: scene.turn_on
     entity_id: scene.late_evening

Any help would be greatly appreciated! :slight_smile:

Can no one help? :pensive:

Maybe you can also include ’ before’ in your condition?

I initially tried to include ‘before’ but it wouldn’t work and gave me an error in the log (can’t remember the exact error). Did I just do it wrong?

Thanks for the reply, by the way :slight_smile:

You need to use ‘before’

Hello! Thanks guys, I do really appreciate it!

Here’s what I’ve changed it to:

-  alias: Day Scene
   trigger:
     -  platform: state
        entity_id: group.home_lights
        state: 'on'
     -  platform: state
        entity_id: group.home_lights
        to: 'on'
   condition:
     condition: time
     after: '07:00:00'
     before: '16:59:59'
   action:
     service: scene.turn_on
     entity_id: scene.daytime

I’ll let 24 hours go by and update the thread if my issue is solved :slight_smile:

Thanks again!

Hello!

Once I added ‘before’ to the conditions, it stopped cycling through all the different scenes when I turn the lights off then back on, which is a great thing. Although, it’s not automatically changing to the difference scenes at the time I specified (i.e. after: ‘07:00:00’). Any ideas why the automation isn’t working?

Stab in the dark here… try simplifying your trigger to only include one trigger. By eliminating one, you can troubleshoot a little easier and identify which of those triggers is not working.

I see what you are trying to accomplish with both triggers, but HA might not allow you to trigger off of both the state being on and when it turns on like your automation calls. Either way, I would start simple and work from there.

So you want your scene turn on when it’s 07:00? Because your trigger (what fires the automation), only relays on the lights turning on. The time is a condition for your automation, not a trigger.
If you want your day scene turns on at 07:00, you should set the trigger for platform: time