Clunky template sensor to list sensors using energy while switch is off

so I have these power sensors, all ending on _actueel, eg sensor.netwerk_dorm_actueel, and, for all these sensors, I also have a switch with the same name, except for the ending _actueel.

What I seek is a template that senses the state of these switches to be ‘off’, while their respective _actueel sensors dont report ‘0’ power usage.

This can happen because these are MQTT sensors that dont always report their states correctly, and have to be forced to re-report state.

Ive been fiddling with something like this:

{%- for s in states.sensor
if ('_actueel' in s.entity_id and
    states(s.entity_id) != '0' and
    states(s.entity_id.split('_actueel')[0]|replace('sensor','switch')) == 'off' )
             %}
{{s.entity_id}}{% if not loop.last %}, {% endif %}
{%- endfor %}

which returns the list of all _actueel sensors reporting their incorrect state.

It seems unnecessary clunky though, but I dont see how I can create a more elegant template just now…
other than maybe taking out the first line, since that already is contained in the last line with the replace() , automatically selecting the correct entity_id’s.

of course… I also need a template to count the number of these ‘off’ sensors, and use that for triggering an automation…

like this:

{%- set ns = namespace(not_off=[]) %}
{%- for s in states.sensor
  if (states(s.entity_id) != '0' and
      states(s.entity_id.split('_actueel')[0]|replace('sensor','switch')) 
        == 'off')%}
  {%- set ns.not_off = ns.not_off + [s] %}
{%- endfor %}
{{ns.not_off|count}}

please have a look if this can be improved?
thanks