Dim light group over period of X seconds to off state

Hi all,
I am just starting to understand HA and I am slowly moving all my lights from Hue to the Zigbee dongle.
As part of that migration I am trying to build scenes.

I am attempting to create a scene button on my dashboard that once pressed:

  • Switches on all my lights in the bedroom at a predefined color and brightness
  • Dims over a period of 10 minutes to off.
    I am nog having any luck in the Scenes Visual Editor, so I am looking for another solution (yaml/node-red). It is however not easy to find the right search words, so I cannot find any examples.
    Hopefully someone can point me in the right direction.

You could creat an input_boolean and combine it with an automation. Something like


alias: Bedroom Scening
mode: single
trigger:
  - platform: state
    entity_id:
      - input_boolean.bedroom
condition: []
action:
  - if:
      - condition: state
        entity_id: input_boolean.bedroom
        state: 'on'
    then:
      - service: light.turn_on
        data:
          rgb_color:
            - 211
            - 131
            - 1
          brightness: 90
        target:
          entity_id:
            - light.bedroom
    else:
      - service: light.turn_off
        target:
          entity_id:
            - light.bedroom
        data:
          transition: 600

Of you want to go both steps on a single button press, I think, you cannot use scenes for that, because they allow only one command for each entity. So, you can either turn lights on; or off. You’ll have to create a script for that.

BTW. I have changed most of my scenes to scripts, because I would run into one limitation or the other. It’s not much more configuration and much more flexible. You can even call the manual scene.apply service from your scripts.

Thanks @pedolsky, that is generally what I was looking for. The only thing is that I would like to do this in one button press:

  • Lights on
  • Dim over X minutes until off

@akloeckner: You are right, so I should go the direction of scripts instead of scenes? My script looks like this:

turn_light_on_and_dim_in_x_seconds:
  alias: Turn light on and dim in X seconds
  sequence:
  - type: turn_on
    device_id: c09891bcc2cf57af1319067e15ca763e
    entity_id: light.hue_color_lamp_1
    domain: light
  - service: light.turn_off
    data:
      transition: 20
    target:
      device_id: c09891bcc2cf57af1319067e15ca763e
  mode: single
  icon: mdi:lightbulb

The script works, now I want more:

  • Link to a button: should be easy
  • Switch a complete Light Group and modify setting for each individual light (brightness, color, color temp etc)
  • Second tigger on a motion sensor, but only between 2200 and 0000, but not when I am already in my bed (so probably need pressure sensor :slight_smile: )

Thank you both for helping me out this far.

I don’t get that point. This would mean you turn on the lights and immediately turn off again.

Link to button

Yes, that’s just an automation.

Switch a light group

You might actually want to use scene.apply for that.

Add second trigger

That will be just that: adding a second trigger to your automation. I believe, there is a new option to add a condition to that new trigger. If not, you’ll have to add some clever condition logic.

This would mean you turn on the lights and immediately turn off again.

I guess it’s kind of a smooth staircase lighting? In that case, you could also add a short delay before starting to dim immediately.

@pedolsky: You are correct. It is a sleep routine. When we decide to go to bed, I press the sleep routine button. It will turn on the lights in the bedroom and over a period of 10 - 15 minutes the lights slowly dim until out.

@akloeckner: Thanks, that is all very helpful. I like the delay option you mentioned. That way I can have the lights on for 10 minutes and over a period of 5 slowly dim until completely off.

Cool, this is where I am now:

turn_light_on_and_dim_in_x_seconds:
  alias: Turn light on and dim in X seconds
  sequence:
  - service: light.turn_on
    data:
      brightness_pct: 100
    target:
      entity_id: light.lights_group_master_bedroom
  - delay: 00:10:00
  - service: light.turn_off
    data:
      transition: 300
    target:
      entity_id: light.lights_group_master_bedroom
  mode: single
  icon: mdi:lightbulb

It might not be the most complicated routine, but I am starting to get the hang of it. More to follow!