DIY alarm zone

This sub-flow can be used to create one or more Alarm Zones, each with different exit/entry delays, alarm durations, and sensor inputs.

The input expects a JSON payload and depending on the type will either arm or disarm the alarm (switch, button, keypad, or mode type) or check for sensor values (contact or security type).

An example payload to arm the alarm would be;

{"type":"mode", "event":"arm", "exitDelaySeconds":5}

NOTE: you can override the default exit delay (set as environment variable on the sub-flow instance) by passing exitDelaySeconds in the arm event.

An example payload to trip the alarm, i.e. from a sensor, would be;

{"type":"contact", "event":"closed", "sensor":"entry pir"}
{"type":"security", "event":"alarm", "sensor":"kitchen window", "entryDelaySeconds":0}

NOTE: you can override the default entry delay (set as environment variable on the sub-flow instance) by passing entryDelaySeconds in the sensor event.

The flow will output events in JSON format as the alarm changes state. See the sub-flow description/docs for more details.

An example output payload when the alarm is tripped would be;

{"type":"alarm", "event":"alarm", "zone":"<zone name>", "sensor":"<sensor name>"}

NOTE: <zone name> is set as environment variable on the sub-flow instance, and <sensor name> is set on the incoming sensor event payload (optionally).

[{"id":"c0b74be01e058643","type":"subflow","name":"alarm zone","info":"# Alarm Zone\r\nRepresents a single alarm zone. Feed sensor events into the input and receive alarm events on the output.\r\n\r\n## Config\r\nSet the zone name, exit/entry delays (in seconds), and alarm duration (in seconds) for this zone;\r\n\r\n - \"Zone Name\" is included in the `alarm` payloads\r\n - \"Exit Delay (secs)\" is how long you have to exit, before the alarm is armed\r\n - \"Entry Delay (secs)\" is how long you have to disarm after tripping a sensor, before the alarm is activated\r\n - \"Alarm Duration (secs)\" is how long the alarm remains active, before resetting\r\n\r\n NOTE: setting the \"Alarm Duration\" to zero seconds will mean it never resets once activated (useful for smoke/flood alarms).\r\n\r\n## Input\r\nExpects a JSON payload on the input with the following options;\r\n\r\n### Arm/Disarm\r\n```json\r\n{\"type\":\"keypad\", \"event\":\"lock|unlock\"}\r\n{\"type\":\"switch\", \"event\":\"on|off\"}\r\n{\"type\":\"mode\", \"event\":\"arm|disarm\", \"exitDelaySeconds\":0}\r\n```\r\n\r\nOptionally include `exitDelaySeconds` to override the zone default. Setting `exitDelaySeconds` to zero will mean no delay and any sensor event will trip the alarm immediately.\r\n\r\n### Sensor\r\n```json\r\n{\"type\":\"contact\", \"event\":\"open|closed\", \"sensor\":\"entry pir\", \"isolated\":true}\r\n{\"type\":\"security\", \"event\":\"normal|alarm\", \"sensor\":\"kitchen window\", \"entryDelaySeconds\":0}\r\n{\"type\":\"contact\", \"event\":\"open|closed\", \"sensor\":\"entry pir\", \"alarmAlways\":true}\r\n```\r\n\r\nOptionally include `sensor` name in the payload, which will be copied to the `alarm` event.\r\nOptionally include `isolated` in the payload, which will cause the sensor events to be ignored.\r\nOptionally include `entryDelaySeconds` to override the zone default. Setting `entryDelaySeconds` to zero will mean no `entry` event and the alarm will activate immediately.\r\nOptionally include `alarmAlways` in the payload, which will cause the alarm to activate even if not armed. The entry delay will still be honoured.\r\n\r\nNOTE: `contact` sensors are assumed to be normally-open, and will alarm on `closed` events.\r\n\r\n## Output\r\nEmits a JSON payload on the output with the following options;\r\n\r\n### Disarmed\r\nEmits an event when the alarm has been disarmed;\r\n```json\r\n{\"type\":\"alarm\", \"event\":\"disarmed\", \"zone\":\"<zone name>\"}\r\n```\r\n\r\n### Exit\r\nEmits an event when arming the alarm to indicate the exit timer is active (i.e. use to turn on warning blips);\r\n```json\r\n{\"type\":\"alarm\", \"event\":\"exit\", \"zone\":\"<zone name>\"}\r\n```\r\n\r\n### Armed\r\nEmits an event when the exit timer has expired and the alarm has been armed;\r\n```json\r\n{\"type\":\"alarm\", \"event\":\"armed\", \"zone\":\"<zone name>\"}\r\n```\r\n\r\n### Entry\r\nEmits an event when a sensor is first tripped (if the alarm is armed) to indicate the entry timer is active (i.e. use to turn on warning blips);\r\n```json\r\n{\"type\":\"alarm\", \"event\":\"entry\", \"zone\":\"<zone name>\", \"sensor\":\"<sensor name>\"}\r\n```\r\nWhere `<sensor name>` is copied from sensor input event, from `payload.sensor`.\r\n\r\n### Alarm\r\nEmits an event if the entry timer expires without the alarm being disarmed (i.e. use turn on strobe/siren);\r\n```json\r\n{\"type\":\"alarm\", \"event\":\"alarm\", \"zone\":\"<zone name>\", \"sensor\":\"<sensor name>\"}\r\n```\r\nWhere `<sensor name>` is copied from sensor input event, from `payload.sensor`.\r\n\r\nNOTE: once the alarm is activated any subsequent sensor events will generate additional `alarm` events, up until the alarm is `disarmed` or `reset`.\r\n\r\n### Reset\r\nEmits an event when the alarm duration timer expires and the alarm is reset (i.e. use turn off strobe/siren);\r\n```json\r\n{\"type\":\"alarm\", \"event\":\"reset\", \"zone\":\"<zone name>\"}\r\n```","category":"","in":[{"x":60,"y":220,"wires":[{"id":"efeb6c9c9d3f38fd"}]}],"out":[{"x":1300,"y":460,"wires":[{"id":"2f3030acedf40d95","port":0},{"id":"f206b685b6cf0761","port":0},{"id":"8b62de9b8c7e1e21","port":0},{"id":"34e303aaf008b154","port":0},{"id":"e8acccc2a7a1744a","port":0},{"id":"f57496fdf4a5e05a","port":0},{"id":"ddf4449348f82f3d","port":0}]}],"env":[{"name":"ALARM_ZONE_NAME","type":"str","value":"House","ui":{"icon":"font-awesome/fa-italic","label":{"en-US":"Zone Name"},"type":"input","opts":{"types":["str"]}}},{"name":"ALARM_ZONE_EXIT_DELAY_SECS","type":"num","value":"30","ui":{"icon":"font-awesome/fa-clock-o","label":{"en-US":"Exit Delay (secs)"},"type":"input","opts":{"types":["num"]}}},{"name":"ALARM_ZONE_ENTRY_DELAY_SECS","type":"num","value":"30","ui":{"icon":"font-awesome/fa-bullhorn","label":{"en-US":"Entry Delay (secs)"},"type":"input","opts":{"types":["num"]}}},{"name":"ALARM_ZONE_ALARM_DURATION_SECS","type":"num","value":"300","ui":{"icon":"font-awesome/fa-clock-o","label":{"en-US":"Alarm Duration (secs)"},"type":"input","opts":{"types":["num"]}}}],"meta":{},"color":"#E9967A","icon":"font-awesome/fa-bullhorn","status":{"x":1300,"y":380,"wires":[{"id":"96736ca0f2bc8ebd","port":0},{"id":"e48f3351b44214f8","port":0},{"id":"d7e9a8712d3bf586","port":0},{"id":"d29c5bc9a97c0cc7","port":0},{"id":"cd88479938936680","port":0},{"id":"4a0d7bbcba614667","port":0}]}},{"id":"efeb6c9c9d3f38fd","type":"switch","z":"c0b74be01e058643","name":"type","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"keypad","vt":"str"},{"t":"eq","v":"button","vt":"str"},{"t":"eq","v":"switch","vt":"str"},{"t":"eq","v":"mode","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":5,"x":170,"y":220,"wires":[["36a2beb55b16559e"],["329398f0b0225c53"],["1c743c0fe0ee1a8d"],["f513c9ba78d691ef"],["434908223452e947"]]},{"id":"8d22603e6fd37fc0","type":"switch","z":"c0b74be01e058643","name":"arm?","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"disarm","vt":"str"},{"t":"eq","v":"arm","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":240,"wires":[["b50cea8feb5d2f86","2563710c67625f91"],["281d06944e9350b8","430ec97a68668b18"]]},{"id":"b50cea8feb5d2f86","type":"change","z":"c0b74be01e058643","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":100,"wires":[["509879f5282ce7f5"]]},{"id":"47d7eeae894d8a81","type":"switch","z":"c0b74be01e058643","name":"security","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"normal","vt":"str"},{"t":"eq","v":"alarm","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":380,"y":580,"wires":[[],["c7859e2816edf8e8"],["3a6775a43c1b4f3b"]]},{"id":"7624d508b571cc97","type":"switch","z":"c0b74be01e058643","name":"contact","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"open","vt":"str"},{"t":"eq","v":"closed","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":380,"y":520,"wires":[[],["c7859e2816edf8e8"]]},{"id":"cb657b7e9bef9311","type":"trigger","z":"c0b74be01e058643","name":"alarm","op1":"","op2":"","op1type":"pay","op2type":"pay","duration":"250","extend":false,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":850,"y":1100,"wires":[["31a435d2f1cc7772"],["afd8c558614a98c7"]]},{"id":"c89d292e080d996d","type":"trigger","z":"c0b74be01e058643","name":"entry","op1":"","op2":"","op1type":"pay","op2type":"pay","duration":"250","extend":false,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":850,"y":940,"wires":[["cfd7852eeb7087d6"],["312f7a09db17f9a0"]]},{"id":"89740f40d7aa003d","type":"gate","z":"c0b74be01e058643","name":"armed","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":true,"storeName":"default","x":610,"y":620,"wires":[["a72878e54f739c8e","dbed6a616ba6af47"]]},{"id":"509879f5282ce7f5","type":"link out","z":"c0b74be01e058643","name":"reset","mode":"link","links":["ef99d4f89a030511","fb76342da33d09a0","3a4b1cbb5b25723a","493d04ab3418fe9e"],"x":735,"y":100,"wires":[]},{"id":"fb76342da33d09a0","type":"link in","z":"c0b74be01e058643","name":"delay: entry","links":["509879f5282ce7f5"],"x":765,"y":920,"wires":[["c89d292e080d996d"]]},{"id":"ef99d4f89a030511","type":"link in","z":"c0b74be01e058643","name":"delay: alarm","links":["509879f5282ce7f5"],"x":765,"y":1080,"wires":[["cb657b7e9bef9311"]]},{"id":"a72878e54f739c8e","type":"gate","z":"c0b74be01e058643","name":"shunt","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":true,"storeName":"default","x":850,"y":840,"wires":[["519c84c3608dac10"]]},{"id":"afd8c558614a98c7","type":"link out","z":"c0b74be01e058643","name":"alarm: end","mode":"link","links":["38feeeac68bec12b","493d04ab3418fe9e","55891ae06ede3140"],"x":935,"y":1120,"wires":[]},{"id":"cf3e8ec375c5c64e","type":"switch","z":"c0b74be01e058643","name":"zero delay?","property":"delay","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":630,"y":960,"wires":[["c89d292e080d996d"],["312f7a09db17f9a0"]]},{"id":"d7e9a8712d3bf586","type":"template","z":"c0b74be01e058643","name":"status: armed","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"fill\":\"blue\",\"shape\":\"dot\",\"text\":\"armed\"}","output":"json","x":1160,"y":300,"wires":[[]]},{"id":"d29c5bc9a97c0cc7","type":"template","z":"c0b74be01e058643","name":"status: entry","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"fill\":\"yellow\",\"shape\":\"dot\",\"text\":\"entry: {{payload.sensor}}\"}","output":"json","x":1150,"y":400,"wires":[[]]},{"id":"cd88479938936680","type":"template","z":"c0b74be01e058643","name":"status: alarm","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"fill\":\"red\",\"shape\":\"dot\",\"text\":\"alarm: {{payload.sensor}}\"}","output":"json","x":1150,"y":500,"wires":[[]]},{"id":"96736ca0f2bc8ebd","type":"template","z":"c0b74be01e058643","name":"status: disarmed","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"fill\":\"green\",\"shape\":\"dot\",\"text\":\"disarmed\"}","output":"json","x":1160,"y":100,"wires":[[]]},{"id":"ddf4449348f82f3d","type":"template","z":"c0b74be01e058643","name":"output: disarmed","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"type\":\"alarm\",\"event\":\"disarmed\",\"zone\":\"{{env.ALARM_ZONE_NAME}}\"}","output":"json","x":1170,"y":140,"wires":[[]]},{"id":"34e303aaf008b154","type":"template","z":"c0b74be01e058643","name":"output: entry","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"type\":\"alarm\",\"event\":\"entry\",\"zone\":\"{{env.ALARM_ZONE_NAME}}\",\"delayMillis\":{{delay}},\"sensor\":\"{{payload.sensor}}\"}","output":"json","x":1150,"y":440,"wires":[[]]},{"id":"8b62de9b8c7e1e21","type":"template","z":"c0b74be01e058643","name":"output: alarm","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"type\":\"alarm\",\"event\":\"alarm\",\"zone\":\"{{env.ALARM_ZONE_NAME}}\",\"sensor\":\"{{payload.sensor}}\"}","output":"json","x":1150,"y":540,"wires":[[]]},{"id":"dbed6a616ba6af47","type":"gate","z":"c0b74be01e058643","name":"report","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":true,"storeName":"default","x":850,"y":620,"wires":[["6e9b4e0a3027c142"]]},{"id":"2563710c67625f91","type":"link out","z":"c0b74be01e058643","name":"disarmed","mode":"link","links":["6e272782224f917e","ad9aa48ed004f8ec"],"x":735,"y":220,"wires":[]},{"id":"281d06944e9350b8","type":"link out","z":"c0b74be01e058643","name":"armed","mode":"link","links":["13ee263f0b196a6e"],"x":735,"y":260,"wires":[]},{"id":"ad9aa48ed004f8ec","type":"link in","z":"c0b74be01e058643","name":"status: disarmed","links":["2563710c67625f91"],"x":1035,"y":120,"wires":[["96736ca0f2bc8ebd","ddf4449348f82f3d"]]},{"id":"985dad1c3753b605","type":"link in","z":"c0b74be01e058643","name":"status: armed","links":["9713ad91985255a2"],"x":1035,"y":320,"wires":[["d7e9a8712d3bf586","e8acccc2a7a1744a"]]},{"id":"7b8caf94318c0ddc","type":"change","z":"c0b74be01e058643","name":"open","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":560,"wires":[["c000c052fd726e7a"]]},{"id":"15a4a72dd7500d96","type":"change","z":"c0b74be01e058643","name":"close","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":520,"wires":[["c000c052fd726e7a"]]},{"id":"76fda49e3d2a8299","type":"comment","z":"c0b74be01e058643","name":"sensor tripped, start entry delay timer","info":"","x":470,"y":920,"wires":[]},{"id":"99e8192021309418","type":"comment","z":"c0b74be01e058643","name":"activate alarm, start timer","info":"","x":430,"y":1060,"wires":[]},{"id":"2b90aad4c337ed65","type":"comment","z":"c0b74be01e058643","name":"sensor events","info":"","x":390,"y":480,"wires":[]},{"id":"b8eb69e9c279cb74","type":"comment","z":"c0b74be01e058643","name":"alarm mode","info":"","x":390,"y":60,"wires":[]},{"id":"36a2beb55b16559e","type":"change","z":"c0b74be01e058643","name":"keypad","rules":[{"t":"set","p":"payload.type","pt":"msg","to":"mode","tot":"str"},{"t":"set","p":"payload.event","pt":"msg","to":"$.payload.event = \"lock\" ? \"arm\" : \"disarm\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":100,"wires":[["f513c9ba78d691ef"]]},{"id":"d1ad7d0563a47d67","type":"trigger","z":"c0b74be01e058643","name":"exit","op1":"","op2":"","op1type":"pay","op2type":"pay","duration":"250","extend":false,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":850,"y":360,"wires":[["666570f45623db25"],["9713ad91985255a2"]]},{"id":"3a4b1cbb5b25723a","type":"link in","z":"c0b74be01e058643","name":"delay: exit","links":["509879f5282ce7f5"],"x":765,"y":340,"wires":[["d1ad7d0563a47d67"]]},{"id":"69431979c854ff7f","type":"switch","z":"c0b74be01e058643","name":"zero delay?","property":"delay","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":630,"y":380,"wires":[["d1ad7d0563a47d67"],["9713ad91985255a2"]]},{"id":"bc99876ec964b3dd","type":"comment","z":"c0b74be01e058643","name":"alarm armed, start exit delay timer","info":"","x":460,"y":340,"wires":[]},{"id":"666570f45623db25","type":"link out","z":"c0b74be01e058643","name":"exit: start","mode":"link","links":["271f9b721bb67856","3b9279380dcab618"],"x":935,"y":340,"wires":[]},{"id":"9713ad91985255a2","type":"link out","z":"c0b74be01e058643","name":"exit: end","mode":"link","links":["38feeeac68bec12b","985dad1c3753b605"],"x":735,"y":420,"wires":[]},{"id":"493d04ab3418fe9e","type":"link in","z":"c0b74be01e058643","name":"report: close","links":["509879f5282ce7f5","afd8c558614a98c7"],"x":765,"y":520,"wires":[["15a4a72dd7500d96"]]},{"id":"e48f3351b44214f8","type":"template","z":"c0b74be01e058643","name":"status: exit","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"fill\":\"yellow\",\"shape\":\"dot\",\"text\":\"exit\"}","output":"json","x":1150,"y":200,"wires":[[]]},{"id":"f57496fdf4a5e05a","type":"template","z":"c0b74be01e058643","name":"output: exit","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"type\":\"alarm\",\"event\":\"exit\",\"zone\":\"{{env.ALARM_ZONE_NAME}}\",\"delayMillis\":{{delay}}}","output":"json","x":1150,"y":240,"wires":[[]]},{"id":"e8acccc2a7a1744a","type":"template","z":"c0b74be01e058643","name":"output: armed","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"type\":\"alarm\",\"event\":\"armed\",\"zone\":\"{{env.ALARM_ZONE_NAME}}\"}","output":"json","x":1160,"y":340,"wires":[[]]},{"id":"3b9279380dcab618","type":"link in","z":"c0b74be01e058643","name":"status: exit","links":["666570f45623db25"],"x":1035,"y":220,"wires":[["e48f3351b44214f8","f57496fdf4a5e05a"]]},{"id":"376997d5b36f3ffd","type":"link in","z":"c0b74be01e058643","name":"status: entry","links":["cfd7852eeb7087d6"],"x":1035,"y":420,"wires":[["d29c5bc9a97c0cc7","34e303aaf008b154"]]},{"id":"9d680251d93b0ea6","type":"link in","z":"c0b74be01e058643","name":"status: alarm","links":["31a435d2f1cc7772","6e9b4e0a3027c142"],"x":1035,"y":520,"wires":[["cd88479938936680","8b62de9b8c7e1e21"]]},{"id":"2f3030acedf40d95","type":"template","z":"c0b74be01e058643","name":"output: fault","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"type\":\"alarm\",\"event\":\"{{payload.event}}\",\"zone\":\"{{env.ALARM_ZONE_NAME}}\",\"sensor\":\"{{payload.sensor}}\"}","output":"json","x":1150,"y":700,"wires":[[]]},{"id":"6bf52291a7f40876","type":"link in","z":"c0b74be01e058643","name":"status: fault","links":["3a6775a43c1b4f3b"],"x":1035,"y":700,"wires":[["2f3030acedf40d95"]]},{"id":"3a6775a43c1b4f3b","type":"link out","z":"c0b74be01e058643","name":"security fault","mode":"link","links":["6bf52291a7f40876"],"x":475,"y":620,"wires":[]},{"id":"4a0d7bbcba614667","type":"template","z":"c0b74be01e058643","name":"status: reset","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"fill\":\"blue\",\"shape\":\"dot\",\"text\":\"reset\"}","output":"json","x":1150,"y":600,"wires":[[]]},{"id":"f206b685b6cf0761","type":"template","z":"c0b74be01e058643","name":"output: reset","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"type\":\"alarm\",\"event\":\"reset\",\"zone\":\"{{env.ALARM_ZONE_NAME}}\"}","output":"json","x":1150,"y":640,"wires":[[]]},{"id":"55891ae06ede3140","type":"link in","z":"c0b74be01e058643","name":"status: reset","links":["afd8c558614a98c7"],"x":1035,"y":620,"wires":[["4a0d7bbcba614667","f206b685b6cf0761"]]},{"id":"6e9b4e0a3027c142","type":"link out","z":"c0b74be01e058643","name":"report: out","mode":"link","links":["9d680251d93b0ea6"],"x":935,"y":620,"wires":[]},{"id":"31a435d2f1cc7772","type":"link out","z":"c0b74be01e058643","name":"alarm: start","mode":"link","links":["18fa87c1e4a121e6","9d680251d93b0ea6","271f9b721bb67856"],"x":935,"y":1080,"wires":[]},{"id":"cfd7852eeb7087d6","type":"link out","z":"c0b74be01e058643","name":"entry: start","mode":"link","links":["271f9b721bb67856","376997d5b36f3ffd"],"x":935,"y":920,"wires":[]},{"id":"b23f9e0456da2a66","type":"comment","z":"c0b74be01e058643","name":"alarm events","info":"","x":1150,"y":60,"wires":[]},{"id":"f513c9ba78d691ef","type":"rbe","z":"c0b74be01e058643","name":"mode","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload.event","topi":"topic","x":370,"y":240,"wires":[["8d22603e6fd37fc0"]]},{"id":"1c743c0fe0ee1a8d","type":"change","z":"c0b74be01e058643","name":"switch","rules":[{"t":"set","p":"payload.type","pt":"msg","to":"mode","tot":"str"},{"t":"set","p":"payload.event","pt":"msg","to":"$.payload.event = \"on\" ? \"arm\" : \"disarm\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":180,"wires":[["f513c9ba78d691ef"]]},{"id":"21a5afe76b4a833e","type":"change","z":"c0b74be01e058643","name":"close","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":740,"wires":[["25e384f70ebcddb0"]]},{"id":"698f2c539acf4b41","type":"change","z":"c0b74be01e058643","name":"open","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":780,"wires":[["25e384f70ebcddb0"]]},{"id":"271f9b721bb67856","type":"link in","z":"c0b74be01e058643","name":"shunt: close","links":["666570f45623db25","66a62d502fb03f37","cfd7852eeb7087d6","31a435d2f1cc7772"],"x":765,"y":740,"wires":[["21a5afe76b4a833e"]]},{"id":"38feeeac68bec12b","type":"link in","z":"c0b74be01e058643","name":"shunt: open","links":["9713ad91985255a2","afd8c558614a98c7"],"x":765,"y":780,"wires":[["698f2c539acf4b41"]]},{"id":"13630e363e48fa2f","type":"change","z":"c0b74be01e058643","name":"close","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":520,"wires":[["5d661cfc8eda178a"]]},{"id":"50393bbf1bdd8bae","type":"change","z":"c0b74be01e058643","name":"open","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":560,"wires":[["5d661cfc8eda178a"]]},{"id":"6e272782224f917e","type":"link in","z":"c0b74be01e058643","name":"armed: close","links":["2563710c67625f91"],"x":525,"y":520,"wires":[["13630e363e48fa2f"]]},{"id":"13ee263f0b196a6e","type":"link in","z":"c0b74be01e058643","name":"armed: open","links":["281d06944e9350b8"],"x":525,"y":560,"wires":[["50393bbf1bdd8bae"]]},{"id":"636d6116bad2f378","type":"comment","z":"c0b74be01e058643","name":"reset all timers on disarm","info":"","x":670,"y":60,"wires":[]},{"id":"18fa87c1e4a121e6","type":"link in","z":"c0b74be01e058643","name":"report: open","links":["31a435d2f1cc7772"],"x":765,"y":560,"wires":[["7b8caf94318c0ddc"]]},{"id":"e161c650971fd5d9","type":"comment","z":"c0b74be01e058643","name":"ignore if disarmed","info":"","x":590,"y":480,"wires":[]},{"id":"14fc8a9300cfc22d","type":"comment","z":"c0b74be01e058643","name":"report if alarm active","info":"","x":830,"y":480,"wires":[]},{"id":"49ddb32629f9edd9","type":"comment","z":"c0b74be01e058643","name":"ignore if entry/exit delay","info":"","x":840,"y":700,"wires":[]},{"id":"ad351c7ca4e01c36","type":"comment","z":"c0b74be01e058643","name":"disarmed","info":"","x":840,"y":220,"wires":[]},{"id":"0122249648ea5a2f","type":"comment","z":"c0b74be01e058643","name":"armed","info":"","x":830,"y":260,"wires":[]},{"id":"9dd653a6f35bec97","type":"switch","z":"c0b74be01e058643","name":"sensor type","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"contact","vt":"str"},{"t":"eq","v":"security","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":190,"y":540,"wires":[["7624d508b571cc97"],["47d7eeae894d8a81"]]},{"id":"329398f0b0225c53","type":"change","z":"c0b74be01e058643","name":"button","rules":[{"t":"set","p":"payload.type","pt":"msg","to":"mode","tot":"str"},{"t":"set","p":"payload.event","pt":"msg","to":"$.payload.state = \"off\" ? \"arm\" : \"disarm\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":140,"wires":[["f513c9ba78d691ef"]]},{"id":"23e2bb176cbcbbe7","type":"comment","z":"c0b74be01e058643","name":"ignore isolated","info":"","x":200,"y":340,"wires":[]},{"id":"434908223452e947","type":"switch","z":"c0b74be01e058643","name":"isolated?","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"$exists($.payload.isolated) and $.payload.isolated","vt":"jsonata"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":180,"y":380,"wires":[[],["9dd653a6f35bec97"]]},{"id":"519c84c3608dac10","type":"change","z":"c0b74be01e058643","name":"entry delay","rules":[{"t":"set","p":"defaultDelaySeconds","pt":"msg","to":"ALARM_ZONE_ENTRY_DELAY_SECS","tot":"env"},{"t":"set","p":"delaySeconds","pt":"msg","to":"$exists($.payload.entryDelaySeconds) ? $.payload.entryDelaySeconds : $.defaultDelaySeconds","tot":"jsonata"},{"t":"set","p":"delay","pt":"msg","to":"$.delaySeconds * 1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":960,"wires":[["cf3e8ec375c5c64e"]]},{"id":"312f7a09db17f9a0","type":"change","z":"c0b74be01e058643","name":"alarm duration","rules":[{"t":"set","p":"defaultDelaySeconds","pt":"msg","to":"ALARM_ZONE_ALARM_DURATION_SECS","tot":"env"},{"t":"set","p":"delaySeconds","pt":"msg","to":"$exists($.payload.alarmDurationSeconds) ? $.payload.alarmDurationSeconds : $.defaultDelaySeconds","tot":"jsonata"},{"t":"set","p":"delay","pt":"msg","to":"$.delaySeconds * 1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":1100,"wires":[["cb657b7e9bef9311"]]},{"id":"430ec97a68668b18","type":"change","z":"c0b74be01e058643","name":"exit delay","rules":[{"t":"set","p":"defaultDelaySeconds","pt":"msg","to":"ALARM_ZONE_EXIT_DELAY_SECS","tot":"env"},{"t":"set","p":"delaySeconds","pt":"msg","to":"$exists($.payload.exitDelaySeconds) ? $.payload.exitDelaySeconds : $.defaultDelaySeconds","tot":"jsonata"},{"t":"set","p":"delay","pt":"msg","to":"$.delaySeconds * 1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":380,"wires":[["69431979c854ff7f"]]},{"id":"c7859e2816edf8e8","type":"switch","z":"c0b74be01e058643","name":"alarm always?","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"$exists($.payload.alarmAlways) and $.payload.alarmAlways","vt":"jsonata"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":740,"wires":[["cb5775e6f1bce2d3","b744bdcf93d7d8ce"],["89740f40d7aa003d"]]},{"id":"cb5775e6f1bce2d3","type":"change","z":"c0b74be01e058643","name":"arm alarm","rules":[{"t":"set","p":"payload.event","pt":"msg","to":"arm","tot":"str"},{"t":"set","p":"payload.exitDelaySeconds","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":840,"wires":[["bf754b38f97455fc"]]},{"id":"bf754b38f97455fc","type":"link out","z":"c0b74be01e058643","name":"link out 10","mode":"link","links":["b12ee4b2a119fca4"],"x":475,"y":840,"wires":[]},{"id":"b744bdcf93d7d8ce","type":"delay","z":"c0b74be01e058643","name":"10ms","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":610,"y":740,"wires":[["89740f40d7aa003d"]]},{"id":"b12ee4b2a119fca4","type":"link in","z":"c0b74be01e058643","name":"link in 4","links":["bf754b38f97455fc"],"x":285,"y":280,"wires":[["f513c9ba78d691ef"]]},{"id":"ac61c4a9ca5e078d","type":"comment","z":"c0b74be01e058643","name":"ignore armed mode","info":"","x":410,"y":700,"wires":[]},{"id":"0a1fd5e2a064671c","type":"comment","z":"c0b74be01e058643","name":"arm alarm in case not already","info":"","x":440,"y":800,"wires":[]},{"id":"5d661cfc8eda178a","type":"junction","z":"c0b74be01e058643","x":680,"y":540,"wires":[["89740f40d7aa003d"]]},{"id":"c000c052fd726e7a","type":"junction","z":"c0b74be01e058643","x":920,"y":540,"wires":[["dbed6a616ba6af47"]]},{"id":"25e384f70ebcddb0","type":"junction","z":"c0b74be01e058643","x":920,"y":760,"wires":[["a72878e54f739c8e"]]},{"id":"6b8afc92d8e616f4","type":"inject","z":"14bc2cf05e45878a","name":"test sensor","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"security\",\"event\":\"alarm\",\"sensor\":\"test\",\"entryDelaySeconds\":5,\"isolated\":false,\"alarmAlways\":false}","payloadType":"json","x":280,"y":1140,"wires":[["3bfd71d9a5df7a44"]]},{"id":"137f51ede9475b92","type":"inject","z":"14bc2cf05e45878a","name":"arm","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"mode\",\"event\":\"arm\",\"exitDelaySeconds\":5}","payloadType":"json","x":270,"y":1180,"wires":[["3bfd71d9a5df7a44"]]},{"id":"bfbc9b4a2e073b0b","type":"inject","z":"14bc2cf05e45878a","name":"disarm","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"mode\",\"event\":\"disarm\"}","payloadType":"json","x":270,"y":1220,"wires":[["3bfd71d9a5df7a44"]]},{"id":"3bfd71d9a5df7a44","type":"subflow:c0b74be01e058643","z":"14bc2cf05e45878a","name":"house","env":[{"name":"ALARM_ZONE_DELAY_SECS","value":"5","type":"num"}],"x":470,"y":1100,"wires":[["782b5f641c6859be","61b22fc3ebe502e7"]]},{"id":"61b22fc3ebe502e7","type":"debug","z":"14bc2cf05e45878a","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":480,"y":1160,"wires":[]}]

Flow Info

Created 2 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x14)
  • comment (x15)
  • debug (x1)
  • delay (x1)
  • inject (x3)
  • link in (x17)
  • link out (x11)
  • rbe (x1)
  • switch (x9)
  • template (x13)
  • trigger (x3)
Other
  • gate (x3)
  • junction (x3)
  • subflow (x1)
  • subflow:c0b74be01e058643 (x1)

Tags

  • security
  • alarm
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option