Hi all, I’m working on a blueprint for managing all the lights in a room with a single remote, in this case a Tradfri puck. I’m aware of the already existing blueprints but my plans reach further, as I want to use the arrow buttons to cycle through the lights. However I didn’t end up there yet as I’m facing problems with the target input selector I am using:
blueprint:
name: Full room light controller
domain: automation
input:
lights:
name: Target lights
description: The lights to control
selector:
target:
entity:
domain: light
I use this to select an area, but I’ve also tried manually selecting devices (which would be okay) but that won’t work either. The problem is here, where I need to get an average brightness of all the lights selected by the target. Note that this code isn’t too functional, I removed other math and service calls so that I can focus on getting this value right.
action:
- variables:
target_light: !input lights
- choose:
# Device selector (right)
- conditions:
- condition: template
value_template: '{{ trigger.to_state.attributes.action == "arrow_right_click" }}'
sequence:
- service: logbook.log
data:
name: Find brightness level
message: 'Average brightness: {{ expand(target_light) | selectattr("attributes.brightness", "defined") | map(attribute="attributes.brightness") | average() | round(0) }}'
However in the trace:
Error: Error rendering data template: StatisticsError: fmean requires at least one data point
Which leads me to believe that expand(target) leads to nothing. In a previous try I tried to join(",") the state values but that didn’t show anything either. Now I know the docs says target is supposed to be used by service calls, but I swear that I’ve read somewhere in there that you can use it to expand targets as well. I’ve been plowing through the docs all morning but I can not find it again, so I guess I am mistaken. Is there any other way to expand a target input into devices or entities for further processing?