WTH Notify only devices at home requires a lot of code

While I would love to see this be easier to set up for new users, it is possible to reduce that automation considerably. The crux may be related to the fact that Zones track person enties but person has no relationship with notification device.

action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.json.event == \"incoming_call\" }}"
        sequence:
          - repeat:
              for_each: >
                {{ expand('device_tracker.mobile_app_anja_handy_moto_g8',
                'device_tracker.mobile_app_oneplus_a6003', 'device_tracker.mobile_app_jannes_handy',
                'device_tracker.mobile_app_pia_moto_g_30') | selectattr('state', 'eq', 'home') 
                | map(attribute='entity_id') | list }}
              sequence:
                - service: notify.{{ (repeat.item).rsplit('.')[1] }}
                  data:
                    title: Door Ring
                    message: Ring ring!
                    data:
                      notification_icon: mdi:lock-open-variant
                      tag: door-ring-detected
                      timeout: 60
                      actions:
                        - action: OPEN_DOOR
                          title: Open door

EDIT: Removed extraneous mobile_app pointed out by TheFes

1 Like