Skip to content

Instantly share code, notes, and snippets.

@Twanne
Last active January 26, 2024 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Twanne/7dead57425a246a8845d62e4be2238f5 to your computer and use it in GitHub Desktop.
Save Twanne/7dead57425a246a8845d62e4be2238f5 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Party Lights (BETA)
#To do:
# - Change lights at random times
# - Effects
# - Return to original state after turn-off
blueprint:
name: Party Lights (BETA)
author: AntonH
description: |
**Version 1.3** **(BETA)**
Lights go to party mode (color loops or fade-in-and-out)
⚠️ **NOTE:** ⚠️
*This automation is triggered by the status of a switch or an input_boolean entity.*
*You can create this input_boolean by going to Settings > Devices & services > Helpers*
*There you click on 'Create helper and choose 'Toggle'.*
source_url: https://gist.github.com/Twanne/7dead57425a246a8845d62e4be2238f5
domain: automation
input:
#Select input_boolean
party_mode_trigger:
name: Party mode trigger
description: |
The trigger you want to use to turn the party mode on.
The automation will keep running until this is turned off.
Supported entity types:
- input_boolean
- switch
default: []
selector:
entity:
domain:
- input_boolean
- switch
#Target lights
target_light:
name: Target lights
description: Which lights do you want to control?
selector:
entity:
multiple: true
filter:
domain: light
#Synchronize or not
sync_lights:
name: Synchronize lights
description: |
If more than 1 target light is selected, choose if they will all change together or if they each get their own random values.
**NOTE:**
*Light groups will be seen an a single entity.*
default: true
selector:
boolean:
#Time between changes
time_between_changes:
name: Time between changes
description: Change the lights setting after this duration
default:
hours: 0
minutes: 0
seconds: 0
selector:
duration:
#Transition
transition_time:
name: Transition time
description: |
The time it takes for the light to transition to the assigned value when it's triggered.
WARNING!:
This value should not be greater than the time between changes
default: 0
selector:
number:
min: 0
max: 300
step: 1
unit_of_measurement: s
mode: slider
#Select color mode
color_mode:
name: Color mode
description: |
Select how the lights need to change
1. ⬛ **NO COLOR CHANGE:**
Don't change colors.
2. 🌈 **RANDOM COLOR MODE**
Change all RGB values randomly.
3. 🟥 **REDS ONLY MODE:**
Change only red value randomly.
4. 🟩 **GREENS ONLY MODE:**
Change only green value randomly.
5. 🟦 **BLUES ONLY MODE:**
Change only blue value randomly.
6. 🟦 **TEALS ONLY MODE:**
Change only blue value randomly.
7. 🟪 **PINKS ONLY MODE:**
Change only blue value randomly.
8. 🟨 **YELLOWS ONLY MODE:**
Change only blue value randomly.
default: no_color_change
selector:
select:
mode: dropdown
options:
- label: NO COLOR CHANGE
value: no_color_change
- label: RANDOM COLOR MODE
value: random
- label: REDS ONLY MODE
value: red
- label: GREENS ONLY MODE
value: green
- label: BLUES ONLY MODE
value: blue
- label: TEALS ONLY MODE
value: teal
- label: PINKS ONLY MODE
value: pink
- label: YELLOWS ONLY MODE
value: yellow
#Select brightness mode
brightness_mode:
name: Brightness mode
description: |
Select how the lights need to change
1. **RANDOM BRIGHTNESS:**
Change the brightness randomly within a set range
2. **FIXED BRIGHTNESS:**
Keep the light at a user defined brightness
default: random
selector:
select:
mode: dropdown
options:
- label: RANDOM BRIGHTNESS
value: random
- label: FIXED BRIGHTNESS
value: fixed
#Min Brightness percentage
min_brightness_pct:
name: Minimum brightness (RANDOM BRIGHTNESS MODE)
description: Don't set the brightness of the light below this value
default: 0
selector:
number:
min: 0
max: 100
step: 1
mode: slider
unit_of_measurement: "%"
#Max brightness percentage
max_brightness_pct:
name: Maximum brightness (RANDOM BRIGHTNESS MODE)
description: Don't set the brightness of the light above this value
default: 100
selector:
number:
min: 0
max: 100
step: 1
mode: slider
unit_of_measurement: "%"
#Fixed brightness percentage
fixed_brightness_pct:
name: Brightness (FIXED BRIGHTNESS MODE)
description: Keep the light at this percentage (color changes might affect this somewhat)
default: 0
selector:
number:
min: 0
max: 100
step: 1
mode: slider
unit_of_measurement: "%"
#Mode
mode: restart
#Variables
variables:
party_mode_trigger: !input party_mode_trigger
target_light: !input target_light
sync_lights: !input sync_lights
time_between_changes: !input time_between_changes
transition_time: !input transition_time
color_mode: !input color_mode
brightness_mode: !input brightness_mode
min_brightness_pct: !input min_brightness_pct
max_brightness_pct: !input max_brightness_pct
fixed_brightness_pct: !input fixed_brightness_pct
#Trigger
trigger:
- platform: state
entity_id: !input party_mode_trigger
to: "on"
#Actions:
action:
#Loop
- repeat:
sequence:
- choose:
#Synchronized lights
- conditions: '{{ sync_lights is true }}'
sequence:
#Define the brightness and rgb values
- 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(0,255) | random, range(0,255) | random, range(0,255) | random }}
{% elif color_mode == "red" %}
{{ range(0,255) | random, 0, 0 }}
{% elif color_mode == "green" %}
{{ 0, range(0,255) | random, 0 }}
{% elif color_mode == "blue" %}
{{ 0, 0, range(0,255) | random }}
{% elif color_mode == "teal" %}
{{ range(0,255) | random, 255, 255 }}
{% elif color_mode == "pink" %}
{{ 255, range(0,255) | random, 255 }}
{% elif color_mode == "yellow" %}
{{ 255, 255, range(0,255) | random }}
{% else %}
{{ 255, 255, 255 }}
{% endif %}
#Call the lights
- service: light.turn_on
data: >
{% if color_mode == "no_color_change" %}
{{ { "transition": transition_time, "brightness_pct": brightness_value } }}
{% else %}
{{ { "transition": transition_time, "brightness_pct": brightness_value, "rgb_color": rgb_value } }}
{% endif %}
target:
entity_id: '{{ target_light }}'
#Unsynchronized lights
- conditions: '{{ sync_lights is false }}'
sequence:
#Send values to log for debugging
- service: system_log.write
metadata: {}
data:
level: warning
message: >
target_light: {{ target_light }}
- repeat:
for_each: '{{ target_light }}'
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(0,255) | random, range(0,255) | random, range(0,255) | random }}
{% elif color_mode == "red" %}
{{ range(0,255) | random, 255, 255 }}
{% elif color_mode == "green" %}
{{ 255, range(0,255) | random, 255 }}
{% elif color_mode == "blue" %}
{{ 255, 255, range(0,255) | random }}
{% else %}
{{ 255, 255, 255 }}
{% endif %}
#Call the lights
- service: light.turn_on
data: >
{% if color_mode == "no_color_change" %}
{{ { "transition": transition_time, "brightness_pct": brightness_value } }}
{% else %}
{{ { "transition": transition_time, "brightness_pct": brightness_value, "rgb_color": rgb_value } }}
{% endif %}
target:
entity_id: '{{ repeat.item }}'
#Wait until the next change
- delay: !input time_between_changes
until:
- condition: state
entity_id: !input party_mode_trigger
state: "off"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment