Filters are applied in order left to right. You need to select all the entities that are on before mapping the entity id.
{{expand(state_attr('light.all_lights', 'entity_id'))| selectattr('state','eq','on')|map(attribute='entity_id')|list|count}}
Filters are applied in order left to right. You need to select all the entities that are on before mapping the entity id.
{{expand(state_attr('light.all_lights', 'entity_id'))| selectattr('state','eq','on')|map(attribute='entity_id')|list|count}}