Hi All,
I’m building a script to standardise the behavior across all my hue switches. So i’m building a script that can be called on an action from any switch. The service will pass on the area and the action (On Press, Dim Press, Off Press, etc…) via fields / variables. Basic On/Off works fine.
Where i am stuck, is i have a template that works currently which expands all lights in an area that are on in a list, so that only the lights that are on will be dimmed. I can’t seem to work out how to put the area/variable into the expand template without getting an error.
Fields are set as follows:
fields:
area:
selector:
target: {}
name: Area
description: Target Area
required: true
step_value:
selector:
number:
min: -10
max: 10
step: 1
name: step value
required: false
type:
selector:
text: null
name: Type
required: true
Here is the part where i’m trying to embed the area into the expand template:
- conditions:
- condition: template
value_template: "{{ type == 'dim down' }}"
sequence:
- service: light.turn_on
data:
transition: 1
brightness_step_pct: "{{ step_value }}"
target:
entity_id: |-
{{ expand(area_entities(area)) | selectattr('domain', 'eq',
'light') | selectattr('state', 'eq', 'on') |
map(attribute='entity_id') | list }}
Full script here:
alias: Test Dim Script
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ type == 'off' }}"
sequence:
- service: light.turn_off
data: "{{ area }}"
- conditions:
- condition: template
value_template: "{{ type == 'on' }}"
sequence:
- service: light.turn_on
data: "{{ area }}"
- conditions:
- condition: template
value_template: "{{ type == 'dim down' }}"
sequence:
- service: light.turn_on
data:
transition: 1
brightness_step_pct: "{{ step_value }}"
target:
entity_id: |-
{{ expand(area_entities(area)) | selectattr('domain', 'eq',
'light') | selectattr('state', 'eq', 'on') |
map(attribute='entity_id') | list }}
mode: single
fields:
area:
selector:
target: {}
name: Area
description: Target Area
required: true
step_value:
selector:
number:
min: -10
max: 10
step: 1
name: step value
required: false
type:
selector:
text: null
name: Type
required: true