Floor_areas: how select by state?

I can count the motion binary sensors for a floor using floor_areas. This works:

{{ floor_areas(floor_id(area)) 
| map('area_entities')| sum(start=[])
| select('match', 'binary_sensor.*_motion_group') 
| list| count }}

I want to count the binary sensors that are on for a floor. This doesn’t work:

{{ floor_areas(floor_id(area)) 
| map('area_entities')| sum(start=[])
| select('match', 'binary_sensor.*_motion_group') 
| selectattr('state', 'eq', 'on') 
| list| count }}

How can I do this? Ta.

The list is composed of entity IDs, not state objects, so you need to select by is_state.

{{ floor_areas(floor_id(area)) 
| map('area_entities') | sum(start=[])
| select('match', 'binary_sensor.*_motion_group') 
| select('is_state', 'on') 
| list | count }}

Thanks very much!