Frigate notifications

So I am using this blueprint to send frigate notifications, and it works well. The main thing I like about it is the snapshot attached to the mobile notification. Is is possible to re-create this in Node Red?

Could it be done, sure. The only thing is that there is a lot of work done for you in the blueprint. You would need to set up everything yourself.

You would need to create all the text for the message options, specify the color of the text, format the Android tv pop-ups etc.

1 Like

I’m really just looking to have the functionality of adding a snapshot to the notification.

I’m not familiar with frigate. I assume that it takes a snapshot once an event occurs. You would need to specify where that file is stored to link it to the text.

I just have my cameras integrated into home assistant. When a motion alarm is triggered, I have it set to take a snapshot of the camera feed. I then send that snapshot to my phone in a text.

1 Like

This is the format to send a text with snapshot. “image” would be the path to where the snapshot is stored.

[{"id":"c18e33a6a9f4c709","type":"api-call-service","z":"60f2d2277843c698","name":"send pic text","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_pixel_7","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"title\": \"your title here\",\t   \"message\": \"your message here\",\t   \"data\":{\t       \"image\":\"/media/local/camera/snapshot_folder/snap01.jpg\",\t       \"ttl\":0,\t       \"priority\":\"high\",\t       \"color\": \"#2DF56D\"\t   }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":870,"y":900,"wires":[[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
1 Like

You use these endpoints to access frigate images and videos https://docs.frigate.video/integrations/home-assistant/#notification-api

and as @Mikefila showed use them in a notification data properties. https://companion.home-assistant.io/docs/notifications/notification-attachments#example-service-call

1 Like

So when trying to use this, I get the following.
"JSONataError: Expected "}", got "H""

You’ll need to post what you have in the data section, there’s an error somewhere. It should have a squiggly red underline in the editor.

{
   "title": "your title here",
   "message": "your message here",
   "data":{
       "image":"/media/frigate/{{ computer_camera }}_{{now().strftime("%Y%m%d-%H%M%S")}}.jpeg",
       "ttl":0,
       "priority":"high",
       "color": "#2DF56D"
   }
}```

It’s not going to render that template. Are you sure that is the format of the snapshot name? From the docs the end point is

https://HA_URL/api/frigate/notifications/<event-id>/snapshot.jpg

Can you put a camera entity that you are going to use to start the flow in a event state node. check the box output on connect towards the bottom. and deploy. Then post the output to the debug.

[{"id":"bd4e19401d4d069e","type":"server-state-changed","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"","entityIdType":"exact","outputInitially":true,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":630,"y":1100,"wires":[["0406976c7788ed8e"]]},{"id":"0406976c7788ed8e","type":"debug","z":"60f2d2277843c698","name":"debug 29","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":880,"y":1100,"wires":[]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

change the ip address(HA_URL) and try.

{
   "title": "your title here",
   "message": "your message here",
   "data":{
       "image":"https://HA_URL/api/frigate/notifications/" & data.new_state.context.id & "/snapshot.jpg",
       "ttl":0,
       "priority":"high",
       "color": "#2DF56D"
   }
}


I doubt the above will work, You’ll need to trigger the motion event and look for the event_id in the debug. Substitute that path for data.new_state.context.id

{"payload":"streaming","data":{"entity_id":"camera.computer_camera","old_state":{"entity_id":"camera.computer_camera","state":"streaming","attributes":{"access_token":"token","frontend_stream_type":"hls","restream_type":"rtsp","device_class":"camera","entity_picture":"/api/camera_proxy/camera.computer_camera?token=token","friendly_name":"Computer Camera","supported_features":2},"context":{"id":"01HQW18CXWG921TPQ2MK28QBPB","parent_id":null,"user_id":null},"last_changed":"2024-03-01T00:19:12.713Z","last_updated":"2024-03-01T03:34:50.044Z","timeSinceChangedMs":11861566},"new_state":{"entity_id":"camera.computer_camera","state":"streaming","attributes":{"access_token":"token","frontend_stream_type":"hls","restream_type":"rtsp","device_class":"camera","entity_picture":"/api/camera_proxy/camera.computer_camera?token=token","friendly_name":"Computer Camera","supported_features":2},"context":{"id":"01HQW18CXWG921TPQ2MK28QBPB","parent_id":null,"user_id":null},"last_changed":"2024-03-01T00:19:12.713Z","last_updated":"2024-03-01T03:34:50.044Z","timeSinceChangedMs":11861566}},"topic":"camera.computer_camera","_msgid":"7ca5b3df60dd2d38"}```

Now that you see it in mqtt explorer, Use an mqtt node to trigger the snapshot text. For the image path use the following but change HA_URL to your HA ip. ex. 192.168.x.x:8123

`"https://HA_URL/api/frigate/notifications/" & payload.id & "/snapshot.jpg"`

image

Mqtt node and switch. In the switch, put the name of the camera in the == text box.

[{"id":"72fc9b88ff77ba83","type":"debug","z":"7d105d71.cc18e4","name":"debug 30","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":680,"y":1780,"wires":[]},{"id":"22e0409995e384eb","type":"switch","z":"7d105d71.cc18e4","name":"camera name","property":"payload.camera","propertyType":"msg","rules":[{"t":"eq","v":"camera goes here","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":480,"y":1780,"wires":[["72fc9b88ff77ba83"]]},{"id":"e2c2a8ab2eb5bcae","type":"mqtt in","z":"7d105d71.cc18e4","name":"frigate/events","topic":"frigate/events/#","qos":"0","datatype":"auto-detect","broker":"601bef1.d5b981","nl":false,"rap":false,"inputs":0,"x":270,"y":1780,"wires":[["22e0409995e384eb"]]},{"id":"601bef1.d5b981","type":"mqtt-broker","name":"Mosquitto","broker":"127.0.0.1","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

I’m assuming the id needs to be the event id?

Yes. Connect the mqtt node to a debug and trigger the camera. I believe you will only see id and not event_id. If it is event_id use payload.event_id instead. If you’re having trouble post the debug out put from the mqtt node.

This is what showed up in the debug

{"topic":"frigate/events","payload":{"before":{"id":"1709592713.813843-19c03d","camera":"computer_camera","frame_time":1709592713.813843,"snapshot":null,"label":"person","sub_label":null,"top_score":0,"false_positive":true,"start_time":1709592713.813843,"end_time":null,"score":0.6953125,"box":[383,333,545,477],"area":23328,"ratio":1.125,"region":[305,160,625,480],"stationary":false,"motionless_count":0,"position_changes":0,"current_zones":[],"entered_zones":[],"has_clip":false,"has_snapshot":false,"attributes":{},"current_attributes":[]},"after":{"id":"1709592713.813843-19c03d","camera":"computer_camera","frame_time":1709592714.014127,"snapshot":{"frame_time":1709592714.014127,"box":[370,327,555,478],"area":27935,"region":[304,160,624,480],"score":0.70703125,"attributes":[]},"label":"person","sub_label":null,"top_score":0.701171875,"false_positive":false,"start_time":1709592713.813843,"end_time":null,"score":0.70703125,"box":[370,327,555,478],"area":27935,"ratio":1.2251655629139073,"region":[304,160,624,480],"stationary":false,"motionless_count":0,"position_changes":1,"current_zones":[],"entered_zones":[],"has_clip":false,"has_snapshot":false,"attributes":{},"current_attributes":[]},"type":"new"},"qos":0,"retain":false,"_msgid":"1244da58baaa6543"}

Make sure in the call service you change HA_URL to your home assistant address.

"https://HA_URL/api/frigate/notifications/" & payload.after.id & "/snapshot.jpg"

[{"id":"d6f11728161eb111","type":"switch","z":"60f2d2277843c698","name":"","property":"payload.before.camera","propertyType":"msg","rules":[{"t":"eq","v":"computer_camera","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":1560,"wires":[["d93a88c7cd6bf9e7"]]},{"id":"d93a88c7cd6bf9e7","type":"api-call-service","z":"60f2d2277843c698","name":"send pic text","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_pixel_7","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"title\": \"your title\",\t   \"message\": \"your message\",\t   \"data\":{\t       \"image\":\"https://HA_URL/api/frigate/notifications/\" & payload.after.id & \"/snapshot.jpg\"\t   }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":530,"y":1560,"wires":[[]]},{"id":"852185cf7efc81d4","type":"mqtt in","z":"60f2d2277843c698","name":"","topic":"frigate/events/#","qos":"2","datatype":"auto-detect","broker":"601bef1.d5b981","nl":false,"rap":true,"rh":0,"inputs":0,"x":140,"y":1560,"wires":[["d6f11728161eb111"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"601bef1.d5b981","type":"mqtt-broker","name":"Mosquitto","broker":"127.0.0.1","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

I have this

"title": "your title here",
   "message": "your message here",
   "data":{
       "image":"https://192.168.0.5:8123/api/frigate/notifications/" & payload."1709592713.813843-19c03d" & "/snapshot.jpg",
       "ttl":0,
       "priority":"high",
       "color": "#2DF56D"
   }
}```

Do you have https setup? You may not be able to use just the ip. I also noticed in the event message that the snapshot is set to false. You may need to enable that in frigate.

image

Edit you do not need to add that number,

& payload."1709592713.813843-19c03d" &

leave the whole path

payload.after.id

It will replace that with the number in the message.

"https://192.168.0.5:8123/api/frigate/notifications/" & payload.after.id & "/snapshot.jpg"

So snapshot is on

{"id":"1709610675.647674-lj9sds","camera":"computer_camera","frame_time":1709610771.448181,"snapshot":{"frame_time":1709610771.448181,"box":[365,318,553,478],"area":30080,"region":[294,160,614,480],"score":0.734375,"attributes":[]},"label":"person","sub_label":null,"top_score":0.701171875,"false_positive":false,"start_time":1709610675.647674,"end_time":null,"score":0.734375,"box":[365,318,553,478],"area":30080,"ratio":1.175,"region":[294,160,614,480],"stationary":false,"motionless_count":16,"position_changes":1,"current_zones":[],"entered_zones":[],"has_clip":false,"has_snapshot":true,"attributes":{},"current_attributes":[]}

I will make the change to the payload.after.id