Can this even be done? I’m using “config-template-card” to show current power usage of items in a group. I’d like to pass in a group as a variable, then use a template to find all the entity members of the group. In the example below, sensor.all_fans_pc_power is the group, everything else is a member.
I’ve tried a variety of template approaches, but nothing seems to work. Any thoughts? Is this even possible? Please see details and attempts below.
Thanks!
Attempt 1:
Provides a LIST
{{ state_attr( 'sensor.all_fans_pc_power', 'entities') }}
results in
Result
[ “sensor.office_fan_fan_power”, “sensor.morpheus_fan_power”, “sensor.guest_fan_fan_power”, “sensor.master_fan_fan_power”, “sensor.familyroom_fan_fan_power” ]
Result type: list
This template listens for the following state changed events:
- Entity: sensor.all_fans_pc_power
Attempt 2:
Which seems like the right content for the entities:
{{ expand(state_attr( 'sensor.all_fans_pc_power', 'entities')) }}
Result type: string
This template listens for the following state changed events:
- Entity: sensor.all_fans_pc_power
- Entity: sensor.familyroom_fan_fan_power
- Entity: sensor.guest_fan_fan_power
- Entity: sensor.master_fan_fan_power
- Entity: sensor.morpheus_fan_power
- Entity: sensor.office_fan_fan_power
type: custom:config-template-card
variables:
- entity: sensor.all_fans_pc_power
- entity: sensor.familyroom_fan_fan_power
- entity: sensor.guest_fan_fan_power
- entity: sensor.master_fan_fan_power
- entity: sensor.morpheus_fan_power
- entity: sensor.office_fan_fan_power
entities:
- entity: sensor.all_fans_pc_power
- entity: sensor.familyroom_fan_fan_power
- entity: sensor.guest_fan_fan_power
- entity: sensor.master_fan_fan_power
- entity: sensor.morpheus_fan_power
- entity: sensor.office_fan_fan_power
element:
type: custom:bar-card
entities: |-
${vars.filter(v => states[v.entity].state > 0).sort((v1,v2) =>
states[v2.entity].state-states[v1.entity].state)}
direction: right
entity_row: true
min: 0
max: >-
${ Math.max(...vars.map(v => states[v.entity]).filter(e => !!e).map(e =>
e.state).filter(n => !isNaN(n))) }
height: 20px
stack: vertical
decimal: 0
icon: mdi:flash
positions:
icon: "off"
indicator: outside
name: inside
value: inside
The resulting output looks like this