Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- {
- "id": "2f9ce9ec.85a026",
- "type": "tab",
- "label": "Alarm (TEST)",
- "disabled": false,
- "info": "## **Flow for alarm automations**\n**By Anders Lukic**\n\n---\n<br>\n\n---\n\n### **Purpose and functionality**\n\n---\n\n\nThis flow include automations that:\n\n - Sends an actionable notification if doors or windows are opened when nobody is home\n - Ability to trigger alarm via notification \n - Ability to play TTS message via notification\n - Plays alarm sound on SONOS speakers and blinks light red when alarm is triggered\n - Stop alarm sound and light blink when alarm is disabled\n \n---\n### **Requirements**\n---\nThis flow requires the following additional configuration to work:\n\n * Definition of IOS push categories for actionable notification\n * Definition of group with persons to track home/away status for"
- },
- {
- "id": "77832b55.c034f4",
- "type": "trigger-state",
- "z": "2f9ce9ec.85a026",
- "name": "Door or window is opened when nobody is home?",
- "server": "3bebce79.1e0962",
- "exposeToHomeAssistant": false,
- "haConfig": [
- {
- "property": "name",
- "value": ""
- },
- {
- "property": "icon",
- "value": ""
- }
- ],
- "entityid": "binary_sensor.openclose",
- "entityidfiltertype": "substring",
- "debugenabled": false,
- "constraints": [
- {
- "targetType": "this_entity",
- "targetValue": "",
- "propertyType": "property",
- "comparatorType": "is",
- "comparatorValueDatatype": "str",
- "comparatorValue": "opening",
- "propertyValue": "new_state.attributes.device_class"
- },
- {
- "targetType": "this_entity",
- "targetValue": "",
- "propertyType": "current_state",
- "comparatorType": "is",
- "comparatorValueDatatype": "str",
- "comparatorValue": "on",
- "propertyValue": "new_state.state"
- },
- {
- "targetType": "entity_id",
- "targetValue": "group.alle_personer",
- "propertyType": "current_state",
- "comparatorType": "is",
- "comparatorValueDatatype": "str",
- "comparatorValue": "not_home",
- "propertyValue": "new_state.state"
- }
- ],
- "outputs": 2,
- "customoutputs": [],
- "outputinitially": false,
- "state_type": "str",
- "x": 210,
- "y": 80,
- "wires": [
- [
- "26dce690.260d3a"
- ],
- []
- ]
- },
- {
- "id": "16f98877.8b8418",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Send critical notification",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": true,
- "service_domain": "notify",
- "service": "mobile_app_anders_iphone",
- "entityId": "",
- "data": "{\"title\":\"Dør/vindue åbnet\",\"message\":\"Følgende døre eller vinduer åbnet, mens I ikke er hjemme: \\n\\n {{payload}} \\n\\n\",\"data\":{\"push\":{\"category\":\"camera1\"},\"sound\":{\"name\":\"default\",\"critical\":1,\"volume\":0},\"attachment\":{\"content-type\":\"jpeg\"},\"entity_id\":\"camera.mycamera\"}}",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 1130,
- "y": 80,
- "wires": [
- []
- ]
- },
- {
- "id": "26dce690.260d3a",
- "type": "ha-get-entities",
- "z": "2f9ce9ec.85a026",
- "server": "3bebce79.1e0962",
- "name": "Get all open doors/windows",
- "rules": [
- {
- "property": "state",
- "logic": "is",
- "value": "on",
- "valueType": "str"
- },
- {
- "property": "attributes.device_class",
- "logic": "is",
- "value": "opening",
- "valueType": "str"
- },
- {
- "property": "entity_id",
- "logic": "starts_with",
- "value": "binary_sensor.openclose",
- "valueType": "str"
- }
- ],
- "output_type": "split",
- "output_empty_results": false,
- "output_location_type": "msg",
- "output_location": "payload",
- "output_results_count": 1,
- "x": 540,
- "y": 80,
- "wires": [
- [
- "9447d949.311778"
- ]
- ]
- },
- {
- "id": "9447d949.311778",
- "type": "template",
- "z": "2f9ce9ec.85a026",
- "name": "Entity names",
- "field": "payload",
- "fieldType": "msg",
- "format": "handlebars",
- "syntax": "mustache",
- "template": "{{payload.attributes.friendly_name}}",
- "output": "str",
- "x": 750,
- "y": 80,
- "wires": [
- [
- "cbe4acf3.33b"
- ]
- ]
- },
- {
- "id": "cbe4acf3.33b",
- "type": "join",
- "z": "2f9ce9ec.85a026",
- "name": "Combine names",
- "mode": "custom",
- "build": "string",
- "property": "payload",
- "propertyType": "msg",
- "key": "topic",
- "joiner": "[92,110]",
- "joinerType": "bin",
- "accumulate": false,
- "timeout": "",
- "count": "",
- "reduceRight": false,
- "reduceExp": "",
- "reduceInit": "",
- "reduceInitType": "",
- "reduceFixup": "",
- "x": 920,
- "y": 80,
- "wires": [
- [
- "16f98877.8b8418"
- ]
- ]
- },
- {
- "id": "6a1bfc6c.073064",
- "type": "comment",
- "z": "2f9ce9ec.85a026",
- "name": "Send actionable notification if doors and windows are opened when nobody is home",
- "info": "",
- "x": 310,
- "y": 40,
- "wires": []
- },
- {
- "id": "ffea8cbc.2b2ef",
- "type": "server-events",
- "z": "2f9ce9ec.85a026",
- "name": "IOS Action?",
- "server": "3bebce79.1e0962",
- "event_type": "ios.notification_action_fired",
- "exposeToHomeAssistant": false,
- "haConfig": [
- {
- "property": "name",
- "value": ""
- },
- {
- "property": "icon",
- "value": ""
- }
- ],
- "x": 90,
- "y": 190,
- "wires": [
- [
- "28ccc57b.53320a"
- ]
- ]
- },
- {
- "id": "28ccc57b.53320a",
- "type": "switch",
- "z": "2f9ce9ec.85a026",
- "name": "Resonse to alert?",
- "property": "payload.event.actionName",
- "propertyType": "msg",
- "rules": [
- {
- "t": "eq",
- "v": "START_ALARM",
- "vt": "str"
- },
- {
- "t": "eq",
- "v": "STOP_ALARM",
- "vt": "str"
- },
- {
- "t": "eq",
- "v": "NOTIFY_TTS",
- "vt": "str"
- }
- ],
- "checkall": "false",
- "repair": false,
- "outputs": 3,
- "x": 270,
- "y": 190,
- "wires": [
- [
- "490a46f8.838258"
- ],
- [
- "97b6a00a.3cb57"
- ],
- [
- "94155e86.d2e45",
- "c9a6a399.68411",
- "490a46f8.838258"
- ]
- ],
- "outputLabels": [
- "Remind me later",
- "Postpone cleaning",
- "Clean selected rooms only"
- ]
- },
- {
- "id": "94155e86.d2e45",
- "type": "debug",
- "z": "2f9ce9ec.85a026",
- "name": "",
- "active": true,
- "tosidebar": true,
- "console": false,
- "tostatus": false,
- "complete": "payload.event.response_info",
- "targetType": "msg",
- "statusVal": "",
- "statusType": "auto",
- "x": 580,
- "y": 290,
- "wires": []
- },
- {
- "id": "e8ba80a8.ddcfb",
- "type": "inject",
- "z": "2f9ce9ec.85a026",
- "name": "Test notification",
- "props": [
- {
- "p": "payload"
- }
- ],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "payload": "test vindue",
- "payloadType": "str",
- "x": 920,
- "y": 130,
- "wires": [
- [
- "16f98877.8b8418"
- ]
- ]
- },
- {
- "id": "da56994e.189b78",
- "type": "inject",
- "z": "2f9ce9ec.85a026",
- "name": "Test TTS",
- "props": [
- {
- "p": "payload.event.response_info",
- "v": "Test af alarm",
- "vt": "str"
- }
- ],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "payloadType": "str",
- "x": 300,
- "y": 240,
- "wires": [
- [
- "c9a6a399.68411"
- ]
- ]
- },
- {
- "id": "490a46f8.838258",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Trigger alarm",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "alarm_control_panel",
- "service": "alarm_trigger",
- "entityId": "alarm_control_panel.alarm",
- "data": "",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 510,
- "y": 140,
- "wires": [
- []
- ]
- },
- {
- "id": "97b6a00a.3cb57",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Disable alarm",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "alarm_control_panel",
- "service": "alarm_disarm",
- "entityId": "alarm_control_panel.alarm",
- "data": "",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 520,
- "y": 190,
- "wires": [
- []
- ]
- },
- {
- "id": "840f0cb5.e2fb5",
- "type": "trigger-state",
- "z": "2f9ce9ec.85a026",
- "name": "Alarm triggered",
- "server": "3bebce79.1e0962",
- "exposeToHomeAssistant": false,
- "haConfig": [
- {
- "property": "name",
- "value": ""
- },
- {
- "property": "icon",
- "value": ""
- }
- ],
- "entityid": "alarm_control_panel.alarm",
- "entityidfiltertype": "exact",
- "debugenabled": false,
- "constraints": [
- {
- "targetType": "this_entity",
- "targetValue": "",
- "propertyType": "current_state",
- "comparatorType": "is",
- "comparatorValueDatatype": "str",
- "comparatorValue": "triggered",
- "propertyValue": "new_state.state"
- }
- ],
- "outputs": 2,
- "customoutputs": [],
- "outputinitially": false,
- "state_type": "str",
- "x": 100,
- "y": 370,
- "wires": [
- [
- "a0335306.d4f64",
- "a210e8b1.4e5f08"
- ],
- [
- "a210e8b1.4e5f08"
- ]
- ]
- },
- {
- "id": "cb84e7b0.af00f8",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Snapshot",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "sonos",
- "service": "snapshot",
- "entityId": "{{ sonos_data.sonos_entity }}",
- "data": "",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 680,
- "y": 240,
- "wires": [
- [
- "ee3feb43.7a0f78"
- ]
- ]
- },
- {
- "id": "ee3feb43.7a0f78",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Unjoin",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "sonos",
- "service": "unjoin",
- "entityId": "{{ sonos_data.sonos_entity }}",
- "data": "",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 810,
- "y": 240,
- "wires": [
- [
- "9976c37a.02441"
- ]
- ]
- },
- {
- "id": "9976c37a.02441",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Volume",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "media_player",
- "service": "volume_set",
- "entityId": "{{ sonos_data.sonos_entity }}",
- "data": "{\"volume_level\":\"{{ sonos_data.volume }}\"}",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 940,
- "y": 240,
- "wires": [
- [
- "f6cddf03.12cb9"
- ]
- ]
- },
- {
- "id": "f6cddf03.12cb9",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "TTS",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "tts",
- "service": "google_translate_say",
- "entityId": "{{ sonos_data.sonos_entity }}",
- "data": "{\"message\":\"{{{sonos_data.message}}}\",\"language\":\"da\"}",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 1070,
- "y": 240,
- "wires": [
- [
- "eaaf75e7.fc5368"
- ]
- ]
- },
- {
- "id": "ef912700.648808",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Restore",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "sonos",
- "service": "restore",
- "entityId": "{{ sonos_data.sonos_entity }}",
- "data": "",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 1320,
- "y": 240,
- "wires": [
- []
- ]
- },
- {
- "id": "eaaf75e7.fc5368",
- "type": "delay",
- "z": "2f9ce9ec.85a026",
- "name": "Delay",
- "pauseType": "delayv",
- "timeout": "10",
- "timeoutUnits": "seconds",
- "rate": "1",
- "nbRateUnits": "1",
- "rateUnits": "second",
- "randomFirst": "1",
- "randomLast": "5",
- "randomUnits": "seconds",
- "drop": false,
- "x": 1190,
- "y": 240,
- "wires": [
- [
- "ef912700.648808"
- ]
- ]
- },
- {
- "id": "c9a6a399.68411",
- "type": "template",
- "z": "2f9ce9ec.85a026",
- "name": "TTS variables",
- "field": "sonos_data",
- "fieldType": "msg",
- "format": "json",
- "syntax": "mustache",
- "template": "{\n \"sonos_entity\": \"media_player.kontor\",\n \"volume\": \"0.5\",\n \"message\": \"{{payload.event.response_info}}\"\n}",
- "output": "json",
- "x": 520,
- "y": 240,
- "wires": [
- [
- "cb84e7b0.af00f8"
- ]
- ]
- },
- {
- "id": "a0335306.d4f64",
- "type": "template",
- "z": "2f9ce9ec.85a026",
- "name": "Alarm variables",
- "field": "sonos_data",
- "fieldType": "msg",
- "format": "json",
- "syntax": "mustache",
- "template": "{\n \"sonos_entity\": \"media_player.kontor\",\n \"volume\": \"0.5\",\n \"filename\": \"https://[myHAURL]/local/assets/sound/alarm.mp3\"\n}",
- "output": "json",
- "x": 300,
- "y": 370,
- "wires": [
- [
- "6839d122.93169"
- ]
- ]
- },
- {
- "id": "58f75663.6c2cd8",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Alarm",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "media_player",
- "service": "play_media",
- "entityId": "{{ sonos_data.sonos_entity }}",
- "data": "{\"media_content_id\":\"{{{sonos_data.filename}}}\",\"media_content_type\":\"music\"}",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 770,
- "y": 370,
- "wires": [
- []
- ]
- },
- {
- "id": "6839d122.93169",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Volume",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "media_player",
- "service": "volume_set",
- "entityId": "{{ sonos_data.sonos_entity }}",
- "data": "{\"volume_level\":\"{{ sonos_data.volume }}\"}",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 470,
- "y": 370,
- "wires": [
- [
- "650f90ac.1d0f9",
- "c54cffa8.0c726"
- ]
- ]
- },
- {
- "id": "650f90ac.1d0f9",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Repeat",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "media_player",
- "service": "repeat_set",
- "entityId": "{{ sonos_data.sonos_entity }}",
- "data": "{\"repeat\":\"one\"}",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 630,
- "y": 370,
- "wires": [
- [
- "58f75663.6c2cd8"
- ]
- ]
- },
- {
- "id": "52fcd0c0.42329",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Trigger alarm",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "alarm_control_panel",
- "service": "alarm_trigger",
- "entityId": "alarm_control_panel.alarm",
- "data": "",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 310,
- "y": 730,
- "wires": [
- []
- ]
- },
- {
- "id": "f10f278e.07e9b8",
- "type": "inject",
- "z": "2f9ce9ec.85a026",
- "name": "Trigger alarm",
- "props": [
- {
- "p": "payload.event.response_info",
- "v": "Test af alarm",
- "vt": "str"
- }
- ],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "x": 120,
- "y": 730,
- "wires": [
- [
- "52fcd0c0.42329"
- ]
- ]
- },
- {
- "id": "bec6943a.ab9ef8",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Disable alarm",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "alarm_control_panel",
- "service": "alarm_disarm",
- "entityId": "alarm_control_panel.alarm",
- "data": "",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 320,
- "y": 780,
- "wires": [
- []
- ]
- },
- {
- "id": "f38e5778.9bf7a8",
- "type": "inject",
- "z": "2f9ce9ec.85a026",
- "name": "Disable alarm",
- "props": [
- {
- "p": "payload.event.response_info",
- "v": "Test af alarm",
- "vt": "str"
- }
- ],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "payloadType": "str",
- "x": 120,
- "y": 780,
- "wires": [
- [
- "bec6943a.ab9ef8"
- ]
- ]
- },
- {
- "id": "7d91e862.348988",
- "type": "comment",
- "z": "2f9ce9ec.85a026",
- "name": "Alarm triggered",
- "info": "",
- "x": 100,
- "y": 330,
- "wires": []
- },
- {
- "id": "67ba49d3.e3a968",
- "type": "template",
- "z": "2f9ce9ec.85a026",
- "name": "Disable variables",
- "field": "sonos_data",
- "fieldType": "msg",
- "format": "json",
- "syntax": "mustache",
- "template": "{\n \"sonos_entity\": \"media_player.kontor\",\n \"volume\": \"0.4\"\n}",
- "output": "json",
- "x": 330,
- "y": 610,
- "wires": [
- [
- "d7e346ff.942a58",
- "21dc9f2d.ddd4"
- ]
- ]
- },
- {
- "id": "30dd7656.bcd85a",
- "type": "trigger-state",
- "z": "2f9ce9ec.85a026",
- "name": "Alarm disabled",
- "server": "3bebce79.1e0962",
- "exposeToHomeAssistant": false,
- "haConfig": [
- {
- "property": "name",
- "value": ""
- },
- {
- "property": "icon",
- "value": ""
- }
- ],
- "entityid": "alarm_control_panel.alarm",
- "entityidfiltertype": "exact",
- "debugenabled": false,
- "constraints": [
- {
- "targetType": "this_entity",
- "targetValue": "",
- "propertyType": "previous_state",
- "comparatorType": "is",
- "comparatorValueDatatype": "str",
- "comparatorValue": "triggered",
- "propertyValue": "old_state.state"
- }
- ],
- "outputs": 2,
- "customoutputs": [],
- "outputinitially": false,
- "state_type": "str",
- "x": 100,
- "y": 610,
- "wires": [
- [
- "67ba49d3.e3a968"
- ],
- []
- ]
- },
- {
- "id": "597e8bab.8ff4d4",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Volume",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "media_player",
- "service": "volume_set",
- "entityId": "{{ sonos_data.sonos_entity }}",
- "data": "{\"volume_level\":\"{{ sonos_data.volume }}\"}",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 710,
- "y": 610,
- "wires": [
- []
- ]
- },
- {
- "id": "d7e346ff.942a58",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Stop Alarm",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "media_player",
- "service": "media_stop",
- "entityId": "{{ sonos_data.sonos_entity }}",
- "data": "",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 560,
- "y": 610,
- "wires": [
- [
- "597e8bab.8ff4d4"
- ]
- ]
- },
- {
- "id": "9195563e.8022c8",
- "type": "comment",
- "z": "2f9ce9ec.85a026",
- "name": "Alarm disabled after being triggered",
- "info": "",
- "x": 160,
- "y": 570,
- "wires": []
- },
- {
- "id": "6bfdf45b.ab910c",
- "type": "comment",
- "z": "2f9ce9ec.85a026",
- "name": "TEST: Trigger and disable alarm",
- "info": "",
- "x": 150,
- "y": 690,
- "wires": []
- },
- {
- "id": "a210e8b1.4e5f08",
- "type": "debug",
- "z": "2f9ce9ec.85a026",
- "name": "",
- "active": true,
- "tosidebar": true,
- "console": false,
- "tostatus": false,
- "complete": "false",
- "statusVal": "",
- "statusType": "auto",
- "x": 290,
- "y": 420,
- "wires": []
- },
- {
- "id": "dccd982a.64f298",
- "type": "api-call-service",
- "z": "2f9ce9ec.85a026",
- "name": "Light blink",
- "server": "3bebce79.1e0962",
- "version": 1,
- "debugenabled": false,
- "service_domain": "light",
- "service": "turn_on",
- "entityId": "light.kokken",
- "data": "{\"flash\":\"short\",\"transition\":0,\"rgb_color\":[252,3,3]}",
- "dataType": "json",
- "mergecontext": "",
- "output_location": "",
- "output_location_type": "none",
- "mustacheAltTags": false,
- "x": 1070,
- "y": 470,
- "wires": [
- []
- ]
- },
- {
- "id": "8b329bec.5475b8",
- "type": "inject",
- "z": "2f9ce9ec.85a026",
- "name": "Test blink",
- "props": [],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "payloadType": "str",
- "x": 470,
- "y": 470,
- "wires": [
- [
- "c54cffa8.0c726"
- ]
- ]
- },
- {
- "id": "644bc868.057528",
- "type": "function",
- "z": "2f9ce9ec.85a026",
- "name": "loop",
- "func": "// Loop function\n// Top output provides triger for next actions\n// Botton output should be connected to the input through a dealy\n// The msg.payload can consis one of actions: start, stop, toggle\n// Other content is ignored\n// On the outoput the msg.payload contains current loop state\n\ncontext.loop = context.loop || \"stop\";\ncontext.loops = context.loops || 0;\n\n//console.log(\"topic :\" + msg.topic);\n//console.log(\"loop :\" + context.loop);\n//console.log(\"loops :\" + context.loops);\n//console.log(\"action:\" + msg.payload);\n\nswitch (msg.payload) {\n\tcase \"stop\":\n\t\tcontext.loops = context.loops + 1;\n\t\tmsg.payload = \"stopped\";\n\t\tcontext.loop = \"stop\";\n\t\treturn [msg,null];\n\tcase \"toggle\":\n\t\tif (context.loop == \"start\") {\n\t\t\tmsg.payload = \"stopped\";\n\t\t\tcontext.loop = \"stop\";\n\t\t\treturn [msg,null];\n\t\t} else {\n\t\t\tmsg.payload = \"started\";\n\t\t\tcontext.loop = \"loop\";\n\t\t\tcontext.loops = 1;\n\t\t\treturn [msg,msg];\n\t\t}\n\tcase \"start\":\n\t\tmsg.payload = \"started\";\n\t\tcontext.loop = \"loop\";\n\t\tcontext.loops = 1;\n\t\treturn [msg,msg];\n\tdefault:\n\t\tif (context.loop == \"loop\") {\n\t\t\tcontext.loops = context.loops + 1;\n\t\t\tmsg.payload = \"loop:\" + context.loops;\n\t\t\treturn [msg,msg];\n\t\t} else {\n\t\t\treturn [null,null]; \n\t\t}\n}",
- "outputs": "2",
- "noerr": 0,
- "initialize": "",
- "finalize": "",
- "x": 900,
- "y": 470,
- "wires": [
- [
- "dccd982a.64f298"
- ],
- [
- "72efe33b.ba9e3c"
- ]
- ]
- },
- {
- "id": "72efe33b.ba9e3c",
- "type": "delay",
- "z": "2f9ce9ec.85a026",
- "name": "",
- "pauseType": "delay",
- "timeout": "2",
- "timeoutUnits": "seconds",
- "rate": "1",
- "nbRateUnits": "",
- "rateUnits": "second",
- "randomFirst": "1",
- "randomLast": "5",
- "randomUnits": "seconds",
- "drop": false,
- "x": 900,
- "y": 530,
- "wires": [
- [
- "644bc868.057528"
- ]
- ]
- },
- {
- "id": "c54cffa8.0c726",
- "type": "change",
- "z": "2f9ce9ec.85a026",
- "name": "Start loop",
- "rules": [
- {
- "t": "set",
- "p": "payload",
- "pt": "msg",
- "to": "start",
- "tot": "str"
- }
- ],
- "action": "",
- "property": "",
- "from": "",
- "to": "",
- "reg": false,
- "x": 660,
- "y": 470,
- "wires": [
- [
- "644bc868.057528"
- ]
- ]
- },
- {
- "id": "21dc9f2d.ddd4",
- "type": "change",
- "z": "2f9ce9ec.85a026",
- "name": "Stop loop",
- "rules": [
- {
- "t": "set",
- "p": "payload",
- "pt": "msg",
- "to": "stop",
- "tot": "str"
- }
- ],
- "action": "",
- "property": "",
- "from": "",
- "to": "",
- "reg": false,
- "x": 660,
- "y": 530,
- "wires": [
- [
- "644bc868.057528"
- ]
- ]
- },
- {
- "id": "eb18f41f.26b4a8",
- "type": "inject",
- "z": "2f9ce9ec.85a026",
- "name": "Stop blink",
- "props": [],
- "repeat": "",
- "crontab": "",
- "once": false,
- "onceDelay": 0.1,
- "topic": "",
- "x": 470,
- "y": 530,
- "wires": [
- [
- "21dc9f2d.ddd4"
- ]
- ]
- },
- {
- "id": "3bebce79.1e0962",
- "type": "server",
- "name": "Home Assistant",
- "addon": true
- }
- ]
Add Comment
Please, Sign In to add comment