How to identify the enity with state on in a list of entities

hello

I have a list of entities starting with the same name.
at one time, I know that one of them is on and the other are off
how to identify it in one query ?

{{ states.switch | selectattr('state','in',['on']) | map(attribute='entity_id')  | list }}

['switch.adguard_parental_control', 'switch.adguard_safe_browsing', 'switch.adguard_safe_search', 'switch.bureau_switch', 'switch.camille_switch', 'switch.cuisine_channel_1', 'switch.cuisine_switch', 'switch.diane_switch', 'switch.espresense_bureau_arduino_ota', 'switch.espresense_bureau_auto_update', 'switch.espresense_bureau_prerelease', 'switch.espresense_cuisine_status_led', 'switch.espresense_diane_arduino_ota', 'switch.espresense_diane_auto_update', 'switch.espresense_diane_prerelease', 'switch.espresense_entree_arduino_ota', 'switch.espresense_entree_auto_update', 'switch.espresense_entree_prerelease', 'switch.espresense_parents_arduino_ota', 'switch.espresense_parents_auto_update', 'switch.espresense_parents_prerelease', 'switch.espresense_salon_active_scan', 'switch.espresense_salon_status_led', 'switch.guirlande_switch', 'switch.parents_general', 'switch.parents_switch', 'switch.salon_switch', 'switch.salonbis_switch', 'switch.sdb_switch', 'switch.vaisselle_power', 'switch.vaisselle_program_auto1', 'switch.vaisselle_program_auto2', 'switch.vaisselle_program_auto3', 'switch.vaisselle_program_autohalfload', 'switch.vaisselle_program_eco50', 'switch.vaisselle_program_expresssparkle65', 'switch.vaisselle_program_glas40', 'switch.vaisselle_program_glasscare', 'switch.vaisselle_program_intensiv45', 'switch.vaisselle_program_intensiv70', 'switch.vaisselle_program_intensivpower', 'switch.vaisselle_program_kurz60', 'switch.vaisselle_program_machinecare', 'switch.vaisselle_program_magicdaily', 'switch.vaisselle_program_maximumcleaning', 'switch.vaisselle_program_nightwash', 'switch.vaisselle_program_normal45', 'switch.vaisselle_program_normal65', 'switch.vaisselle_program_prerinse', 'switch.vaisselle_program_quick45', 'switch.vaisselle_program_quick65', 'switch.vaisselle_program_steamfresh', 'switch.vaisselle_program_super60']

i want to find the one starting with ‘vaisselle_program’ which is on
any help would be appreciated
best regards

You can use regex:

Also unless you are going to include more states this would be quicker than a list search:

| selectattr('state','eq','on')
1 Like