Frigate Mobile App Notifications

Im afraid not, just having another play with it now, have already removed and re-added the blueprint… And tried setting the base url… And tried changing the click actions… No joy as yet, will keep reading.

search for a spin off created by toddrob99. Let me know if you can’t find it. it worked for me.

So, in addition to the above. I’ve also tried swapping out all the paths (not just the clip.mp4 ones) such as {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
to
{{base_url}}/api/events/{{id}}/clip.mp4

I’ve then restarted and still the same error. So I’ve cleared the log and walked in front of the camera and I pick this event up:

Logger: homeassistant.components.automation.gate_door_station_frigate_notification_0_10_0
Source: components/automation/__init__.py:470 
Integration: Automation (documentation, issues) 
First occurred: 21:02:52 (1 occurrences) 
Last logged: 21:02:52

Error rendering variables: ValueError: Template error: int got invalid input 'unknown' when rendering template '{{ fps_value|int if is_number(fps_value) or 5 }}' but no default was specified

This appears to come from these lines in the blueprint:

  fps_value: '{{ states(''sensor.'' + camera + ''_camera_fps'') }}'
  fps: '{{ fps_value|int if is_number(fps_value) or 5 }}'

At this point, I tried checking for the sensor name using the DevTools, and discovered that my camera name "Dining-Internal’ isn’t there, because the hyphen has been changed to an underscore. The sensor name is in fact sensor.dining_internal_camera_fps.

So if you see the DevTools screenshot below, that code produces the same error as seen in the log:

But if I change the camera name to replace the hyphen with underscore…

So it seems that underscores in the camera name cannot be tolerated by this blueprint. Some people might say, don’t use hyphens in the camera names, use underscores, but I have hyphens in the camera names because DNS doesn’t support underscores, only hyphens!

Since all my cameras bar 1 have hyphens in the name, I was going to have to change the automation to work on PondCam! However, creating detection on this cam at this time of night was going to be awkward… But to entice the fish, I went out and threw some food near the underwater camera to see if they would come up…

And voila… After waiting about 20 minutes, Frigate finally detected a fish (person) and I received a notification along with the URL / thumbnail / video link etc as expected!!!

So since I don’t want to rename all my cameras, I’ve looked at the template code and in particular the variables section around line 159 that is setting the camera_fps variable and added extra code in there to replace hyphens in the camera name with underscores as follows

  fps_value: '{{ states(''sensor.'' + camera | replace(''-'',''_'') + ''_camera_fps'') }}'

There are a number of other references to the “camera” variable in the blueprint around the groups and actions and I did think about updating the camera variable to perform a replace on the hyphens but I have left alone for now (as I’m not familiar with automations, yaml or python)! I can also see a reference in the MQTT section and this is working with hyphens so needs to be left as is for sure.

One other little amendment that could be made to the blueprint is that there is a variable called camera_name which replaces underscores with blank spaces and formats them with capitalised first letters, presumably for presentation. This doesn’t tidy up hyphens, but it may be that people don’t want this, I’m not too fussed about it either way so have left alone for the minute.

I have the updated blueprint file (which includes all the URL changes too). I suspect there is a way to add this on GitHub or something, so maybe I’ll workout how to do my first commit to the original repo (only ever used SVN)!

Maybe this is the answer to the people that had the same error as me, as many people are using this without issue, I’m guessing only a few of us have hyphens in our camera names!

Hope this helps!

I’ve been banging my head against the wall for literal weeks. This fixed it so I get notifications again… Not all heroes wear capes!

1 Like

Hi, did you manage to get an answer to this? Thanks.

I found an open issue that describes this problem here: Unable to connect to Home Assistant error when playing video opened from notification · Issue #2684 · home-assistant/android · GitHub

Hopefully a fix can be found :slightly_smiling_face:

Hi,

I was having the same issue. My notifications stopped working and gave me the same “null” reason.

Today I noticed in Developer Tools-States that there are duplicate states. For instance I have a camera called north. I discovered that the binary_sensor.north_car_motion was unavailable. However right below it was binary_sensor.north_car_motion_2 and it was responding correctly.

I went through the list for all the cameras and deleted the unavailable sensors. Then I renamed the _2 sensors by just deleting the _2. Now my notifications are working just as they had in the past.

Hope this helps someone.

Edit: I also just found some other unavailable items under camera.(cameraname)

Hi, I think i’ve determined the cause. Do you have “update thumbnail” enbled?

I’ve discovered that with this enabled it bypasses all other filters. I think I have a fix though and have edited my post with the full blueprint from above

@hunterjm

Hi mate.

In playing with my state filter additions I believe I have found a bug. I will try to refer to only your original 0.10 gist. I believe new snapshots can cause the zone filter to be bypassed incorrectly.

This section below starts at line 285

                  zone_filter: "{{ not zone_only or entered_zones|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) }}"
                  update: "{{ 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 (new_snapshot or presence_changed or stationary_moved or zone_only_changed or entered_zones_changed)) }}"
                   

zone_filter is true simply by having the toggle enabled and any item in the associated list.
Due to the conditions (last line above) a new snapshot can trigger an update without zone_only_changed or entered_zones_changed actually changing.

It is resulting in traces like this were the initial notification is not sent because the zone filter is correctly applied however subsequent snapshot updates to result in a notification dspite the required zones never being entered.

my proposal is to edit the zone_filter line from:

                    zone_filter: "{{ not zone_only or entered_zones|length > 0 }}"

to

                    zone_filter: "{{ not zone_only or entered_zones|length > 0 and zones|select('in', entered_zones)|list|length > 0 }}"

This should cause the condition to remain false unless a required zone has been entered unless i am misunderstanding something.

1 Like

Just setup the newest iteration of this blueprint last night but it’s 100% not working. Running Frigate 3.1 (v0.10.0) so used the template for the same version as well.

Tried a few different conditions at first (objects, updated snapshot etc) but couldn’t get the automation to trigger. Removed all optional conditions and it’s still not working. Saw the comment about hyphens being at fault so renamed my cameras using underscores and without anything at all instead. Still not getting a single notification.

Anyone got any ideas?

I am using the blueprint without issues and my modified one also which is largely similar but with a few extra features without issue.

My guess is your trigger entity has an _2 or similar at the end as someone else experienced 3 posts up.

Just checked to be double sure. I don’t have any trigger entity set manually, only using whatever is in the blueprint.

Camera name: “front-door”
Entities are all set as sensor.front_door_person/cat/dog (without any trailing _2 or similar). For the binary_sensors it’s the same thing - no trailing _2 or anything.

Doesn’t seem to be an issue with entity names or anything.

Is it the underscore vs hyphen issue still?

Post the yaml of the automation, might reveal something.

Can’t figure out how to view the full automation w/ the substitutions but here’s the YAML for my bit of it.

description: ""
use_blueprint:
  path: hunterjm/frigate_0.10_notification.yaml
  input:
    notify_device: d16ccfb0a313773c14360c7657772961
    update_thumbnail: true
    camera: front-door

And the actual blueprint…

blueprint:
  name: Frigate Notification (0.10.0)
  description: "## Frigate Mobile App Notification\n\nThis blueprint will send a notification
    to your device when a Frigate event for the selected camera is fired. The notification
    will initially include the thumbnail of the detection, but include an actionable
    notification allowing you to view the clip and snapshot.\n\nWith this blueprint,
    you may send the notification to multiple devices by leaving \"Device\" blank
    and instead use a [notification group][1].\n\n### Software Version Requirements\nMinimum
    Home Assistant Version: 2022.2\nMinimum Frigate Version: 0.10.0 Beta 10\nMinimum
    Frigate Integration Version: 2.2.0\nMinimum iOS Version: 15.0\n\n### Required
    entities:\n  - Frigate Camera Name\n  - Mobile App Device **or** the name of a
    Notification Group\n\n### Optional features:\n  - You can optionally send the
    notification as a critical alert.\n  - You can choose whether or not to update
    the notification with new thumbnails as they become available.\n  - You can limit
    notifications to objects entering pre-defined [zones][2] in Frigate.\n  - You
    can specify which [zones][2] to be notified about. This must be a list (e.g.):\n
    \   ```yaml\n    - backyard\n    ```\n  - You can specify what type of [objects][3]
    to be notified about. This must be a list (e.g.):\n    ```yaml\n    - person\n
    \   - car\n    ```\n  - You can disable notifications if a presence entity or
    group is \"home\".\n  - You can configure a cooldown for the camera to reduce
    the number of notifications when back-to-back events occur.\n  - You can silence
    future notifications for a defined amount of time through actionable notifications.
    This is helpful in situations where you know you will be triggering detections
    for an extended period of time. i.e. kids playing outside.\n  - You can set a
    loitering timer to notify you of stationary objects that remain for a set period
    of time.\n\n[1]: https://companion.home-assistant.io/docs/notifications/notifications-basic#sending-notifications-to-multiple-devices\n[2]:
    https://blakeblackshear.github.io/frigate/configuration/cameras#zones\n[3]: https://blakeblackshear.github.io/frigate/configuration/objects\n"
  domain: automation
  source_url: https://gist.github.com/hunterjm/8ff0005104dce3f28923294f49a443b1
  input:
    camera:
      name: Frigate Camera
      description: The name of the camera as defined in your frigate configuration.
    notify_device:
      name: Device
      description: The device must run the official Home Assistant app to receive
        notifications.
      default: false
      selector:
        device:
          integration: mobile_app
          multiple: false
    notify_group:
      name: Notification Group
      description: The name of the notification group to call.
      default: ''
    base_url:
      name: (Optional) Base URL
      description: 'The external url for your Home Assistant instance. This will default
        to a relative URL and will open the clips in the app instead of the browser,
        which does not work well on iOS.

        '
      default: ''
    critical:
      name: (Optional) Critical Notification
      description: Send as a critical notification to the mobile device.
      default: false
      selector:
        boolean: {}
    update_thumbnail:
      name: (Optional) Update Thumbnail
      description: Update notification if a new "better" thumbnail is available.
      default: false
      selector:
        boolean: {}
    zone_filter:
      name: (Optional) Zone Filter
      description: Only notify if object has entered a defined zone.
      default: false
      selector:
        boolean: {}
    zones:
      name: (Optional) Trigger Zones
      description: A list (-) of zones you wish to recieve notifications for.
      default: []
      selector:
        object: {}
    labels:
      name: (Optional) Trigger Objects
      description: A list (-) of objects you wish to recieve notifications for.
      default: []
      selector:
        object: {}
    presence_filter:
      name: (Optional) Presence Filter
      description: Only notify if selected presence entity is not "home".
      default: ''
      selector:
        entity: {}
    cooldown:
      name: (Optional) Cooldown
      description: Delay before sending another notification for this camera after
        the last event.
      default: 30
      selector:
        number:
          max: 300.0
          min: 0.0
          unit_of_measurement: seconds
          step: 1.0
          mode: slider
    silence_timer:
      name: (Optional) Silence New Object Notifications
      description: "How long to silence notifications for this camera when requested
        as part of the actionable notification. Note: This only applies to new objects.
        Existing tracked objects \n"
      default: 30
      selector:
        number:
          max: 300.0
          min: 0.0
          unit_of_measurement: minutes
          step: 1.0
          mode: slider
    loiter_timer:
      name: (Optional) Loitering Notifications
      description: 'Sends new loitering notification if a stationary object is detected
        for longer than the specified time. 0 is off and will not send notifications.

        '
      default: 0
      selector:
        number:
          max: 300.0
          min: 0.0
          unit_of_measurement: minutes
          step: 1.0
          mode: slider
mode: parallel
trigger_variables:
  camera: !input camera
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''] }}/{{ value_json[''type'']}}'
  id: frigate-event
