[ { "id": "78e2f572.71f74c", "type": "subflow", "name": "room_pir", "info": "", "category": "", "in": [ { "x": 137, "y": 179.0000057220459, "wires": [ { "id": "d715137.ff4d2f" }, { "id": "26cc49d7.f67c66" } ] } ], "out": [], "env": [ { "name": "ROOM", "type": "str", "value": "" }, { "name": "SENSOR_TOPIC", "type": "env", "value": "zigbee2mqtt/$(ROOM)_sensor" }, { "name": "LIGHTS_SET_TOPIC", "type": "env", "value": "zigbee2mqtt/$(ROOM)_lights/set" }, { "name": "LIGHTS_GET_TOPIC", "type": "env", "value": "zigbee2mqtt/$(ROOM)_lights/get" } ] }, { "id": "831905b7.d08f08", "type": "function", "z": "78e2f572.71f74c", "name": "translate_on_off", "func": "var msg_out = {};\n\nif (msg.payload.occupancy) {\n msg_out.payload = {state:\"ON\"};\n} else {\n msg_out.payload = {state:\"OFF\"};\n}\n\nnode.send(msg_out);", "outputs": 1, "noerr": 0, "x": 438.6666793823242, "y": 74.99998950958252, "wires": [ [ "d63adc7e.8c6d" ] ] }, { "id": "d63adc7e.8c6d", "type": "function", "z": "78e2f572.71f74c", "name": "delay_off", "func": "var timeout;\n\ntimeout = context.get('timeout');\nif (timeout) {\n clearTimeout(timeout);\n context.set('timeout', null);\n}\n\nif (msg.payload.state === \"ON\") {\n node.send(msg);\n} else {\n timeout = setTimeout(function() {\n node.send(msg);\n }, 1*60*1000);\n context.set('timeout', timeout);\n}", "outputs": 1, "noerr": 0, "x": 635.6666831970215, "y": 53.000003814697266, "wires": [ [ "82283ee3.6f9eb" ] ] }, { "id": "82283ee3.6f9eb", "type": "rbe", "z": "78e2f572.71f74c", "name": "", "func": "rbe", "gap": "", "start": "", "inout": "out", "property": "payload", "x": 811.6666831970215, "y": 80.66668701171875, "wires": [ [ "26cc49d7.f67c66", "d715137.ff4d2f" ] ] }, { "id": "26cc49d7.f67c66", "type": "debug", "z": "78e2f572.71f74c", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 714.0000228881836, "y": 288.99999713897705, "wires": [] }, { "id": "d715137.ff4d2f", "type": "mqtt out", "z": "78e2f572.71f74c", "name": "lights_set", "topic": "${LIGHTS_SET_TOPIC}", "qos": "2", "retain": "", "broker": "b20923dd.3cab2", "x": 1012.0001907348633, "y": 129, "wires": [] }, { "id": "a57a5e26.6c97f", "type": "mqtt in", "z": "78e2f572.71f74c", "name": "sensor", "topic": "${SENSOR_TOPIC}", "qos": "2", "datatype": "json", "broker": "b20923dd.3cab2", "x": 218.00000762939453, "y": 92.0000057220459, "wires": [ [ "831905b7.d08f08", "26cc49d7.f67c66" ] ] }, { "id": "b20923dd.3cab2", "type": "mqtt-broker", "z": "", "name": "mosquitto", "broker": "localhost", "port": "1883", "clientid": "", "usetls": false, "compatmode": true, "keepalive": "60", "cleansession": true, "birthTopic": "", "birthQos": "0", "birthPayload": "", "closeTopic": "", "closeQos": "0", "closePayload": "", "willTopic": "", "willQos": "0", "willPayload": "" }, { "id": "1bd984a7.b656db", "type": "subflow:78e2f572.71f74c", "z": "3fa9553c.71ffaa", "name": "kitchen_pir", "env": [ { "name": "ROOM", "type": "str", "value": "kitchen" }, { "name": "LIGHTS_GET_TOPIC", "type": "env", "value": "zigbee2mqtt/$(ROOM)_lights/get" } ], "x": 580.0000038146973, "y": 160.5000023841858, "wires": [] } ]