šŸŽ‰ Party Lights - Randomly loop through color and brightness values

I studied IT in the past and always enjoyed programming, but I do something completely different now. Occasionally writing blueprints or scripts keeps my mind trained in thinking through logic and itā€™s just satisfying to see an idea come to life.

1 Like

Great to see it works well for you!

Is it possible to have less than 1 second for the lights to switch colors?
1 second is a bit too much i would prefer half a second for more BPM tracks :slight_smile:

There are power on defaults for some bulbs - but some donā€™t let you pick default colors etc. Thatā€™s a loss of power/restored scenario.

In my case, the lights are already powered on, but software turned off. I think for the ā€œreturn to previous stateā€ you have to first send a command of ā€œonā€ to each bulb in the list. Then proceed with color changes. That should keep the temperature and settings that they were originally in. Not sure how hard itā€™s to implement that.

What is their state in Home Assistant in this case? On or off?

Essentially what the Blueprint does is make a snapshot the state of the lights before looping through the colors and then restoring that snapshot. So if your lights are off, they will return to off.

If you want them to return to a specific setting, then you can create a scene yourself and let the Blueprint activate that when the party mode is turned off.

Shouldnā€™t be very hard, Iā€™ll add that in the next release.
Do take into account that you may run into buffering issues quite quickly (see some earlier comments).

This feature has now been added.

Hi @AntonH ,
do you mean my transition request was implemented? do i need to pull the blueprint again? Im pretty new to HA, sorry for my dumb questions.

Yes if the Blueprint is updated you need to redownload into HA to get the new features.

You can do this in Settings > Automatons & Scenes > Blueprints and then using the three-dots/overflow menu against the blueprint you want to update.

1 Like

First I want to say thank you so much @AntonH for this blueprint! It was exactly what Iā€™ve been trying to do myself for awhile but could never get working right. I did want to have a bit more control of the color options and performing other actions before and after the loop so I ā€œtook overā€ the blueprint so I could edit the base YAML for my changes and itā€™s all working great except for 1 thing and Iā€™m not sure what Iā€™m doing wrong. Iā€™m trying to have a attribute of an entity (the ā€œdescriptionā€ attribute of the entity ā€œcalendar.ttrpg_gamesā€) define the ā€œcolor_modeā€ variable but everytime I save the updated YAML it ignores the attribute I defined and reverts to the previous saved value of ā€œrandomā€. Basically what Iā€™m trying to do is have the current selected color mode set based off the description I have in my calendar event that is triggering it. Any help or tips would be greatly appreciated, here is a copy of the entire current automation so far.

alias: Lighting_DnD_Random
description: Magic lights mode for DnD campaigns
trigger:
  - platform: state
    entity_id:
      - calendar.ttrpg_games
    to: "on"
    enabled: true
condition: []
action:
  - action: scene.create
    metadata: {}
    data:
      scene_id: lighting_dndmode_priorstate
      snapshot_entities: "{{ target_lights }}"
  - action: automation.turn_off
    metadata: {}
    data:
      stop_actions: true
    target:
      entity_id:
        - automation.office_lightstoggle_motion_01
        - automation.hallway_lightsoff_relay_01
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id:
        - switch.adaptive_lighting_office_ledstrip_01
        - switch.adaptive_lighting_office_main_01
        - switch.adaptive_lighting_hallway_room_01
  - repeat:
      sequence:
        - repeat:
            for_each: "{{ target_lights }}"
            sequence:
              - variables:
                  brightness_value: |
                    {% if brightness_mode == "random" %}
                      {{ range(min_brightness_pct, max_brightness_pct) | random }}
                    {% else %}
                      {{ fixed_brightness_pct }}
                    {% endif %}
                  rgb_value: |
                    {% if color_mode == "random" %}
                      {{ range(5,255) | random, range(5,255) | random, range(5,255) | random }}
                    {% elif color_mode == "red" %}
                      {{ range(5,255) | random, 0, 0 }}
                    {% elif color_mode == "green" %}
                      {{ 0, range(5,255) | random, 0 }}
                    {% elif color_mode == "blue" %}
                      {{ 0, 0, range(5,255) | random }}
                    {% elif color_mode == "teal" %}
                      {{ range(5,255) | random, 255, 255 }}
                    {% elif color_mode == "pink" %}
                      {{ 255, range(5,255) | random, 255 }}
                    {% elif color_mode == "yellow" %}
                      {{ 255, 255, range(5,255) | random }}
                    {% elif color_mode == "dark" %}
                      {{ range(150,255) | random, range(5,30) | random, 0 }}
                    {% else %}
                      {{ 255, 255, 255 }}
                    {% endif %}
              - data: |
                  {% if color_mode == "no_color_change" %}
                    {{ { "transition": transition_time, "brightness_pct": brightness_value, "effect": light_effect } }}
                  {% else %}
                    {{ { "transition": transition_time, "brightness_pct": brightness_value, "rgb_color": rgb_value, "effect": light_effect  } }}
                  {% endif %}
                target:
                  entity_id: "{{ repeat.item }}"
                action: light.turn_on
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
      until:
        - condition: state
          entity_id: calendar.ttrpg_games
          state: "off"
  - metadata: {}
    target:
      entity_id: scene.lighting_dndmode_priorstate
    action: scene.turn_on
  - action: automation.turn_on
    target:
      entity_id:
        - automation.office_lightstoggle_motion_01
        - automation.hallway_lightsoff_relay_01
    data: {}
  - action: switch.turn_on
    target:
      entity_id:
        - switch.adaptive_lighting_office_ledstrip_01
        - switch.adaptive_lighting_office_main_01
        - switch.adaptive_lighting_hallway_room_01
    data: {}
