How to shorten this condition_template?

continuing from this thread,
how could this automations condition_template be shortened? Ive tried to use a list, but cant get the filter correct…:

- alias: 'Call state change event (all)'
  id: 'Call state change event (all)'
#  hide_entity: True
#  initial_state: 'on'
  trigger:
    platform: event
    event_type: state_changed
  condition:
    - condition: template
      value_template: >
        {{ trigger.event.data.entity_id in state_attr('group.family','entity_id') or
           trigger.event.data.entity_id in state_attr('group.hubs_binary_pinged','entity_id') or
           trigger.event.data.entity_id in state_attr('group.critical_devices_state','entity_id') or
           trigger.event.data.entity_id in state_attr('group.media_player_media','entity_id') or
           trigger.event.data.entity_id in state_attr('group.device_tracker_media','entity_id') or
           trigger.event.data.entity_id in state_attr('group.all_lights_only','entity_id') or
           trigger.event.data.entity_id in state_attr('group.iungo_switch_switches_template','entity_id') or
           trigger.event.data.entity_id in state_attr('group.iungo_switch_appliances_template','entity_id') or
           trigger.event.data.entity_id in state_attr('group.binary_sensors_active_template','entity_id') }}
  action:
    service: python_script.summary

please check with me, thx,
Marius

You’re always good for a challenge! :slight_smile:

How about this:

    - condition: template
      value_template: >
        {% for x in
             ['family',
              'hubs_binary_pinged',
              'critical_devices_state',
              'media_player_media',
              'device_tracker_media',
              'all_lights_only',
              'iungo_switch_switches_template',
              'iungo_switch_appliances_template',
              'binary_sensors_active_template']
           if trigger.event.data.entity_id in state_attr('group.'+x,'entity_id') %}
          true
        {% else %}
          false
        {% endfor %}
1 Like

magic. a for loop…
Had the same (or at least almost…) list, but forgot about the for loop.
Thanx!
you’re always good for templating magic :wink: