Advertisement
drinfernoo

Frigate Notification Blueprint

Apr 30th, 2021
2,309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 8.64 KB | None | 0 0
  1. blueprint:
  2.   name: Frigate Notification
  3.   description: "## Frigate Mobile App Notification\n\nThis blueprint will send a notification\
  4.    \ to your device when a Frigate event for the selected\ncamera is fired. The notification\
  5.    \ will initially include the thumbnail of the detection, but\nwill update to include\
  6.    \ an actionable notification allowing you to view the saved clip when\navailable.\n\
  7.    \nWith this blueprint, you may send the notification to multiple devices by leaving\
  8.    \ \"Device\"\nblank and instead use a [notification group][1].\n\n### Required\
  9.    \ entities:\n  - Frigate Camera Name\n  - Mobile App Device **or** the name of\
  10.    \ a Notification Group\n\n### Optional features:\n  - You can limit notifications\
  11.    \ to objects entering pre-defined [zones][2] in Frigate.\n  - You can specify\
  12.    \ which [zones][2] to be notified about. This must be a list (e.g.):\n    ```yaml\n\
  13.    \    - backyard\n    ```\n  - You can specify what type of [objects][3] to be\
  14.    \ notified about. This must be a list (e.g.):\n    ```yaml\n    - person\n   \
  15.    \ - car\n    ```\n  - You can disable notifications if a presence entity or group\
  16.    \ is \"home\".\n  - You can configure a cooldown for the camera to reduce the\
  17.    \ number of notifications\n    when back-to-back events occur.\n  - You can silence\
  18.    \ future notifications for a defined amount of time through\n    actionable notifications.\
  19.    \ This is helpful in situations where you know you will\n    be triggering detections\
  20.    \ for an extended period of time. i.e. kids playing outside.\n\n[1]: https://companion.home-assistant.io/docs/notifications/notifications-basic#sending-notifications-to-multiple-devices\n\
  21.    [2]: https://blakeblackshear.github.io/frigate/configuration/cameras#zones\n[3]:\
  22.    \ https://blakeblackshear.github.io/frigate/configuration/objects\n"
  23.   domain: automation
  24.   source_url: https://gist.github.com/hunterjm/23c1588a9f2b8b9c2a62ffc364e17f8c
  25.   input:
  26.     camera:
  27.       name: Frigate Camera
  28.       description: The name of the camera as defined in your frigate configuration.
  29.     notify_device:
  30.       name: Device
  31.       description: The device must run the official Home Assistant app to receive
  32.         notifications.
  33.       default: false
  34.       selector:
  35.         device:
  36.           integration: mobile_app
  37.     notify_group:
  38.       name: Notification Group
  39.       description: The name of the notification group to call.
  40.       default: ''
  41.     zone_filter:
  42.       name: (Optional) Zone Filter
  43.       description: Only notify if object has entered a defined zone.
  44.       default: false
  45.       selector:
  46.         boolean: {}
  47.     zones:
  48.       name: (Optional) Trigger Zones
  49.       description: A list (-) of zones you wish to recieve notifications for.
  50.       default: []
  51.       selector:
  52.         object: {}
  53.     labels:
  54.       name: (Optional) Trigger Objects
  55.       description: A list (-) of objects you wish to recieve notifications for.
  56.       default: []
  57.       selector:
  58.         object: {}
  59.     presence_filter:
  60.       name: (Optional) Presence Filter
  61.       description: Only notify if selected presence entity is not "home".
  62.       default: ''
  63.       selector:
  64.         entity: {}
  65.     cooldown:
  66.       name: (Optional) Cooldown
  67.       description: Delay before sending another notification for this camera after
  68.         the last event.
  69.       default: 30
  70.       selector:
  71.         number:
  72.           max: 300.0
  73.           min: 0.0
  74.           unit_of_measurement: seconds
  75.           step: 1.0
  76.           mode: slider
  77.     silence_timer:
  78.       name: (Optional) Silence Notifications
  79.       description: 'How long to silence notifications for this camera when requested
  80.         as part of the actionable notification.
  81.  
  82.         '
  83.       default: 30
  84.       selector:
  85.         number:
  86.           max: 300.0
  87.           min: 0.0
  88.           unit_of_measurement: minutes
  89.           step: 1.0
  90.           mode: slider
  91.     base_url:
  92.       name: Base URL
  93.       description: (Optional) An Input Text with the base URL for notifications.
  94.       default: ''
  95.       selector:
  96.         entity:
  97.           domain: input_text
  98. mode: single
  99. max_exceeded: silent
  100. trigger:
  101.   platform: mqtt
  102.   topic: frigate/events
  103.   payload: !input 'camera'
  104.   value_template: '{{ value_json[''after''][''camera''] }}'
  105. variables:
  106.   id: '{{ trigger.payload_json[''after''][''id''] }}'
  107.   camera: '{{ trigger.payload_json[''after''][''camera''] }}'
  108.   camera_name: '{{ camera | replace(''_'', '' '') | title }}'
  109.   object: '{{ trigger.payload_json[''after''][''label''] }}'
  110.   label: '{{ object | title }}'
  111.   entered_zones: '{{ trigger.payload_json[''after''][''entered_zones''] }}'
  112.   type: '{{ trigger.payload_json[''type''] }}'
  113.   group_target: !input 'notify_group'
  114.   zone_only: !input 'zone_filter'
  115.   input_zones: !input 'zones'
  116.   zones: '{{ input_zones | list }}'
  117.   input_labels: !input 'labels'
  118.   labels: '{{ input_labels | list }}'
  119.   presence_entity: !input 'presence_filter'
  120.   base_url: !input 'base_url'
  121. condition:
  122. - '{{ type != ''end'' }}'
  123. - '{{ not zone_only or entered_zones|length > 0 }}'
  124. - '{{ not zones|length or zones|select(''in'', entered_zones)|list|length > 0 }}'
  125. - '{{ not labels|length or object in labels }}'
  126. - '{{ not presence_entity or not is_state(presence_entity, ''home'') }}'
  127. action:
  128. - choose:
  129.   - conditions: '{{ not group_target }}'
  130.     sequence:
  131.     - device_id: !input 'notify_device'
  132.       domain: mobile_app
  133.       type: notify
  134.       message: A {{ label }} is being detected on the {{ camera_name }} camera.
  135.       data:
  136.         tag: '{{ id }}'
  137.         group: frigate-notification-{{ camera }}
  138.         image: '{{ base_url }}/api/frigate/notifications/{{ id }}/thumbnail.jpg?format=android'
  139.         attachment:
  140.           url: '{{ base_url }}/api/frigate/notifications/{{ id }}/thumbnail.jpg'
  141.           content-type: jpeg
  142.   default:
  143.   - service: notify.{{ group_target }}
  144.     data:
  145.       message: A {{ label }} is being detected on the {{ camera_name }} camera.
  146.       data:
  147.         tag: '{{ id }}'
  148.         group: frigate-notification-{{ camera }}
  149.         image: '{{ base_url }}/api/frigate/notifications/{{ id }}/thumbnail.jpg?format=android'
  150.         attachment:
  151.           url: '{{ base_url }}/api/frigate/notifications/{{ id }}/thumbnail.jpg'
  152.           content-type: jpeg
  153. - repeat:
  154.     sequence:
  155.     - wait_for_trigger:
  156.       - platform: mqtt
  157.         topic: frigate/events
  158.         payload: '{{ id }}'
  159.         value_template: '{{ value_json[''after''][''id''] }}'
  160.       timeout:
  161.         minutes: 2
  162.       continue_on_timeout: false
  163.     - condition: template
  164.       value_template: '{{ wait.trigger.payload_json[''type''] == ''end'' }}'
  165.     - choose:
  166.       - conditions: '{{ not group_target }}'
  167.         sequence:
  168.         - device_id: !input 'notify_device'
  169.           domain: mobile_app
  170.           type: notify
  171.           message: A {{ label }} was detected on the {{ camera_name }} camera.
  172.           data:
  173.             tag: '{{ id }}'
  174.             group: frigate-notification-{{ camera }}
  175.             image: '{{ base_url }}/api/frigate/notifications/{{ id }}/thumbnail.jpg?format=android'
  176.             attachment:
  177.               url: '{{ base_url }}/api/frigate/notifications/{{ id }}/thumbnail.jpg'
  178.               content-type: jpeg
  179.             actions:
  180.             - action: URI
  181.               title: View Clip
  182.               uri: '{{ base_url }}/api/frigate/notifications/{{ id }}/{{ camera }}/clip.mp4'
  183.             - action: silence-{{ camera }}
  184.               title: Pause Notifications
  185.               destructive: true
  186.       default:
  187.       - service: notify.{{ group_target }}
  188.         data:
  189.           message: A {{ label }} was detected on the {{ camera_name }} camera.
  190.           data:
  191.             tag: '{{ id }}'
  192.             group: frigate-notification-{{ camera }}
  193.             image: '{{ base_url }}/api/frigate/notifications/{{ id }}/thumbnail.jpg?format=android'
  194.             attachment:
  195.               url: '{{ base_url }}/api/frigate/notifications/{{ id }}/thumbnail.jpg'
  196.               content-type: jpeg
  197.             actions:
  198.             - action: URI
  199.               title: View Clip
  200.               uri: '{{ base_url }}/api/frigate/notifications/{{ id }}/{{ camera }}/clip.mp4'
  201.             - action: silence-{{ camera }}
  202.               title: Pause Notifications
  203.               destructive: true
  204.     - wait_for_trigger:
  205.       - platform: event
  206.         event_type: mobile_app_notification_action
  207.         event_data:
  208.           action: silence-{{ camera }}
  209.       timeout:
  210.         seconds: !input 'cooldown'
  211.       continue_on_timeout: false
  212.     - delay:
  213.         minutes: !input 'silence_timer'
  214.     until: '{{ wait.trigger.payload_json[''type''] == ''end'' }}'
  215.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement