-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdahua_func_flow.json
1 lines (1 loc) · 16.6 KB
/
dahua_func_flow.json
1
[{"id":"7841ff42ab3da737","type":"inject","z":"60f2d2277843c698","name":"second (rule 1)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event_type\":\"dahua_event_received\",\"event\":{\"Code\":\"CrossRegionDetection\",\"action\":\"Start\",\"index\":\"3\",\"data\":{\"Action\":\"Appear\",\"Class\":\"Normal\",\"CountInGroup\":1,\"DetectRegion\":[[4168,3111],[4405,7778],[5916,7510],[5388,3160]],\"EventSeq\":26,\"FrameSequence\":2419837,\"GroupID\":0,\"IndexInGroup\":0,\"Mark\":0,\"Name\":\"ivs\",\"Object\":{\"Action\":\"Appear\",\"BoundingBox\":[3752,2840,5112,4664],\"Center\":[4432,3752],\"Confidence\":0,\"FrameSequence\":0,\"ObjectID\":176,\"ObjectType\":\"Unknown\",\"RelativeID\":0,\"Source\":0,\"Speed\":0,\"SpeedTypeInternal\":0},\"PTS\":58592,\"RuleId\":1,\"Sequence\":0,\"Source\":0,\"Track\":null,\"UTC\":1705948123,\"UTCMS\":0},\"name\":\"XVR second floor\",\"DeviceName\":\"XVR second floor\"},\"origin\":\"LOCAL\",\"time_fired\":\"2024-01-22T23:28:45.514691+00:00\",\"context\":{\"id\":\"01HMSR2GEAFBBXNWHDVCK556PJ\",\"parent_id\":null,\"user_id\":null}}","payloadType":"json","x":240,"y":180,"wires":[["1581e37794a021d1"]]},{"id":"bc3369746dc22f61","type":"inject","z":"60f2d2277843c698","name":"basement (rule 2)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event_type\":\"dahua_event_received\",\"event\":{\"Code\":\"CrossRegionDetection\",\"action\":\"Start\",\"index\":\"2\",\"data\":{\"Action\":\"Appear\",\"Class\":\"Normal\",\"CountInGroup\":1,\"DetectRegion\":[[5697,7792],[7827,6965],[7954,6187],[5952,7184]],\"EventSeq\":5,\"FrameSequence\":2418608,\"GroupID\":0,\"IndexInGroup\":0,\"Mark\":0,\"Name\":\"basement\",\"Object\":{\"Action\":\"Appear\",\"BoundingBox\":[6312,6024,6984,7272],\"Center\":[6648,6648],\"Confidence\":0,\"FrameSequence\":0,\"ObjectID\":33,\"ObjectType\":\"Unknown\",\"RelativeID\":0,\"Source\":0,\"Speed\":0,\"SpeedTypeInternal\":0},\"PTS\":37761,\"RuleId\":1,\"Sequence\":0,\"Source\":0,\"Track\":null,\"UTC\":1705948103,\"UTCMS\":0},\"name\":\"XVR first floor\",\"DeviceName\":\"XVR first floor\"},\"origin\":\"LOCAL\",\"time_fired\":\"2024-01-22T23:28:24.743001+00:00\",\"context\":{\"id\":\"01HMSR1W57T75MKGFXS2J1A8GM\",\"parent_id\":null,\"user_id\":null}}","payloadType":"json","x":230,"y":220,"wires":[["1581e37794a021d1"]]},{"id":"4814dfb3a875c322","type":"inject","z":"60f2d2277843c698","name":"first (rule 2)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event_type\":\"dahua_event_received\",\"event\":{\"Code\":\"CrossRegionDetection\",\"action\":\"Start\",\"index\":\"2\",\"data\":{\"Action\":\"Cross\",\"Class\":\"Normal\",\"CountInGroup\":1,\"DetectRegion\":[[2293,6198],[3986,6222],[3568,7972],[2658,8069],[1893,6660],[2293,6344]],\"Direction\":\"Leave\",\"EventSeq\":10,\"FrameSequence\":2419240,\"GroupID\":0,\"IndexInGroup\":0,\"Mark\":0,\"Name\":\"first\",\"Object\":{\"Action\":\"Appear\",\"BoundingBox\":[2944,3864,4992,7960],\"Center\":[3968,5912],\"Confidence\":0,\"FrameSequence\":0,\"ObjectID\":35,\"ObjectType\":\"Unknown\",\"RelativeID\":0,\"Source\":0,\"Speed\":0,\"SpeedTypeInternal\":0},\"PTS\":48461,\"RuleId\":2,\"Sequence\":0,\"Source\":0,\"Track\":null,\"UTC\":1705948113,\"UTCMS\":0},\"name\":\"XVR first floor\",\"DeviceName\":\"XVR first floor\"},\"origin\":\"LOCAL\",\"time_fired\":\"2024-01-22T23:28:35.553034+00:00\",\"context\":{\"id\":\"01HMSR26Q1RR5FPACJ8A30RQES\",\"parent_id\":null,\"user_id\":null}}","payloadType":"json","x":250,"y":260,"wires":[["1581e37794a021d1"]]},{"id":"e4eedb3ea1392aea","type":"inject","z":"60f2d2277843c698","name":"motion start (rule 3)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event_type\":\"dahua_event_received\",\"event\":{\"Code\":\"VideoMotion\",\"action\":\"Start\",\"index\":\"15\",\"data\":{\"SmartMotionEnable\":false},\"name\":\"XVR front step\",\"DeviceName\":\"XVR front step\"},\"origin\":\"LOCAL\",\"time_fired\":\"2024-01-22T23:24:13.506340+00:00\",\"context\":{\"id\":\"01HMSQT6T2NSYRJGYGYFVE2K5Q\",\"parent_id\":null,\"user_id\":null}}","payloadType":"json","x":230,"y":300,"wires":[["1581e37794a021d1"]]},{"id":"334c139fc2bbd57b","type":"inject","z":"60f2d2277843c698","name":"should return null","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event_type\":\"dahua_event_received\",\"event\":{\"Code\":\"Videootion\",\"action\":\"Stop\",\"index\":\"3\",\"data\":{\"SmartMotionEnable\":false},\"name\":\"XVR second floor\",\"DeviceName\":\"XVR second floor\"},\"origin\":\"LOCAL\",\"time_fired\":\"2024-01-22T23:24:13.969622+00:00\",\"context\":{\"id\":\"01HMSQT78HSZHSW6Y2HY3PXDW6\",\"parent_id\":null,\"user_id\":null}}","payloadType":"json","x":240,"y":340,"wires":[["1581e37794a021d1"]]},{"id":"bc7d0a355d3162f4","type":"inject","z":"60f2d2277843c698","name":"mailbox","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event_type\":\"dahua_event_received\",\"event\":{\"Code\":\"VideoMotion\",\"action\":\"Start\",\"index\":\"1\",\"data\":{\"SmartMotionEnable\":false},\"name\":\"XVR mailbox\",\"DeviceName\":\"XVR mailbox\"},\"origin\":\"LOCAL\",\"time_fired\":\"2024-01-26T20:09:17.318697+00:00\",\"context\":{\"id\":\"01HN3P84R69B5F8JZ7XHXAKG0N\",\"parent_id\":null,\"user_id\":null}}","payloadType":"json","x":270,"y":380,"wires":[["1581e37794a021d1"]]},{"id":"fa24c991d7b00202","type":"inject","z":"60f2d2277843c698","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":420,"wires":[["1581e37794a021d1"]]},{"id":"60e519a6e6fa396c","type":"server-events","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":3,"exposeAsEntityConfig":"","eventType":"dahua_event_received","eventData":"","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":190,"y":120,"wires":[["1581e37794a021d1"]]},{"id":"1581e37794a021d1","type":"function","z":"60f2d2277843c698","name":"Camera action out","func":"if (msg.cameraRate != undefined) {\n const rate = msg.cameraRate * 1000;\n flow.set('rate', rate);\n msg = {};\n msg.rate = 'delay changed to ' + rate/1000 + \" seconds\";\n node.done;\n return msg;\n}\n\nif (msg.payload.event.Code == undefined || msg.payload.event.action === \"Stop\" ) {\n msg = null;\n return [null, null, null, null, null];\n} else {\n\nfunction buildCameraId() {\n const index = msg.payload.event.index;\n const rule = msg.payload.event.data.Name || '';\n const evCo = msg.payload.event.Code;\n const camera = index + '_' + rule + '_' + evCo;\n const cameraTimerArray = global.get(\"cameraTimerArray\")|| [];\n if (cameraTimerArray.indexOf(camera) === -1){\n cameraTimerArray.push(camera);\n global.set(\"cameraTimerArray\", cameraTimerArray);\n }\n return camera;\n}\n\nconst camera = buildCameraId();\n\nfunction testCamera(camera) { \n const lastTime = flow.get(camera) || 30000;\n const currentTime = new Date().getTime();\n const rate = flow.get('rate') || 30000;\n const result = (lastTime < currentTime);\n if (result) {\n flow.set(camera, currentTime + rate);\n }\n return result;\n}\n\nconst result = testCamera(camera);\n\n\nif (result) {\n \n const phoneState = global.get('homeassistant.homeAssistant.states[\"sensor.pixel_7_phone_state_2\"].state');\n const evco = msg.payload.event.Code;\n const ivsRule = msg.payload.event.data.Name;\n const cameraName = msg.payload.event.DeviceName;\n const index = msg.payload.event.index; \n const cameraEntity = \"camera.\" + (cameraName.toLowerCase()).replace(/\\s/g, \"_\") + \"_main\";\n const mTitle = ((cameraName.toUpperCase()).replace(/XVR /, \"\")).replace(/ FLOOR/, \"\");\n const validEvents = global.get(\"validEvents\");\n const mEvent = validEvents[evco];\n const mText = cameraName.replace(/XVR /, \"\");\n\n let msg1 = {};\n let msg2 = {};\n let msg3 = {};\n\n\n \n\n function sendTts() {\n let tts = \"\";\n if (phoneState === \"offhook\") {\n tts = null;\n } else if (evco === \"LeftDetection\") {\n tts = \"Something is at the mailbox\";\n } else if (ivsRule === \"ivs\" || evco === \"VideoMotion\") {\n tts = ((cameraName.toLowerCase()).replace(/xvr /, \"\")).replace(/ floor/, \"\");\n } else {\n tts = ivsRule;\n }\n\n return tts;\n\n }\n\n \n msg1.payload = sendTts();\n node.send([null, null, null, msg1, null]);\n \n\n msg2.payload = {\n \"title\": mTitle,\n \"message\": mEvent +\" on \"+ mText,\n \"image\": cameraEntity,\n \"action1\": camera + \"|5\",\n \"action2\": camera + \"|20\",\n \"action3\": \"all|10\"\n }\n\n\n msg3.payload = (Number(index) + 1);\n msg3.cName = mText;\n msg3.cEntity = cameraEntity;\n\n \n\n let countOutput = (context.get('countOutput' || 1));\n\n if (countOutput == 1) {\n countOutput += 1;\n context.set(\"countOutput\", countOutput);\n return [msg2, null, null, null, msg3];\n } else if (countOutput == 2) {\n countOutput += 1;\n context.set(\"countOutput\", countOutput);\n return [null, msg2, null, null, msg3]; \n } else {\n countOutput = 1;\n context.set(\"countOutput\", countOutput);\n return [null, null, msg2, null, msg3];\n };\n} else {\n return [null, null, null, null, null];\n}\n\n}","outputs":5,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":160,"wires":[["513fade4cdd3a9d0"],["3ca42db57d476a4b"],["824217f8e77b9e4d"],["862c608b440e0a9c"],["bb27be6d7026196d"]]},{"id":"862c608b440e0a9c","type":"api-call-service","z":"60f2d2277843c698","name":"send tts text","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_pixel_7","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\":\"TTS\",\"data\":{\"tts_text\":\"{{payload}}\",\"ttl\":0,\"priority\":\"high\"}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"all","x":830,"y":320,"wires":[[]]},{"id":"eaa5a6b40e961459","type":"api-call-service","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"counter","service":"set_value","areaId":[],"deviceId":[],"entityId":["counter.frontend_cams"],"data":"{\"value\":12}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1070,"y":380,"wires":[[]]},{"id":"bb27be6d7026196d","type":"api-call-service","z":"60f2d2277843c698","name":"tigger cam","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"input_number","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_number.frontend_trigger_cam"],"data":"{ \"value\" : {{payload}} }","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"date"}],"queue":"none","x":830,"y":400,"wires":[["eaa5a6b40e961459"]]},{"id":"3ca42db57d476a4b","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\": payload.title,\t \"message\": payload.message,\t \"data\":{\t \"image\": $entities(payload.image).attributes.entity_picture,\t \"clickAction\":\"/lovelace-test/back\",\t \"ttl\":0,\t \"priority\":\"high\",\t \"actions\":[\t {\t \"action\": payload.action1,\t \"title\": \"5 Min\"\t },\t {\t \"action\": payload.action2,\t \"title\": \"20 Min\"\t },\t {\t \"action\": payload.action3,\t \"title\": \"All\"\t }\t ] \t }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"all","x":830,"y":200,"wires":[[]]},{"id":"513fade4cdd3a9d0","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\": payload.title,\t \"message\": payload.message,\t \"data\":{\t \"image\": $entities(payload.image).attributes.entity_picture,\t \"clickAction\":\"/lovelace-test/back\",\t \"ttl\":0,\t \"priority\":\"high\",\t \"actions\":[\t {\t \"action\": payload.action1,\t \"title\": \"5 Min\"\t },\t {\t \"action\": payload.action2,\t \"title\": \"20 Min\"\t },\t {\t \"action\": payload.action3,\t \"title\": \"All\"\t }\t ] \t }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"all","x":830,"y":140,"wires":[[]]},{"id":"824217f8e77b9e4d","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\": payload.title,\t \"message\": payload.message,\t \"data\":{\t \"image\": $entities(payload.image).attributes.entity_picture,\t \"clickAction\":\"/lovelace-test/back\",\t \"ttl\":0,\t \"priority\":\"high\",\t \"actions\":[\t {\t \"action\": payload.action1,\t \"title\": \"5 Min\"\t },\t {\t \"action\": payload.action2,\t \"title\": \"20 Min\"\t },\t {\t \"action\": payload.action3,\t \"title\": \"All\"\t }\t ] \t }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"all","x":830,"y":260,"wires":[[]]},{"id":"318bdc545581bdb5","type":"server-events","z":"60f2d2277843c698","name":"mobile_app_notification_action","server":"6b1110b5.183a4","version":3,"exposeAsEntityConfig":"","eventType":"mobile_app_notification_action","eventData":"","waitForRunning":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"},{"property":"event_type","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":190,"y":60,"wires":[["0e9a1ec68550f9c4"]]},{"id":"0e9a1ec68550f9c4","type":"function","z":"60f2d2277843c698","name":"Camera action in","func":"if (msg.payload.event.action == undefined) {\n return(null);\n}\n\nconst action = msg.payload.event.action;\nconst split = action.split(\"|\");\nconst camera = split[0];\nconst delay = Number(split[1]) * 60 * 1000;\nif (camera == \"all\"){\n const cameraList = global.get(\"cameraTimerArray\");\n for (let i = 0; i < cameraList.length; i++) {\n const element = cameraList[i];\n const timer = flow.get(element);\n const delayTime = timer + delay;\n flow.set(element, delayTime); \n }\n} else {\n const cameraDelay = flow.get(camera);\n const extendDelay = cameraDelay + delay;\n flow.set(camera, extendDelay);\n}\n\n\nmsg = {};\nmsg.camera = camera;\nmsg.delay = delay;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":60,"wires":[["d8105b8ecc406be1"]]},{"id":"d8105b8ecc406be1","type":"debug","z":"60f2d2277843c698","name":"debug 176","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":60,"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}]