Disco Light help

I am a real beginner on hassio, but i want to have a light that changes color fast (like a disco) in my dahugters room, i have the basic setup for it, but i can’t get it to loop… this is what i currently have in scripts:

lights_party_on:
  alias: Party ON!
  sequence:
    service: light.turn_on
    data_template:
      entity_id: light.lampa_emmas_rum_2
      rgb_color:
        [
          "{{ (range(0, 255)|random) }}",
          "{{ (range(0, 255)|random) }}",
          "{{ (range(0, 255)|random) }}",
        ]
      brightness: "{{ (range(50, 250)|random) }}"
      transition: "0.1"

But i want it to loop, and if possile have a slider that i can change the speed of it :slight_smile:

Thanks in advance
/Cozilic

3 Likes

ok, i got it to work… with some modifications from another script… now i just need a slider to controll the speed… :slight_smile:

I’ve manage to get a slider to for somwhat good, put want it on the ui and not on a buttonpress… I’ll check some more :blush:

1 Like

Could you please share your configuration?

I’m also very interested in your setup if you don’t mind sharing it!

Here is my configuration for my party lights setup, based on another script here.

configuration.yml

# ##########################################################################################
# # Inputs
# ##########################################################################################

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
# ##########################################################################################

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

automation.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.lampa_emmas_rum_2
    - delay: 1
    - service: script.lights_partying_off

inputs.yaml

party:
  name: La Festa
  icon: mdi:PartyPopper
  initial: off

switch:
  - platform: template
    switches:
      party:
        value_template: '{{ states("input_boolean.party") }}'
        friendly_name: "Party!"
        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.yaml

lights_partying_on:
  alias: Lights partying on
  sequence:
    - service: scene.create
      data:
        scene_id: studioprimaparty
        snapshot_entities:
          - light.lampa_emmas_rum_2
    - 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.lampa_emmas_rum_2
              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.studioprimaparty

Looks like this:

8 Likes

Thank you for sharing!

Hi, I have tride to use your code and just change light.lampa_emmas_rum_2 to the name as my light is. But I dont get it to work.
How do you “link” to “inputs.yaml”
I dont get input: !include inputs.yaml to work. or inputs: !include inputs.yaml
Thanks. =)

Thanks for that @cozilic

Any idea on how to add extra lights? Also is there a way to smooth the transitions?

I’ll check how to add more lights, but I think the transition is: transition: 0.1 under Scripts.yaml :slight_smile:

I’ll check how I added the input.yaml file

I just got it working!

but tbh I think from another version of your script I found lol

But also I would love to see your updated script :pray:

It’s not my script, I found a script that I modified for my needs, I take no credit for this script at all :blush:

Thanks for this !
Instead of two icons, it’s better to use custom:slider-entity-row to change the speed, it’s take less space and can be change with only one clic !

      - type: vertical-stack
        cards:
          - type: button
            tap_action:
              action: toggle
            entity: switch.party
            icon: mdi:party-popper
          - entity: input_number.party_speed
            type: custom:slider-entity-row
            name: Speed
            full_row: true

Can you elaborate on how you got it working?

Can someone explain what to do with the inputs.yaml bit and how to actually get a card in Lovelace to control the whole thing? I do not see any inputs.yaml file in my homeassistant installation. I tried creating a new file at the same level as configuration.yaml but that still did not seem to do anything.

I got it working :slight_smile:

Ignore the inputs.yaml file above, and make a card on your lovelace dashboard as @Roumano said with:

type: vertical-stack
cards:
  - type: button
    tap_action:
      action: toggle
    entity: switch.party
    icon: mdi:party-popper
  - entity: input_number.party_speed
    type: custom:slider-entity-row
    name: Speed
    full_row: true

This assumes you have GitHub - thomasloven/lovelace-slider-entity-row: 🔹 Add sliders to entity cards installed

1 Like

Thanks a lot for the dicussion. Finally i´ve got it running with my shelly rgbw2.

Since white type of colors ofte show up, I am wondering if it would be possible to add a color list, where the script randomly picks the colors.

I suppose the colors should be also defined in the lights partying script.

service: light.turn_on
data_template:
  entity_id: light.shellyrgbw2_e868e7f34e2a
  rgbw_color:
    - "{{ (range(0, 255)|random) }}"
    - "{{ (range(0, 255)|random) }}"
    - "{{ (range(0, 255)|random) }}"
    - "0"
  brightness: "{{ (range(50, 250)|random) }}"
  transition: 0.2

Would be something like this:?

- alias: "Set variables"
  variables:
    entities:
      - rgbw_color1
       rgbw_color: 0,200,0,0
      - rgbw_color1
       rgbw_color: 200,0,0,0

Anybody who could help?