Having trouble accessing custom attribute from map

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.

Have you solved? I am facing a similar problem
I added a custom attribute through customize.yaml

light.cespuglio_divano:
icon: /local/image.png
friendly_name: Cespuglio Divano
technology: switch-as
brand: homeassistant
floor: Terra

I can see it through the UI and if I put it in a template like
{{ state_attr(‘light.cespuglio_divano’, ‘floor’) }}
I get “Terra”

{{ states.light.cespuglio_divano }}

returns:
<template TemplateState(<state light.cespuglio_divano=off; supported_color_modes=[<ColorMode.ONOFF: ‘onoff’>], friendly_name=Cespuglio Divano, supported_features=LightEntityFeature.0, icon=/local/image.png, technology=switch-as, brand=homeassistant, floor=Terra @ 2023-03-25T16:44:17.037442+01:00>)>

but:

{{ states.light |
selectattr(‘attributes.Floor’, ‘defined’) |
selectattr(‘Floor’,‘eq’,‘Terra’) |
map(attribute=‘entity_id’) |
list }}

returns []

and actually
{{ states.light |
selectattr(‘attributes.Floor’, ‘defined’) |
list }}
returns []
as if it was not defined.

Same problem here:

In customize.yaml

sensor.mean_rssi_mi_band_childbed_1:
  room: "living"

template

{{ expand('sensor.mean_rssi_mi_band_childbed_1') | map(attribute='room') | first }}

result

'homeassistant.helpers.template.TemplateState object' has no attribute 'room'

map is not accepting custom attributes which is surprising because in the state

state_class: measurement
source_value_valid: true
unit_of_measurement: dBm
device_class: signal_strength
icon: mdi:calculator
friendly_name: Mean Rssi Mi Band ChildBed 1
room: child 1
age_coverage_ratio: 0.29

the attribute is well defined and it is not categorized differently from the others