Frigate motion detection - make a message template?

I have an automation set to warn us by phone notification (and turns on a light at home) if our indoor cameras detect a person while we are out.

My automation code is naive, and I feel sure that rather than all the repeated code I could simplify it and use a template to add the camera name as a variable, but I can’t work out how to achieve this.

Any help gratefully received.

Here is my code:

alias: Frigate Motion Detection Inside
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.lounge_person_occupancy
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 10
    id: Lounge Motion Detected
  - trigger: state
    entity_id:
      - binary_sensor.kitchen_person_occupancy
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 10
    id: Kitchen Motion Detected
  - trigger: state
    entity_id:
      - binary_sensor.office_person_occupancy
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 10
    id: Office Motion Detected
  - trigger: state
    entity_id:
      - binary_sensor.lounge_person_occupancy
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 30
    id: Lounge Motion Cleared
  - trigger: state
    entity_id:
      - binary_sensor.kitchen_person_occupancy
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 30
    id: Kitchen Motion Cleared
  - trigger: state
    entity_id:
      - binary_sensor.office_person_occupancy
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 30
    id: Office Motion Cleared
conditions:
  - condition: state
    state: "off"
    entity_id: input_boolean.someone_home
actions:
  - parallel:
      - choose:
          - conditions:
              - condition: trigger
                id:
                  - Lounge Motion Detected
                  - Kitchen Motion Detected
                  - Office Motion Detected
            sequence:
              - type: turn_on
                device_id: 2e9c07d975f9ad0e9fe72adb31f5630c
                entity_id: a3604aa3c5225fc269502782663f535d
                domain: light
                enabled: true
                brightness_pct: 100
          - conditions:
              - condition: trigger
                id:
                  - Lounge Motion Cleared
                  - Kitchen Motion Cleared
                  - Office Motion Cleared
            sequence:
              - type: turn_off
                device_id: 2e9c07d975f9ad0e9fe72adb31f5630c
                entity_id: a3604aa3c5225fc269502782663f535d
                domain: light
      - if:
          - condition: trigger
            id:
              - Lounge Motion Detected
        then:
          - parallel:
              - action: notify.mobile_app_phone_a
                data:
                  message: Person detected in living room
              - action: notify.mobile_app_phone_b
                data:
                  message: Person detected in living room
      - if:
          - condition: trigger
            id:
              - Kitchen Motion Detected
        then:
          - parallel:
              - action: notify.mobile_app_phone_a
                data:
                  message: Person detected in kitchen
              - action: notify.mobile_app_phone_b
                data:
                  message: Person detected in kitchen
      - if:
          - condition: trigger
            id:
              - Office Motion Detected
        then:
          - parallel:
              - action: notify.mobile_app_phone_a
                data:
                  message: Person detected in office
              - action: notify.mobile_app_phone_b
                data:
                  message: Person detected in office
mode: single

Have you consider grouping the sensors in Helpers so that any one sensor will act as all sensors?

If necessary, you could define the message based on the specific sensor triggered to know the area the motion was detected.

Thank you. That sounds like an option, but I’m not sure it would really simplify my code.

FWIW I tried the Frigate Notification Blueprint, but that simply will not work, no matter what I try. It never triggers.

Simplify your automation with one occupancy sensor as the trigger and one action. Expand further if that is successful. Your occupancy timeouts may not exceed your conditions.

Waiting for 10 seconds in case an intruder is detected in each of the 3 rooms, isn’t it a bit too long? With that long time an intruder who just sneaks through to reach a room with no motion sensor might successfully pass without notice :thinking:

Thanks all. 10 seconds is fine for this purpose.

If I received a notification I would want to know which camera triggered it.

I may put my efforts into why the Blueprint doesn’t work for me. That would appear to cover everything I might need. Why it flatly refuses to trigger is the mystery.

HA records what happens so it’s not really a mystery if you trace the error.

No error to trace. Just an automation that didn’t trigger.

However, I got the Blueprint working - and I have no idea how. I didn’t make any changes, but suddenly it’s working. All I now need to figure out is why for some cameras I can see the recording, but for others I just get a play button with a line through it.

So this topic is kind of solved - by abandoning my code in favour of the blueprint.