Damn. I feel so stupid sometimes. Thank you for pointing me to the right direction.
Here’s the full work for anyone will use it:
# ##########################################################################################
# # Inputs
# ##########################################################################################
input_boolean:
party:
name: La Festa
icon: mdi:PartyPopper
initial: off
# ##########################################################################################
# # Inputs
# ##########################################################################################
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
##########################################################################################
# Scripts
##########################################################################################
script:
lights_partying_on:
alias: Lights partying on
sequence:
- service: scene.create
data:
scene_id: studioprimaparty
snapshot_entities:
- light.lampada_scrivania
- light.jack_lamp
- light.comodino_marco
- light.comodino_irene
- light.lampada_fiore
- light.lampada_simonasalvo
- light.striscia_led
- light.piantana
- 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.lampada_scrivania
rgb_color: ['{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}']
brightness: 250
transition: '{{ (range(1, 3)|random) }}'
- service: light.turn_on
data_template:
entity_id: light.jack_lamp
rgb_color: ['{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}']
brightness: 250
transition: '{{ (range(1, 3)|random) }}'
- service: light.turn_on
data_template:
entity_id: light.piantana
rgb_color: ['{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}']
brightness: 250
transition: '{{ (range(1, 3)|random) }}'
- service: light.turn_on
data_template:
entity_id: light.lampada_fiore
rgb_color: ['{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}']
brightness: 250
transition: '{{ (range(1, 3)|random) }}'
- service: light.turn_on
data_template:
entity_id: light.lampada_simonasalvo
rgb_color: ['{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}']
brightness: 250
transition: '{{ (range(1, 3)|random) }}'
- service: light.turn_on
data_template:
entity_id: light.striscia_led
rgb_color: ['{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}']
brightness: 250
transition: '{{ (range(1, 3)|random) }}'
- service: light.turn_on
data_template:
entity_id: light.comodino_irene
rgb_color: ['{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}']
brightness: 250
transition: '{{ (range(1, 3)|random) }}'
- service: light.turn_on
data_template:
entity_id: light.comodino_marco
rgb_color: ['{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}',
'{{ (range(0, 255)|random) }}']
brightness: 250
transition: '{{ (range(1, 3)|random) }}'
- delay: 1
lights_partying_off:
alias: Lights partying off
sequence:
- service: scene.turn_on
data:
entity_id: scene.studioprimaparty
##########################################################################################
# Automations
##########################################################################################
automation:
- 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.lampada_scrivania
- light.jack_lamp
- light.comodino_marco
- light.comodino_irene
- light.lampada_fiore
- light.lampada_simonasalvo
- light.striscia_led
- light.piantana
- delay: 1
- service: script.lights_partying_off```