Template to find entities without a label

I can do the following to find a switch that is on:

{{ states.switch
    | selectattr('entity_id', 'search', 'smartplug')
    | selectattr('state','equalto','on')
    | list
    | length
}}

And I can do this to find switches with a given label and state:

{{
  label_entities('normally off')
    | select('is_state', 'on') 
    | select('match', 'switch.*smartplug')
    | list
    | length
}}

...but how can I find a switch without any label at all?

[edit: typos]

{% set labeled = labels() | map("label_entities") | flatten | unique | list %}
{{ states.switch | map(attribute='entity_id') | reject('in', labeled) | list }}
1 Like

Brilliant - thanks!

flatten and unique are new to me. ...so much more to learn!