So the problem is your light group has light groups and you do not want it to recursively expand is that the gist? Yes in that case you won’t be able to use expand in this spot anymore. expand
always recursively expanded group
entities but did not recursively expand other types of groups (like light groups for example). Now all groups work the same with expand which is more consistent and less confusing but appears to be an issue for you.
I think your best solution here is now this:
{% set ns = namespace(on_lights=0) %}
{% for light in state_attr('group.all_lights', 'entity_id') if is_state(light, 'on') %}
{% set ns.on_lights = ns.on_lights + 1 %}
{% endfor %}
{{ ns.on_lights }}