I have a custom template sensors that looks like this:
template:
- binary_sensor:
- name: FamilyRoom Red On
unique_id: familyroom_red_on
attributes:
parent_entity_id: 'switch.red_led'
state: >-
{% set cutoff = 0.75 %}
{% set power = states('sensor.eagle_200_meter_power_demand') | float %}
{{ power > cutoff }}
- binary_sensor:
- name: FamilyRoom Yellow On
unique_id: familyroom_yellow_on
attributes:
parent_entity_id: 'switch.yellow_led'
state: >-
{% set cutoff = 1.0 %}
{% set power = states('sensor.eagle_200_meter_power_demand') | float | abs %}
{{ power < cutoff }}
- binary_sensor:
- name: FamilyRoom Green On
unique_id: familyroom_green_on
attributes:
parent_entity_id: 'switch.green_led'
state: >-
{% set cutoff = 0.75 %}
{% set power = states('sensor.eagle_200_meter_power_demand') | float %}
{{ power < cutoff }}
they are gouped like so (this is from an include, so assume a “group:” header and correct formatting);
familyroom_led:
name: FamilyRoom LEDs
entities:
- binary_sensor.familyroom_yellow_on
- binary_sensor.familyroom_red_on
- binary_sensor.familyroom_green_on
I’m trying to access those members of the group that have status ‘on’, then get their parent_entity_id, and returned a joined string (to be used as an action in a automation). I’ve pieced together some template code to do that:
{{ expand('group.familyroom_led') | selectattr('state','eq','off') | map(attribute='parent_entity_id') | join(',') }}
But I see in the log:
021-09-03 13:02:48 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'homeassistant.helpers.template.TemplateState object'
has no attribute 'parent_entity_id' when rendering '{{ expand('group.familyroom_led') | selectattr('state','eq','off') | map(attribute='parent_entity_id') | join(',') }}'
I can see the object does indeed have the attribute that I added, parent_entity_id (also checked the entity browser).
I get this error in the log when I’m using the template tester, but interestingly I get the correct number of commas in an otherwise empty string - so the code recognizes the correct number of objects that pass the first test, but can’t extract the attribute.
If I switch the requested attribute to a “normal” attribute like entity_id, this code renders successfully, but with my “custom” attribute, it doesn’t. Am I approaching this wrong or is there a problem in the way I’m trying to use map()? Thanks, any comments would be appreciated.