variables:
  camera: !input camera
  camera_name: '{{ camera | replace(''_'', '' '') | title }}'
  base_url: !input base_url
  critical: !input critical
  update_thumbnail: !input update_thumbnail
  group_target: !input notify_group
  zone_only: !input zone_filter
  input_zones: !input zones
  zones: '{{ input_zones | list }}'
  input_labels: !input labels
  labels: '{{ input_labels | list }}'
  presence_entity: !input presence_filter
  cooldown: !input cooldown
  loiter_timer: !input loiter_timer
  fps_value: '{{ states(''sensor.'' + camera + ''_camera_fps'') }}'
  fps: '{{ fps_value|int if is_number(fps_value) or 5 }}'
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: !input silence_timer
    - 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 }}'
    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, ''home'')
          }}'
        initial_entered_zones: '{{ trigger.payload_json[''after''][''entered_zones'']
          }}'
    - 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 initial_entered_zones|length > 0 }}'
        - '{{ not zones|length or zones|select(''in'', initial_entered_zones)|list|length
          > 0 }}'
        - '{{ not initial_home }}'
        sequence:
        - choose:
          - conditions: '{{ not group_target }}'
            sequence:
            - device_id: !input notify_device
              domain: mobile_app
              type: notify
              message: A {{ label }} was detected on the {{ camera_name }} camera.
              data:
                tag: '{{ id }}'
                group: frigate-notification-{{ camera }}
                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'') }}'
                url: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
                attachment:
                  url: /api/frigate/notifications/{{id}}/thumbnail.jpg
                push:
                  interruption-level: '{{ iif(critical, ''critical'', ''active'')
                    }}'
                actions:
                - action: URI
                  title: View Clip
                  uri: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
                - action: URI
                  title: View Snapshot
                  uri: '{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg'
                - action: silence-{{ camera }}
                  title: Silence New Notifications
                  destructive: true
          default:
          - service: notify.{{ group_target }}
            data:
              message: A {{ label }} was detected on the {{ camera_name }} camera.
              data:
                tag: '{{ id }}'
                group: frigate-notification-{{ camera }}
                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'') }}'
                url: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
                attachment:
                  url: /api/frigate/notifications/{{id}}/thumbnail.jpg
                push:
                  interruption-level: '{{ iif(critical, ''critical'', ''active'')
                    }}'
                actions:
                - action: URI
                  title: View Clip
                  uri: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
                - action: URI
                  title: View Snapshot
                  uri: '{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg'
                - action: silence-{{ camera }}
                  title: Silence New Notifications
                  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, ''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 entered_zones|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)
              }}'
            update: '{{ 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 (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: !input notify_device
                  domain: mobile_app
                  type: notify
                  message: A {{ label }} {{ 'is loitering' if loitering else 'was
                    detected' }} on the {{ camera_name }} camera.
                  data:
                    tag: '{{ id }}{{''-loitering'' if loitering}}'
                    group: frigate-notification-{{ camera }}{{'-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'') }}'
                    url: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
                    attachment:
                      url: /api/frigate/notifications/{{id}}/thumbnail.jpg
                    sound: '{{ iif(update, ''none'', ''default'') }}'
                    push:
                      interruption-level: '{{ iif(critical, ''critical'', ''active'')
                        }}'
                    actions:
                    - action: URI
                      title: View Clip
                      uri: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
                    - action: URI
                      title: View Snapshot
                      uri: '{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg'
                    - action: silence-{{ camera }}
                      title: Silence New Notifications
                      destructive: true
              default:
              - service: notify.{{ group_target }}
                data:
                  message: A {{ label }} {{ 'is loitering' if loitering else 'was
                    detected' }} on the {{ camera_name }} camera.
                  data:
                    tag: '{{ id }}{{''-loitering'' if loitering}}'
                    group: frigate-notification-{{ camera }}{{'-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'') }}'
                    url: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
                    attachment:
                      url: /api/frigate/notifications/{{id}}/thumbnail.jpg
                    sound: '{{ iif(update, ''none'', ''default'') }}'
                    push:
                      interruption-level: '{{ iif(critical, ''critical'', ''active'')
                        }}'
                    actions:
                    - action: URI
                      title: View Clip
                      uri: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
                    - action: URI
                      title: View Snapshot
                      uri: '{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg'
                    - action: silence-{{ camera }}
                      title: Silence New Notifications
                      destructive: true
        until: '{{ not wait.trigger or wait.trigger.payload_json[''type''] == ''end''
          }}'

You mentioned you tried using underscores and also without underscores but your automation still uses hyphens. Did you update the automation for testing?

I would try using frontdoor.

Also what do the traces look like? Nothing triggering at all? Are your mqtt topics setup properly?

Hi,
thanks a lot for your reply and support!
It is correct, I am using the update thumbnail feature.
I have now re-enabled all my automation after upgrading the Blueprint, and it seems that everything is working fine now!

Found the issue. The camera entity created by Frigate had the _2 attached to it. I’d checked the sensor and binary sensor entities but not the camera entities. Working fine now!

Notification - ios 16
I’ve tried everything I can think of… but no matter what I cannot get the blueprint automation to send me a notification.
If I run actions… nothing
if I walk past camera… nothing.

frigate does register that I walk past… but the automation does not trigger.

yaml is:

alias: test - frigate simple
description: ""
use_blueprint:
  path: hunterjm/frigate_0.10_notification.yaml
  input:
    camera: Carport
    notify_device: 4cd07a06e55a8f9322d55e0686073fd5

Only thing I can think of is that the notify_device is wrong… but I selected the correct device… but I cannot verify that the 4cd07… is the right ID.
If I go to the mobile app integration and find my phone - it shows the frigate automation - so it IS the right device.

Any thoughts on how I can solve it?

Go to settings, entities and search for camera.carport, does it exist exactly like that?
If not, what is it called?

If yes, paste a trace from the automation after you trigger the motion.

hi… tried one where I changed the ‘Carport’ to ‘carport’.
then I got a notification.

so am i right that … if I ONLY run actions… nothing will happen? All automations I’ve tried can trigger the notification without the actual trigger… but not this one?