I have 5 HUE bulbs in the front of my house. I wanted to make the bulbs randomly change between red/green/white. Using some templating that’s possible!
select_hue_light:
sequence:
- service: script.set_hue_christmas_color
data_template:
light_id: >-
{% set i = (range(1,6)|random) %}
{% if i == 1 %}
{% set chosen_light = "light.porch_west" %}
{% elif i == 2 %}
{% set chosen_light = "light.porch_east" %}
{% elif i == 3 %}
{% set chosen_light = "light.garage_west" %}
{% elif i == 4 %}
{% set chosen_light = "light.garage_east" %}
{% elif i == 5 %}
{% set chosen_light = "light.lamp_post" %}
{% endif %}
{{ chosen_light }}
color_name: >-
{%- set i = (range(1,6)|random) %}
{%- if i == 1 %}
{% set color = "red" %}
{%- elif i == 2 %}
{% set color = "red" %}
{%- elif i == 3 %}
{% set color = "green" %}
{%- elif i == 4 %}
{% set color = "green" %}
{%- elif i == 5 %}
{% set color = "white" %}
{%- endif %}
{{ color }}
The first script chooses between one of five lights, and chooses between red, red, green, green, and white(more likely to be red or green than white) and then calls the second script which triggers the color change.
Step 2: Now set up the automation. In my automation I have made it trigger the script every 5 seconds “/5” and only after sunset (because I don’t want them on during the day, derrr).
EDIT: It appears thatcondition: after sunsetstops firing after midnight. Open to ideas! In the meantime I changed this to only fire when one of the lights is on.
There are a couple flaws which I don’t care to spend time fixing:
the script will (fairly often) randomly select a light that’s either JUST finished changing, or is still in the process of changing (since it’s running every 5 sec and we set the transition to 10 sec). This could be addressed by re-selecting the light if it’s changed within the last 5 seconds. Don’t care enough to figure out how to do that.
the script will (again, fairly often) select the same color (i.e. red -> red or green -> green). Again, I don’t care enough to fix this but it could be prevented. (just wanted to point it out before someone else does ! )
If you want to have this automation run only during the night (so basically from “after dusk” to “beginning of dawn”) you could make use of my period-of-day identification. Simply build your condition like below:
Tried that (from the UI editor). Didn’t work - I presume the editor takes all conditions and then ANDs them together. In this case, it cannot be both conditions at once because it seems they are mutually exclusive, so I’d need to OR them but guess that’s not possible from the UI currently. shrug
Anding them together is fine but if you really want to or them then you can do that by manually writing the script if necessary. i do it all the time and it works fine. They aren’t mutually exclusive either. see my explanation above.
This is a great share! Same setup as me where I have about 5-6 bulbs in the front of my house too.
I know the post is quite old but I am a new HA user (HA Green on the way) and was wondering about this type of automation. I have a LOT of Hue bulbs that I will be pairing with the hub. Was hoping to remove the Phillips Hue hub after but the wife likes to do halloween and Christmas light themes.
Is this still valid and functional? Is there more of these automations for HA out there?