dr-insane
(Jan Hupfeld)
February 17, 2023, 8:14am
23
My quick solution goes like this with just copying the actions and focus on the basic colors. Lokks nice
repeat:
while:
- condition: state
entity_id: input_boolean.party
state: "on"
sequence:
- service: light.turn_on
data_template:
entity_id: light.shellyrgbw2_e868e7f34e2a
rgbw_color:
- "255"
- "{{ (range(0, 100)|random) }}"
- "{{ (range(0, 100)|random) }}"
- "0"
brightness: "{{ (range(50, 250)|random) }}"
transition: 0.1
- delay: "{{ states.input_number.party_speed.state }}"
- service: light.turn_on
data_template:
entity_id: light.shellyrgbw2_e868e7f34e2a
rgbw_color:
- "{{ (range(0, 100)|random) }}"
- "255"
- "{{ (range(0, 100)|random) }}"
- "0"
brightness: "{{ (range(50, 250)|random) }}"
transition: 0.2
- delay: "{{ states.input_number.party_speed.state }}"
- service: light.turn_on
data_template:
entity_id: light.shellyrgbw2_e868e7f34e2a
rgbw_color:
- "{{ (range(0, 100)|random) }}"
- "{{ (range(0, 100)|random) }}"
- "255"
- "0"
brightness: "{{ (range(50, 250)|random) }}"
transition: 0.2
- delay: "{{ states.input_number.party_speed.state }}"
2 Likes
chunk1970
(Nigel Higgins)
March 22, 2023, 10:44am
24
Thanks all for this info. I managed to setup three bulbs running separate scripts.
What would be nice if we could setup this as a blue print so this could be setup eaiser. Would also be great if we could setup a list of light colours to choose by name.
Any ideas how this could be done as a blueprint?
Thanks for awesome sharing in this post!
I’m not completely finished with the tuning, but this example shows how we can create a list of explicit RGB colors to choose from (which could be extended for easier use). The only thing I’d like to do is modify the random selector to calculate the length of the color array rather than explicitly set a range.
lights_partying:
variables:
colors:
- [25,25,112]
- [72,61,139]
- [255,0,0]
- [255,140,0]
sequence:
- repeat:
while:
- condition: state
entity_id: input_boolean.party
state: "on"
sequence:
- service: light.turn_on
data_template:
entity_id: group.downstairs_living_room
rgb_color: "{{ colors[(range(0, 3)|random)] }}"
brightness: "{{ (range(50, 250)|random) }}"
transition: 0.1
- delay: "{{ states.input_number.party_speed.state }}"
2 Likes
Have you figured this out yet?
I’m struggling with the same thing.
DOSirl
August 31, 2023, 2:42pm
28
Thanks all for the code.
I’ve used the repeat - while and the code within there, with some minor adjustments for the lights/LEDs I want to use this code on, but I’ve found that it stops on a random color after 3 to 5 colors.
Turn it on, lights come on with a random color, the change as per the setting, but after 3 to 4 color changes, it just stops changing and stays on the final color.
I don’t suppose anyone knows what I’m doing wrong?
Once I turn the Boolean off, it follows the correct automation sequence and does what its supposed to, but I just can’t get it to keep changing color.
For me, the following worked, only replace the entity_id: light.living_room_lights with yours in scenes.yaml , automation.yaml and in scripts.yaml :
In scenes.yaml:
- id: '1697057636536'
name: Party
entities:
light.living_room_lights:
state: 'off'
metadata: {}
In configuration.yaml:
input_boolean:
party:
name: Party ON!
icon: mdi:party-popper
initial: off
input_number:
party_speed:
name: Speed
initial: 0.4
min: 0.1
max: 0.9
step: 0.1
switch:
- platform: template
switches:
party:
value_template: '{{ states("input_boolean.party") }}'
friendly_name: "La Festa"
turn_on:
- service: input_boolean.turn_on
entity_id: input_boolean.party
turn_off:
- service: input_boolean.turn_off
entity_id: input_boolean.party
In automations.yaml:
- alias: "Lights partying on"
id: "La Festa ON"
initial_state: true
trigger:
- platform: state
entity_id: input_boolean.party
from: "off"
to: "on"
action:
service: script.lights_partying_on
- alias: "Lights partying off"
id: "La Festa OFF"
initial_state: true
trigger:
- platform: state
entity_id: input_boolean.party
from: "on"
to: "off"
action:
- service: light.turn_off
entity_id:
- light.living_room_lights
- delay: 1
- service: script.lights_partying_off
In scripts.yaml:
lights_partying_on:
alias: Lights partying on
sequence:
- service: scene.create
data:
scene_id: party
snapshot_entities:
- light.living_room_lights
- service: script.turn_on
entity_id: script.lights_partying
lights_partying:
sequence:
- repeat:
while:
- condition: state
entity_id: input_boolean.party
state: "on"
sequence:
- service: light.turn_on
data_template:
entity_id: light.living_room_lights
rgb_color:
[
"{{ (range(0, 255)|random) }}",
"{{ (range(0, 255)|random) }}",
"{{ (range(0, 255)|random) }}",
]
brightness: "{{ (range(50, 250)|random) }}"
transition: 0.1
- delay: "{{ states.input_number.party_speed.state }}"
lights_partying_off:
alias: Lights partying off
sequence:
- service: scene.turn_on
data:
entity_id: scene.party
1 Like