mode: restart
variables:
  party_mode_trigger: input_boolean.lighting_dndmode
  target_lights:
    - light.office_ledstrip_desktop_01
    - light.office_lightbulb_fanlight_01
    - light.office_lightbulb_fanlight_02
    - light.office_lightbulb_fanlight_03
    - light.office_lightbulb_lamp_01
    - light.office_lightbulb_lamp_02
    - light.office_lightbulb_lamp_03
    - light.office_lightbulb_lamp_04
    - light.hallway_lightbulb_ceiling_01
    - light.hallway_lightbulb_ceiling_02
  transition_time: 1
  color_mode: {{ state_attr("calendar.ttrpg_games", "description") }}
  brightness_mode: random
  min_brightness_pct: 10
  max_brightness_pct: 100
  fixed_brightness_pct: 100
  light_effect: ""

UPDATE: Big thanks to @karwosts on the discord for helping me figure out what I was messing up. Solution below:
Change

color_mode: {{ state_attr("calendar.ttrpg_games", "description") }}

to this

color_mode: '{{ state_attr("calendar.ttrpg_games", "description") }}'
1 Like

Looks great!
Are you changing the colors on the fly during the game with this or whatā€™s the reason you want to set it through the calendar?

NEW RELEASE

16/09/2024 - Version 2.3

  • Added support for shorter delays by adding a millisecond option to the ā€˜time between changesā€™.
    WARNING: this might cause a buffering issue to occur because of the frequent changes.
  • Modified some explanations to improve user friendliness.

This has been added in version 2.3

1 Like

Is it just me or import currently doesnā€™t work?

I get an error ā€œInvalid blueprint: extra keys not allowed @ data[ā€˜blueprintā€™][ā€˜inputā€™][ā€˜time_between_changesā€™][ā€˜selectorā€™][ā€˜enable_millisecondā€™]. Got Noneā€

Thanks

Have you upgraded to the latest version of HA?
The support for this has been added only recently.

Thank you, this might be the issue. Iā€™ll re-check, although Iā€™m currently running Core version 2024.7.4.

Thanks

1 Like

I believe it was added in 2024.8

1 Like

Hello everyone.

Love this Blueprint. Works very well with my Philips Hue Iris.

I seem to have issues with my Tradfri bulbs from Ikea. Some colours on the random mode just stay white on those but work well on my Iris.

I feel like this is a limitation on the Tradri bulbs.

Anyone has a workaround or advice to prevent just the white colours?

Thanks,

I have added HUE COLOR MODE, which cycles between random fully saturated colors (using hs_color).

https://gist.githubusercontent.com/hugokerstens/f428e772d9bf2ce4b872bca69b392725/raw/bd42754e98264aacb7fbd0010db05d4cd7c70d0f/party_lights.yaml

@AntonH Feel free to copy/adjust this and integrate it in your version.

@misterd4n This seems to partially address your issue, this color mode prevents white colors.

1 Like

Thank you! I will test it!