Frigate Mobile App Notifications 2.0

No no events are recorded, only in debug mode do I see some squares happening sometimes. I have also required_zones set and

detect:
  stationary:
    interval: 0
    threshold: 50
    max_frames:
      objects:
        car: 50
        person: 50

Every wind blow that moves the bushes triggers a notification, but no recording.

I don’t have an exact answer but I’d suggest putting a zone for cars that does not include the closest part of the normal car parking location. Frigate looks at object zones only based on the bottom of the object box. If the car when parked is not in the car zone, it shouldn’t cause issues.

You can use the disable times option also

The problem if I at home I got - not critical notification between 7AM-12AM why?
I cannot figure out the problem

alias: In Home - Someone enter to dangerzone (00-06 Critical)
description: ""
trigger:
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: silence-{{ camera }}
    id: silence
  - platform: mqtt
    topic: frigate/events
    payload: "{{ camera }}/new"
    value_template: "{{ value_json['after']['camera'] | lower }}/{{ value_json['type']}}"
    id: frigate-event
condition: []
action:
  - choose:
      - alias: Silence New Object Notifications
        conditions:
          - condition: trigger
            id: silence
        sequence:
          - service: automation.turn_off
            target:
              entity_id: "{{ this.entity_id }}"
            data:
              stop_actions: false
          - delay:
              minutes: 60
          - service: automation.turn_on
            target:
              entity_id: "{{ this.entity_id }}"
      - alias: Frigate Event
        conditions:
          - condition: trigger
            id: frigate-event
          - "{{ is_state(this.entity_id, 'on') }}"
          - >-
            {{ not this.attributes.last_triggered or (now() -
            this.attributes.last_triggered).seconds > cooldown }}
          - "{{ not disable_times|length or not now().hour in disable_times }}"
        sequence:
          - variables:
              id: "{{ trigger.payload_json['after']['id'] }}"
              object: "{{ trigger.payload_json['after']['label'] }}"
              label: "{{ object | title }}"
              initial_home: >-
                {{ presence_entity != '' and is_state(presence_entity,
                'not_home') }}
              initial_entered_zones: "{{ trigger.payload_json['after']['entered_zones'] }}"
              message: A {{ label }} was detected on the {{ camera_name }} camera.
              button_1: View Clip
              button_2: View Snapshot
              button_3: Silence New Notifications
              custom_url: "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
              icon:
                - mdi:home-assistant
          - alias: Notifications enabled for object label
            condition: template
            value_template: "{{ not labels|length or object in labels }}"
          - alias: Notify on new object
            choose:
              - conditions:
                  - >-
                    {{ not zone_only or zones|select('in',
                    initial_entered_zones)|list|length > 0  }}
                  - "{{ not initial_home }}"
                  - >-
                    {{ not state_only or states(input_entity) in states_filter
                    }}
                sequence:
                  - choose:
                      - conditions: "{{ not group_target }}"
                        sequence:
                          - device_id: 83073481c067b87f9df240bc8e2c1d15
                            domain: mobile_app
                            type: notify
                            message: "{{message}}"
                            data:
                              tag: "{{ id }}"
                              group: "{{ camera }}-frigate-notification"
                              image: >-
                                /api/frigate/notifications/{{id}}/thumbnail.jpg?format=android
                              clickAction: >-
                                {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                              ttl: "{{ iif(critical, 0, 3600000) }}"
                              priority: "{{ iif(critical, 'high', 'normal') }}"
                              notification_icon: "{{icon}}"
                              url: >-
                                {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                              attachment:
                                url: >-
                                  /api/frigate/notifications/{{id}}/thumbnail.jpg
                              push:
                                sound: "{{sound}}"
                                interruption-level: "{{ iif(critical, 'critical', 'active') }}"
                              actions:
                                - action: URI
                                  title: "{{button_1}}"
                                  uri: >-
                                    {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                                - action: URI
                                  title: "{{button_2}}"
                                  uri: "{{custom_url}}"
                                - action: silence-{{ camera }}
                                  title: "{{button_3}}"
                                  destructive: true
                    default:
                      - service: notify.{{ group_target }}
                        data:
                          message: "{{message}}"
                          data:
                            tag: "{{ id }}"
                            group: "{{ camera }}-frigate-notification"
                            image: >-
                              /api/frigate/notifications/{{id}}/thumbnail.jpg?format=android
                            clickAction: >-
                              {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                            ttl: "{{ iif(critical, 0, 3600000) }}"
                            priority: "{{ iif(critical, 'high', 'normal') }}"
                            notification_icon: "{{icon}}"
                            url: >-
                              {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                            attachment:
                              url: /api/frigate/notifications/{{id}}/thumbnail.jpg
                            push:
                              sound: "{{sound}}"
                              interruption-level: "{{ iif(critical, 'critical', 'active') }}"
                            actions:
                              - action: URI
                                title: "{{button_1}}"
                                uri: >-
                                  {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                              - action: URI
                                title: "{{button_2}}"
                                uri: "{{custom_url}}"
                              - action: silence-{{ camera }}
                                title: "{{button_3}}"
                                destructive: true
          - repeat:
              sequence:
                - wait_for_trigger:
                    - platform: mqtt
                      topic: frigate/events
                      payload: "{{ id }}"
                      value_template: "{{ value_json['after']['id'] }}"
                  timeout:
                    minutes: 2
                  continue_on_timeout: false
                - variables:
                    event: "{{ wait.trigger.payload_json }}"
                    loitering: >-
                      {{ loiter_timer and
                      event['before']['motionless_count']/fps/60 < loiter_timer
                      and event['after']['motionless_count']/fps/60 >=
                      loiter_timer }}
                    new_snapshot: >-
                      {{ update_thumbnail and event['before']['snapshot_time']
                      != event['after']['snapshot_time'] }}
                    home: >-
                      {{ presence_entity != '' and is_state(presence_entity,
                      'not_home') }}
                    presence_changed: >-
                      {{ presence_entity != '' and
                      as_datetime(event['before']['frame_time']) <
                      states[presence_entity].last_changed }}
                    last_zones: "{{ event['before']['entered_zones'] }}"
                    entered_zones: "{{ event['after']['entered_zones'] }}"
                    zone_filter: >-
                      {{ not zone_only or zones|select('in',
                      entered_zones)|list|length > 0 }}
                    stationary_moved: >-
                      {{ event['after']['position_changes'] >
                      event['before']['position_changes'] }}
                    zone_only_changed: >-
                      {{ zone_only and (entered_zones|length > 0 and not
                      last_zones|length) }}
                    entered_zones_changed: >-
                      {{ zones|length > 0 and (zones|select('in',
                      entered_zones)|list|length > 0 and not zones|select('in',
                      last_zones)|list|length) }}
                    state_true: >-
                      {{ not state_only or states(input_entity) in states_filter
                      }}
                    update: >-
                      {{ alert_once or (new_snapshot and not loitering and not
                      presence_changed and not zone_only_changed and not
                      entered_zones_changed) }}
                - alias: Notify on loitering or significant change
                  choose:
                    - conditions: >-
                        {{ loitering or (not home and zone_filter and state_true
                        and (new_snapshot or presence_changed or
                        stationary_moved or zone_only_changed or
                        entered_zones_changed)) }}
                      sequence:
                        - choose:
                            - conditions: "{{ not group_target }}"
                              sequence:
                                - device_id: 83073481c067b87f9df240bc8e2c1d15
                                  domain: mobile_app
                                  type: notify
                                  message: "{{message}}"
                                  data:
                                    tag: "{{ id }}{{'-loitering' if loitering}}"
                                    group: >-
                                      {{ camera
                                      }}-frigate-notification{{'-loitering' if
                                      loitering}}
                                    image: >-
                                      /api/frigate/notifications/{{id}}/thumbnail.jpg?format=android
                                    clickAction: >-
                                      {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                                    ttl: "{{ iif(critical, 0, 3600000) }}"
                                    priority: "{{ iif(critical, 'high', 'normal') }}"
                                    alert_once: "{{ alert_once }}"
                                    notification_icon: "{{icon}}"
                                    url: >-
                                      {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                                    attachment:
                                      url: >-
                                        /api/frigate/notifications/{{id}}/thumbnail.jpg
                                    push:
                                      sound:
                                        name: "{{ iif(update, 'none', sound) }}"
                                      interruption-level: >-
                                        {{ iif(critical, 'critical', 'active')
                                        }}
                                    actions:
                                      - action: URI
                                        title: "{{button_1}}"
                                        uri: >-
                                          {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                                      - action: URI
                                        title: "{{button_2}}"
                                        uri: "{{custom_url}}"
                                      - action: silence-{{ camera }}
                                        title: "{{button_3}}"
                                        destructive: true
                          default:
                            - service: notify.{{ group_target }}
                              data:
                                message: "{{message}}"
                                data:
                                  tag: "{{ id }}{{'-loitering' if loitering}}"
                                  group: >-
                                    {{ camera
                                    }}-frigate-notification{{'-loitering' if
                                    loitering}}
                                  image: >-
                                    /api/frigate/notifications/{{id}}/thumbnail.jpg?format=android
                                  clickAction: >-
                                    {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                                  ttl: "{{ iif(critical, 0, 3600000) }}"
                                  priority: "{{ iif(critical, 'high', 'normal') }}"
                                  alert_once: "{{ alert_once }}"
                                  notification_icon: "{{icon}}"
                                  url: >-
                                    {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                                  attachment:
                                    url: >-
                                      /api/frigate/notifications/{{id}}/thumbnail.jpg
                                  push:
                                    sound:
                                      name: "{{ iif(update, 'none', sound) }}"
                                    interruption-level: "{{ iif(critical, 'critical', 'active') }}"
                                  actions:
                                    - action: URI
                                      title: "{{button_1}}"
                                      uri: >-
                                        {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
                                    - action: URI
                                      title: "{{button_2}}"
                                      uri: "{{custom_url}}"
                                    - action: silence-{{ camera }}
                                      title: "{{button_3}}"
                                      destructive: true
              until: >-
                {{ not wait.trigger or wait.trigger.payload_json['type'] ==
                'end' }}
mode: parallel
trigger_variables:
  input_camera: camera.gardentwo
  camera: "{{ input_camera | replace('camera.', '') }}"
variables:
  input_camera: camera.gardentwo
  camera: "{{ input_camera | replace('camera.', '') }}"
  camera_name: "{{ camera | replace('_', ' ') | title }}"
  base_url: https://abc.com:8123
  critical_input: >-
    {{'false' if now().hour in
    [7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0] else 'true'}}
  critical: "{{true if critical_input == 'true' else false}}"
  alert_once: true
  update_thumbnail: true
  group_target: ""
  zone_only: true
  input_zones:
    - zone_danger
  zones: "{{ input_zones | list }}"
  input_labels:
    - person
    - cat
    - dog
  labels: "{{ input_labels | list }}"
  presence_entity: device_tracker.testiphonetest
  disable_times: []
  cooldown: 150
  loiter_timer: 150
  fps: "{{ states('sensor.' + camera + '_camera_fps')|int(5) }}"
  state_only: false
  input_entity: ""
  input_states: []
  states_filter: "{{ input_states | list }}"
  sound: default

I had an issue with the _2 name on my camera, rename the camera to living instead of living_2 and now the notifications are working! Thanks SgtBatten!

1 Like

Hello, I have a question about the “Base URL”. My current setup is I have the cloudFlared for remote access. I believe that means I will need to add the cloudFlared domain in the Base URL section. When I do that, clicking the “view clip” button will bring me to the url https://mydomain.com/api/frigate/notification/some_numbers/camera_name/clip.mp4. I noticed this url can be accessed anywhere without login (I can see the clip in the incognito window). My concern is if this is going to become a security/privacy issue?

correct. this is what the frigate notification api gives us. The event id is different for every event and provides some obfuscation. You can set an expiry time in the configuration of the frigate integration also.

1 Like

you can use the time filter to prevent notifications at any time.

One issue I have identified with this update btw. Although the Live View entity selection lets you have the iPhone real-time stream work well, this now causes an issue on the Apple Watch alert (video animation doesnt appear anymore). For the apple watch, it works with the frigate camera entity, but not the MJPEG generic camera entity, however this setup doesn’t work on the iphone, since the iPhone requires the MJPEG generic camera entity.

What should a group target look like? I created a YAML notify group, like this:

But it doesn’t seem to be working.

In that example where it has name: "My notification group"

There are two options. Either My notification group or notify.my_notification_group

Capitalisation and spaces instead of underscores do not matter

1 Like

I have setup everything as per instructions in Hassio. Frigate is working and creating events. MQTT is getting messages from Frigate. The only problems seems to be frigate/events is not getting any messages. I get frigate/camera name message, frigate/stats and so on. I have check logs and all seems ok. Any suggestions on where I should look to solve the problem. I am keen to get this automation firing.

this seems somewhat contradictory? Can you share the mqtt portion of your frigate config?

Yes it does sound contradictory. Thanks for your help.

mqtt: host: 192.168.1.5 user: MQTT password: password port: 1883

Sorry.

mqtt:
host: 192.168.1.5
user: MQTT
password: password
port: 1883

3rd time lucky
image

thanks, by the sound of it that is working fine. is home assistant also connected to the same mqtt server?

I am runing mosquitto from Integrations within Hassio. So I assume so.

Thanks for your help. For some reason after several days I have received some messages to events. Let me keep investiggating.

if you go and trigger your camera you should see events in real time.