Help with party mode lights script

Hi all,

I’m working on a party mode using my zigbee lights with deconz.

I made 2 script to make a loop for chaning color.

This works:

    lights_partying:
    mode: restart
    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: script.lights_partying_on_loop

This not ( so there’s no loop and color change only if I manually execute first script).

  lights_partying_on_loop:
    mode: queued
    alias: Loop Lights
    sequence:
      - delay:
          seconds: 1
      - service: script.lights_partying

Can someone please point me in the right direction?

Thank you in advance!

You created an endless loop here, the script lights_partying_on_loop calls light_partying, which in the end calls the other script again, this will run forever.

Well what I want to achieve is to change color of all lights randomly until I say to stop it (this will be in an automation that will call another script with light.turn_of.

At the moment the lights change color only one time. Then nothing happens.

Why not use a loop with wait template or similar?

Uhm can you be more specific?

Loop your actions like described here, use a repeat until and then have some condition like when boolean xy is off the loop is finished.

1 Like

Ok I made the update:

The script works but the condition reports error:

input_boolean:
  party:
    name: Party mode
    initial: off

  lights_partying:
    # alias: Party
    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) }}'
            - delay: 1

This is the error when checking config.

Invalid config for [input_boolean]: [alias] is an invalid option for [input_boolean]. Check: input_boolean->input_boolean->lights_partying_on->alias. (See ?, line ?).

If I change the condition it works.

Why?

1 Like

You forgot script: at the top of your script, currently your script is in the input boolean section, that’s why you get the error.

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```
4 Likes

May I suggest this for an Blueprint ?

It’s a good idea. Maybe I will have to study how to do it first :slight_smile:

Forgive my noobness, but can you tell me where to add all og this?

I tried adding the script par of your code to my scripts.yaml, but what about the rest of the code?

/wessller

I suggest you to copy paste the whole thing in a package.

In my opinion is a smarter way to manage different domains (script automation etc) that have a logic in common.

Consider using audio input to control the light - found this

It requires dedicate hw so is out of scope for me

So in package you have one inputs, one scripts and one automations?

Several scripts and several automations:

scripts:
1 save status of the lights with scene create
2 start party mode
3 restore scene

automation:

1 when input boolean turns on start script sequence
2 when input boolean turns off end script sequence

1 Like

@Jokerigno thank you for this! It’s just what I’m looking for. However, one small (dumb) question. What’s the difference between a switch and a boolean? You can both change them and do functional the same thing. The switch is I think superior because you can set the state by template.

And looking how it functions now. What do you use the switch for? It looks obsolete as everything is triggered by the input_boolean and you can change that yourself or through a service call.

And another throught. Why not loose the input_boolean and make everything trigger on the switch instead?