Этот небольшой поток услужливо включает свет, когда ты приходишь домой, а там достаточно темно. За выключение света отвечает этот поток.
Поток-то небольшой, а вот железок для реализации необходимо много:
Помимо этого нужен, понятно, Node-RED, а еще Zigbee2MQTT и MQTT-брокер! От так.
Это вторая версия потока, переосмысленная и полностью переписанная. Первая тут.
Узлы «mqtt in» подключаются к брокеру и подписываются на соответствующие темы. При получении сообщений, сохраняют их в потоковый контекст.
Основная цепочка запускается при срабатывании датчика присутствия, расположенного между дверьми в предбаннике, при этом учитывается освещенность в коридоре и направление прохода – домой или из дома. При выходе, если освещение было выключено, оно не включается, а при входе, включается только, если в коридоре недостаточная освещенность2).
[ { "id": "c4349e32af512e17", "type": "mqtt in", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Статус движения в предбаннике", "topic": "zigbee2mqtt/motionsensor/anteroom", "qos": "2", "datatype": "json", "broker": "1765f6372ba832dc", "nl": false, "rap": false, "inputs": 0, "x": 180, "y": 1100, "wires": [ [ "4236a0fa4248d8a5" ] ] }, { "id": "0704136eea9e2dd4", "type": "switch", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Маршрутизация", "property": "payload", "propertyType": "msg", "rules": [ { "t": "jsonata_exp", "v": "$not( $exists( cycle ) ) and\t$flowContext( \"statuses.motion.anteroom\" ) \tand $not( $flowContext( \"statuses.contact.corridor\" ) )", "vt": "jsonata" }, { "t": "jsonata_exp", "v": "$flowContext( \"statuses.motion.anteroom\" ) and \t$flowContext( \"statuses.illuminance.corridor\" ) <= $flowContext( \"settings.illuminance.corridor.min\" )\tand\t$flowContext( \"statuses.power.corridorlighting\" ) = \"OFF\" \tand $flowContext( \"statuses.contact.corridor\" )", "vt": "jsonata" }, { "t": "jsonata_exp", "v": "$flowContext( \"statuses.motion.anteroom\" ) and \t$flowContext( \"statuses.illuminance.corridor\" ) <= $flowContext( \"settings.illuminance.corridor.min\" )\tand\t$flowContext( \"statuses.power.corridorlighting\" ) = \"OFF\" \tand $not( $flowContext( \"statuses.contact.corridor\" ) )", "vt": "jsonata" } ], "checkall": "false", "repair": false, "outputs": 3, "x": 770, "y": 1160, "wires": [ [], [ "876d0caddd47e291" ], [ "d365e83a761d8643" ] ], "outputLabels": [ "Сброс", "Цикл", "Включить" ] }, { "id": "27640e667a8b4d62", "type": "mqtt in", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Статус двери в коридоре", "topic": "zigbee2mqtt/contactsensor/corridor", "qos": "2", "datatype": "json", "broker": "1765f6372ba832dc", "nl": false, "rap": false, "inputs": 0, "x": 160, "y": 1220, "wires": [ [ "59fa84aab3055391" ] ] }, { "id": "e189d282b85e2eb5", "type": "mqtt in", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Освещенность в коридоре", "topic": "zigbee2mqtt/lightsensor/corridor", "qos": "2", "datatype": "json", "broker": "1765f6372ba832dc", "nl": false, "rap": false, "inputs": 0, "x": 160, "y": 1160, "wires": [ [ "02fe415757945b3b" ] ] }, { "id": "02fe415757945b3b", "type": "change", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Сохранение освещенности", "rules": [ { "t": "set", "p": "statuses.illuminance.corridor", "pt": "flow", "to": "payload.illuminance_lux", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 460, "y": 1160, "wires": [ [] ] }, { "id": "59fa84aab3055391", "type": "change", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Сохранение положения двери", "rules": [ { "t": "set", "p": "statuses.contact.corridor", "pt": "flow", "to": "payload.contact", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 490, "y": 1220, "wires": [ [] ] }, { "id": "4236a0fa4248d8a5", "type": "change", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Сохранение статуса движения", "rules": [ { "t": "set", "p": "statuses.motion.anteroom", "pt": "flow", "to": "payload.occupancy", "tot": "msg" }, { "t": "move", "p": "payload.occupancy", "pt": "msg", "to": "occupancy", "tot": "msg" }, { "t": "delete", "p": "payload", "pt": "msg" }, { "t": "set", "p": "payload", "pt": "msg", "to": "true", "tot": "bool" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 530, "y": 1100, "wires": [ [ "fcce3189cd77fd1e" ] ], "outputLabels": [ "Включить" ] }, { "id": "2c55e1a3168c9aa8", "type": "delay", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Задержка цикла", "pauseType": "delay", "timeout": "500", "timeoutUnits": "milliseconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 390, "y": 1280, "wires": [ [ "797916b2055f0ea4" ] ] }, { "id": "fcce3189cd77fd1e", "type": "rbe", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Фильтр повторов", "func": "rbe", "gap": "", "start": "", "inout": "out", "septopics": false, "property": "occupancy", "topi": "topic", "x": 830, "y": 1100, "wires": [ [ "0704136eea9e2dd4" ] ] }, { "id": "d365e83a761d8643", "type": "mqtt out", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Публикация сообщения", "topic": "corridorlighting_0F7B7C/cmnd/POWER", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "1765f6372ba832dc", "x": 810, "y": 1220, "wires": [] }, { "id": "c2ba3d63d4da7060", "type": "change", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Метка цикла", "rules": [ { "t": "set", "p": "cycle", "pt": "msg", "to": "true", "tot": "bool" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 190, "y": 1280, "wires": [ [ "2c55e1a3168c9aa8" ] ] }, { "id": "797916b2055f0ea4", "type": "link out", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "link out 1", "mode": "link", "links": [ "fb1f6dbaeeb54ccf" ], "x": 525, "y": 1280, "wires": [] }, { "id": "fb1f6dbaeeb54ccf", "type": "link in", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "link in 1", "links": [ "797916b2055f0ea4" ], "x": 625, "y": 1160, "wires": [ [ "0704136eea9e2dd4" ] ] }, { "id": "876d0caddd47e291", "type": "link out", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "link out 2", "mode": "link", "links": [ "2431a0af2b14fb59" ], "x": 905, "y": 1160, "wires": [] }, { "id": "2431a0af2b14fb59", "type": "link in", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "link in 2", "links": [ "876d0caddd47e291" ], "x": 55, "y": 1280, "wires": [ [ "c2ba3d63d4da7060" ] ] }, { "id": "32f80887aa4f339d", "type": "change", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Настройки включения", "rules": [ { "t": "set", "p": "settings.illuminance.corridor.min", "pt": "flow", "to": "6", "tot": "num" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 820, "y": 1280, "wires": [ [] ] }, { "id": "1f3f938eb897d149", "type": "inject", "z": "b18e26a3.abdb68", "g": "61a1b296ea12dbcc", "name": "Запуск", "props": [], "repeat": "", "crontab": "", "once": true, "onceDelay": "0.1", "topic": "", "x": 640, "y": 1280, "wires": [ [ "32f80887aa4f339d" ] ] }, { "id": "1765f6372ba832dc", "type": "mqtt-broker", "name": "localhost", "broker": "localhost", "port": "1883", "clientid": "", "autoConnect": true, "usetls": false, "protocolVersion": "4", "keepalive": "60", "cleansession": true, "autoUnsubscribe": true, "birthTopic": "", "birthQos": "0", "birthRetain": "false", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closeQos": "0", "closeRetain": "false", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willRetain": "false", "willPayload": "", "willMsg": {}, "userProps": "", "sessionExpiry": "" } ]
Обсуждение