A simple single automation candle effect for Hue White Ambience (and other) bulbs

Tags: #<Tag:0x00007f7397d6ac10>

I wanted a nice “candle” effect, with changing brightness and warmth, but there didn’t appear to be much out there.

I have two Hue White Ambience bulbs either side of my bed, and this works an absolute treat. Suggestions/simplifications welcome!

- alias: Candle Mode Automation
  initial_state: on
  trigger: 
    platform: state
    entity_id: input_boolean.candle_mode
    to: 'on'
  action:
    - alias: Repeat this until the boolean is turned off
      repeat:
        sequence:
          - service: light.turn_on
            data_template:
              entity_id: light.left_bedside
              brightness: '{{ (range(1, 25)|random) }}'
              color_temp: '{{ (range(400, 500)|random) }}'
              transition: 1
          - delay:
              milliseconds: '{{ (range(200, 700)|random) }}'
          - service: light.turn_on
            data_template:
              entity_id: light.right_bedside
              brightness: '{{ (range(1, 25)|random) }}'
              color_temp: '{{ (range(400, 500)|random) }}'
              transition: 1
          - delay:
              milliseconds: '{{ (range(200, 700)|random) }}'
        until:
          - condition: state
            entity_id: input_boolean.candle_mode
            state: 'off'

The automation is triggered by input_boolean.candle_mode being turned on, which I do from a switch in my dashboard.

After that, the sequence will repeat until the input boolean is turned off.

It should be fairly self-explanatory, but basically it turns each light on to a random (but low) brightness, then to a random (but warm) colour temperature, then waits a random time between doing it again.

I put transition: 1 because 0 was too jarring, but it’s a real shame there isn’t a 0.5 option, as 1 doesn’t qute give the “flicker” I’d like.

8 Likes

This is really cool! Thanks very much!

I might have to try this tomorrow on my 9 bulb chandelier in my dining room. Thanks for sharing.

9 bulb! I’d love to hear how that goes… the automation goes via each light in sequence, so with 9 bulbs you may find each are on for a relatively long period of time.

I wonder if there is a way of running this in parallel? 3 automations each handling 3 bulbs maybe?

Keep us posted!

remove the random delay statement for every 3 entities? or just shorten?

suggestion way outside of my coding skills:

  1. save the state of the bulb before starting the loop, revert after exiting the loop.

If I am understanding you correctly, this would be very easy to do with the handy dandy scene.create service. Take a look at the last example here. https://www.home-assistant.io/integrations/scene/#creating-scenes-on-the-fly

I’ll have to give this a try tomorrow! I also have two bedside hue lights so this is perfect. :slightly_smiling_face:

Regarding the nine bulb situation… I wonder if you could write this as a script with the entity as a variable, and have nine instances of the script running in parallel? That would spare you “writing out” the automation actions nine times.

1 Like