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.
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?
I’ll have to give this a try tomorrow! I also have two bedside hue lights so this is perfect.
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.
Thanks for your clever idea!
I moved it a bit further: when brightness is higher, the color on my bulb goes more yellow - and back to red-ish color, when brightness is lower.
I needed variable for this, so i created script, which is called in automation.
Automation:
alias: Candle effect
trigger:
- platform: state
entity_id:
- input_boolean.candles
from: "off"
to: "on"
action:
- repeat:
until:
- condition: state
entity_id: input_boolean.candles
state: "off"
sequence:
- service: script.random_candle_setting
- delay:
milliseconds: "{{ (range(500, 1000)|random) }}"
mode: single
Ok, I thank you for your suggestions but all these solutions didn’t satisfy me fully.
I had to learn yaml (hey, guy from hass why create a new language, there are soo much that already make the job?)
I have improved the script to make it generic be able to apply to many lights simultaneously by independently.
The result is better but still does not convince me, you are welcome if you have other suggestions to make my phillips hue lamps look like candles.
Script:
I have modified this script so that it retains the color and brightness of the bulb. It makes it possible to apply the effect on any color and brightness without having to do a specific automation. In this version the light temperature is not used for the effect, but I found it to be more candle-like this way, and this is the behavior of the effect in the hue app.
Here is the pyscript (to use with the pyscript integration):
import random
@service
def candle_light(**params):
entity_id = params.get('entity_id')
if entity_id is None:
log.error(f'candle_light: entity_id required. saw {params}')
return
if not entity_id.startswith('light.'):
log.error(f'candle_light {entity_id}: entity_id must be a light')
return
task.unique(f'candle_light_{entity_id}')
statef = params.get('state')
if statef != 'on':
log.info(f'candle_light {entity_id}: stopping')
return
log.info(f'candle_light {entity_id}: starting')
brightness = state.getattr(entity_id)["brightness"]
brightness_min = max(brightness - 10, 0)
brightness_max = min(brightness + 10, 255)
delay = params.get('delay', 500)
delay_min = round(delay * 0.5)
delay_max = round(delay * 1.5)
log.info(f'candle_light {entity_id}: brightness {brightness_min}-{brightness_max}, delay {delay_min}-{delay_max}')
while True:
brightness = random.randint(brightness_min, brightness_max)
delay = (random.randint(delay_min, delay_max)) / 1000
light.turn_on(
entity_id=entity_id,
brightness=brightness,
transition=delay
)
task.sleep(delay)
With a delay of 150 it works nicely, I compared it with the hue app ‘candle’ effect on a different bulb at the same time and if you select the right temperature it does match quite well. When changing the color of your bulb to orange you have the ‘fireplace’ effect. And in green it’s interesting as well, you feel like you’re in Harry Potter
I have tried to get my head around that but failed
Could you please go into a bit more detail how to get the needed zha_toolkit variables.
Which ones are necessary and where do I get them.
Possibly to get the fireplace effect working as well.