Skip to content

Instantly share code, notes, and snippets.

@ps-jay
Last active June 8, 2023 11:46
Show Gist options
  • Select an option

  • Save ps-jay/42e1320d39424136888eae7de59e2c6e to your computer and use it in GitHub Desktop.

Select an option

Save ps-jay/42e1320d39424136888eae7de59e2c6e to your computer and use it in GitHub Desktop.
blueprint:
name: Simple On + Reset
description: |
Turn on specified lights, or if already on then reset to colour and brightness
source_url: https://gist.github.com/ps-jay/42e1320d39424136888eae7de59e2c6e
domain: automation
input:
lights:
name: Lights
description: Lights to turn on
default: []
selector:
device:
multiple: true
entity:
- domain:
- light
percent:
name: Percent
description: Percent brightness to reset to
selector:
number:
min: -100.0
max: 100.0
step: 1.0
mode: slider
transition:
name: Transition
description: Transition time to apply the dimming in seconds
default: 0
selector:
number:
mode: box
step: 0.1
colour:
name: Colour
description: Colour in Kelvin to reset to
selector:
number:
min: 1000.0
max: 8000.0
step: 1.0
mode: slider
variables:
targets: !input lights
# map devices -> entities
entities: |
{%- set ns = namespace(ret=[]) %}
{%- if targets %}
{%- set targets = [ targets ] if targets is string else targets %}
{%- set targets = targets | map('device' ~ '_entities') | sum ( start = [] ) %}
{%- set ns.ret = ns.ret + [ targets ] %}
{%- endif %}
{{ ns.ret | sum(start=[]) }}
light_entities: "{{ entities | select( 'search' , '^light' ) | list }}"
lights_on: "{{ light_entities | select('is_state', 'on') | list }}"
lights_on_bool: "{{ lights_on | count > 0 }}"
trigger: []
condition: []
action:
- if:
- condition: template
value_template: "{{ lights_on_bool }}"
then:
- service: light.turn_on
data:
brightness_pct: !input percent
kelvin: !input colour
transition: !input transition
target:
device_id: !input lights
else:
- service: light.turn_on
data:
transition: !input transition
target:
device_id: !input lights
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment