Flow to send deep stack object notification and image to IOS notification

X-Posted to Face and person detection with Deepstack - local and free! which is also a prerequisite.

I created a templated IOS notification for deepstack events and thought others could use.

The events all triggers from a deepstack.object_detected event. A switch node then directs which object triggered event and send to a change node to capture some of the payload and sets them in the flow with some strings to create a meaningful message on your phone. Requires no changes the function or call service node.

flow:

[{"id":"1a5277d2.1344c8","type":"tab","label":"Deepstack IOS Notification","disabled":false,"info":""},{"id":"beab4dc5.0a174","type":"server-events","z":"1a5277d2.1344c8","name":"deep stack object detected","server":"2a12269e.94634a","event_type":"deepstack.object_detected","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":190,"y":200,"wires":[["1206ad98.130652"]]},{"id":"3cbd2461.d2750c","type":"function","z":"1a5277d2.1344c8","name":"Create IOS Alert","func":"var entity = flow.get('entity');\nvar object_type = flow.get('object_type');\nvar confidence = flow.get('confidence');\nvar msg1 = flow.get('msg1');\nvar msg2 = flow.get('msg2')\nvar msg3 = flow.get('msg3');\nvar msg4 = flow.get('msg4');\nvar ios_target = flow.get('ios_target')\nvar image_url = flow.get('image_url')\n\nvar final_msg = `${msg1}` +`${object_type}` + `${msg2}` + `${entity}` + `${msg3}` + `${confidence}` + `${msg4}`\nvar payload = {\"data\":\n{\n    \"message\": `${final_msg}`,\n    \"data\": {\n        \"attachment\": {\n            \"url\": `${image_url}`,\n            \"content-type\": \"jpg\",\n            \"hide-thumbnail\": false\n        }\n    }\n       \n    }\n}\n\nmsg.payload = payload\nmsg.topic = `${ios_target}`\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1080,"y":200,"wires":[["80a81c05.fbc12"]]},{"id":"80a81c05.fbc12","type":"api-call-service","z":"1a5277d2.1344c8","name":"Notify Target IOS with Message","server":"2a12269e.94634a","version":1,"debugenabled":false,"service_domain":"notify","service":"{{topic}}","entityId":"","data":"{}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1370,"y":200,"wires":[[]]},{"id":"593c5bca.f93ea4","type":"change","z":"1a5277d2.1344c8","name":"Set Variables","rules":[{"t":"set","p":"msg1","pt":"flow","to":"A ","tot":"str"},{"t":"set","p":"object_type","pt":"flow","to":"payload.event.object_type","tot":"msg"},{"t":"set","p":"msg2","pt":"flow","to":" was detected in the ","tot":"str"},{"t":"set","p":"entity","pt":"flow","to":"Driveway ","tot":"str"},{"t":"set","p":"msg3","pt":"flow","to":"with ","tot":"str"},{"t":"set","p":"confidence","pt":"flow","to":"payload.event.confidence","tot":"msg"},{"t":"set","p":"msg4","pt":"flow","to":" confidence","tot":"str"},{"t":"set","p":"ios_target","pt":"flow","to":"mobile_app_paul_phone","tot":"str"},{"t":"set","p":"image_url","pt":"flow","to":"https://external_HA-URL/local/snapshots/test/driveway_person_test_objects_latest.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":200,"wires":[["3cbd2461.d2750c"]]},{"id":"1206ad98.130652","type":"switch","z":"1a5277d2.1344c8","name":"","property":"payload.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"image_processing.driveway_person_test_objects","vt":"str"},{"t":"eq","v":"image_processing.driveway_objects","vt":"str"},{"t":"eq","v":"image_processing.garage_objects","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":450,"y":200,"wires":[["593c5bca.f93ea4"],[],[]]},{"id":"4d810478.d9b9cc","type":"comment","z":"1a5277d2.1344c8","name":"change you your HA server","info":"This will listen to all deepstack.object_detected events","x":190,"y":160,"wires":[]},{"id":"899123b1.dc364","type":"comment","z":"1a5277d2.1344c8","name":"Edit your image processing objects","info":"create a switch for each image processing object","x":500,"y":160,"wires":[]},{"id":"216d717b.28a1ee","type":"comment","z":"1a5277d2.1344c8","name":"Edit your message and IOS target","info":"Change:\n  entity \"Driveway\"\n  msg1 \"A \"\n  msg2 \"was detected \"\n  msg3 \"in the \"\n  msg4 \"with \"\n  ios_target \"mobile_device_iphone\"\n  image_url your ha url to snapshot from deepstack latest\n  \nThis will send the following message to that phone.\n\n\"A Person was detected in the Driveway with 82.98% confidence\"","x":800,"y":160,"wires":[]},{"id":"ae43c5d7.393d38","type":"comment","z":"1a5277d2.1344c8","name":"No edits needed","info":"","x":1080,"y":160,"wires":[]},{"id":"997d46d2.a4fb58","type":"comment","z":"1a5277d2.1344c8","name":"No edits needed","info":"","x":1320,"y":160,"wires":[]},{"id":"2a12269e.94634a","type":"server","name":"Hingham Home","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
2 Likes