После установки, сперва микроволнового датчика движения, и последующей его замены на два инфракрасных, работающих в паре, в совмещенном санузле появилась задача грамотного и гибкого управления освещением и вентиляцией с большим количеством условий, где главные, это – вентиляция должна выключаться только если влажность в норме, а освещение должно подчиняться не телу человека, а его желанию… т.е. не всегда, когда человек находится в помещении, нужно включать свет.
При включении освещения и вентиляции с кнопки или из приложения, если не было движения, все автоматически выключится по таймеру, т.е. случайно включив в приложении что-то, но так и не дойдя до помещения, через установленный промежуток времени, в моем случае, это 5 минут, то, что было включено, автоматически выключится. Этот функционал был навеян последним случаем, когда мы уехали на неделю в отпуск, а каким-то чудом вентиляция оказалась включенной и тарахтела все это время…
Если после включения освещения и вентиляции появляется движение или движение было до включения, управление переходит к датчику движения – после прекращения движения запускается таймер, описанный выше и, если движения не появляется, выключает освещение и, если позволяют пороги влажности, вентиляцию. Далее вентиляция управляется по порогам.
При выключении освещения или вентиляции по датчику движения, запускается дополнительный таймер, в моем случае на 10 секунд, во время действия которого, если появляется движение, то, что было ранее выключено, включается обратно. Это сделано для любителей затаиться в «позе мыслителя».
По истечению вышеописанного таймера, датчик движения не инициализирует включение, ни освещения, ни вентиляции, что позволяет находиться в помещении с выключенным освещением и вентиляцией, если это необходимо – что случается у меня достаточно часто, как бы странно это не звучало.
При некотором желании, сюда можно подключить поток автоматической корректировки порогов влажности. Но я пока не стал заморачиваться, выставив вручную 70 и 90 процентов.
[ { "id": "b18e26a3.abdb68", "type": "tab", "label": "Вентиляция и освещение", "disabled": false, "info": "" }, { "id": "3819abb9.0655f4", "type": "group", "z": "b18e26a3.abdb68", "style": { "stroke": "#999999", "stroke-opacity": "1", "fill": "none", "fill-opacity": "1", "label": true, "label-position": "nw", "color": "#a4a4a4" }, "nodes": [ "8dc1f913.7c1be8", "1ca6c51a.a84bfb", "9641f718.2ef2b8", "3411c3.c4214e3e", "2b005b2b.52eb84", "ee50fb70.9ef358", "90578701.c67e78" ], "x": 14, "y": 559, "w": 932, "h": 142 }, { "id": "8c6f543.c72bba8", "type": "group", "z": "b18e26a3.abdb68", "style": { "stroke": "#999999", "stroke-opacity": "1", "fill": "none", "fill-opacity": "1", "label": true, "label-position": "nw", "color": "#a4a4a4" }, "nodes": [ "379acc8b.039564", "5ca297a1.cc2f18", "e06cd28e.9cec1", "6a9bbabd.83ee54" ], "x": 14, "y": 119, "w": 922, "h": 82 }, { "id": "adcaad18.c6376", "type": "group", "z": "b18e26a3.abdb68", "style": { "stroke": "#999999", "stroke-opacity": "1", "fill": "none", "fill-opacity": "1", "label": true, "label-position": "nw", "color": "#a4a4a4" }, "nodes": [ "da5d5b1f.c65968", "dfd3c8ff.af26b8" ], "x": 14, "y": 19, "w": 592, "h": 82 }, { "id": "b621e9dc.d9a628", "type": "group", "z": "b18e26a3.abdb68", "style": { "stroke": "#999999", "stroke-opacity": "1", "fill": "none", "fill-opacity": "1", "label": true, "label-position": "nw", "color": "#a4a4a4" }, "nodes": [ "23a24d9b.d59c32", "75dd7dc.868d284", "c337d54b.42fca8", "9801df40.8eaf", "e4432163.9f8fd", "f1fcfd21.d7158", "3565833d.d0ae0c", "5b2acd6f.cfd724", "a073baa6.ad14e8", "47a4ae91.ab2e8", "73484b4a.02ca14", "3c6e79.67586188", "95ef2769.22ba18", "2e0426c6.51b69a", "73e256bd.06ea38", "4ff36372.28fdac", "fc81cbf3.d9e598", "806b8b4f.fc9e28", "9706c5ee.ed90f8", "1eb4de14.948162" ], "x": 14, "y": 219, "w": 932, "h": 322 }, { "id": "23a24d9b.d59c32", "type": "mqtt in", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Статус датчика движения", "topic": "bathroomlighting_E8BC7B/stat/MOTION", "qos": "2", "datatype": "utf8", "broker": "8745b931.133868", "x": 150, "y": 260, "wires": [ [ "3565833d.d0ae0c" ] ] }, { "id": "75dd7dc.868d284", "type": "trigger", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Задержка выключения", "op1": "", "op2": "", "op1type": "nul", "op2type": "payl", "duration": "5", "extend": true, "overrideDelay": true, "units": "min", "reset": "1", "bytopic": "all", "topic": "topic", "outputs": 1, "x": 470, "y": 320, "wires": [ [ "3c6e79.67586188", "5b2acd6f.cfd724", "f1fcfd21.d7158" ] ] }, { "id": "c337d54b.42fca8", "type": "mqtt out", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Управление освещением", "topic": "bathroomlighting_E8BC7B/cmnd/POWER", "qos": "", "retain": "", "broker": "8745b931.133868", "x": 240, "y": 500, "wires": [] }, { "id": "379acc8b.039564", "type": "mqtt in", "z": "b18e26a3.abdb68", "g": "8c6f543.c72bba8", "name": "Телеметрия вентиляции", "topic": "ventilation_000457/tele/SENSOR", "qos": "2", "datatype": "json", "broker": "8745b931.133868", "x": 150, "y": 160, "wires": [ [ "5ca297a1.cc2f18" ] ] }, { "id": "5ca297a1.cc2f18", "type": "change", "z": "b18e26a3.abdb68", "g": "8c6f543.c72bba8", "name": "Настройка действия", "rules": [ { "t": "set", "p": "humidity", "pt": "flow", "to": "$round( payload.SI7021.Humidity, 0 )", "tot": "jsonata" }, { "t": "set", "p": "payload", "pt": "msg", "to": "payload.SI7021.Humidity > $flowContext( \"settings.ventilation.on\" ) ? 1 : payload.SI7021.Humidity < $flowContext( \"settings.ventilation.off\" ) ? 0", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 440, "y": 160, "wires": [ [ "e06cd28e.9cec1" ] ] }, { "id": "da5d5b1f.c65968", "type": "inject", "z": "b18e26a3.abdb68", "g": "adcaad18.c6376", "name": "Настройки порогов", "props": [ { "p": "ventilation.on", "v": "90", "vt": "num" }, { "p": "ventilation.off", "v": "70", "vt": "num" }, { "p": "switching.off", "v": "5", "vt": "num" }, { "p": "switching.on", "v": "10", "vt": "num" } ], "repeat": "", "crontab": "", "once": true, "onceDelay": "0.1", "topic": "", "payloadType": "str", "x": 160, "y": 60, "wires": [ [ "dfd3c8ff.af26b8" ] ], "info": "ventilation в процентах, switching.off в минутах (к примеру, 0.1 или 5), switching.on в секундах." }, { "id": "dfd3c8ff.af26b8", "type": "change", "z": "b18e26a3.abdb68", "g": "adcaad18.c6376", "name": "Перемещение в контекст", "rules": [ { "t": "move", "p": "ventilation", "pt": "msg", "to": "settings.ventilation", "tot": "flow" }, { "t": "set", "p": "switching.off", "pt": "msg", "to": "switching.off * 60000", "tot": "jsonata" }, { "t": "set", "p": "switching.on", "pt": "msg", "to": "switching.on * 1000", "tot": "jsonata" }, { "t": "move", "p": "switching", "pt": "msg", "to": "settings.switching", "tot": "flow" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 460, "y": 60, "wires": [ [] ] }, { "id": "9801df40.8eaf", "type": "mqtt out", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Управление вентиляцией", "topic": "ventilation_000457/cmnd/POWER", "qos": "", "retain": "", "broker": "8745b931.133868", "x": 800, "y": 500, "wires": [] }, { "id": "e4432163.9f8fd", "type": "change", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Настройка задержки", "rules": [ { "t": "set", "p": "delay", "pt": "msg", "to": "settings.switching.off", "tot": "flow" }, { "t": "set", "p": "payload", "pt": "msg", "to": "payload = \"ON\" ? 0 : payload = \"OFF\" ? 1 : payload", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 220, "y": 320, "wires": [ [ "75dd7dc.868d284" ] ] }, { "id": "e06cd28e.9cec1", "type": "rbe", "z": "b18e26a3.abdb68", "g": "8c6f543.c72bba8", "name": "Фильтрация повторов", "func": "rbe", "gap": "", "start": "", "inout": "out", "septopics": false, "property": "payload", "x": 700, "y": 160, "wires": [ [ "6a9bbabd.83ee54" ] ] }, { "id": "8dc1f913.7c1be8", "type": "mqtt in", "z": "b18e26a3.abdb68", "g": "3819abb9.0655f4", "name": "Состояние освещения", "topic": "bathroomlighting_E8BC7B/stat/POWER", "qos": "2", "datatype": "utf8", "broker": "8745b931.133868", "x": 140, "y": 600, "wires": [ [ "2b005b2b.52eb84" ] ] }, { "id": "f1fcfd21.d7158", "type": "switch", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Проверка порога вентиляции", "property": "humidity", "propertyType": "flow", "rules": [ { "t": "lt", "v": "settings.ventilation.off", "vt": "flow" } ], "checkall": "false", "repair": false, "outputs": 1, "x": 510, "y": 380, "wires": [ [ "a073baa6.ad14e8" ] ] }, { "id": "1ca6c51a.a84bfb", "type": "mqtt in", "z": "b18e26a3.abdb68", "g": "3819abb9.0655f4", "name": "Состояние вентиляции", "topic": "ventilation_000457/stat/POWER", "qos": "2", "datatype": "utf8", "broker": "8745b931.133868", "x": 140, "y": 660, "wires": [ [ "2b005b2b.52eb84" ] ] }, { "id": "9641f718.2ef2b8", "type": "change", "z": "b18e26a3.abdb68", "g": "3819abb9.0655f4", "name": "Сохранение состояний", "rules": [ { "t": "set", "p": "statuses.power", "pt": "flow", "to": "$merge( [ $flowContext( \"statuses.power\" ), { $.deviceName: payload } ] )", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 450, "y": 660, "wires": [ [ "ee50fb70.9ef358" ] ] }, { "id": "3411c3.c4214e3e", "type": "switch", "z": "b18e26a3.abdb68", "g": "3819abb9.0655f4", "name": "Проверка состояний питания", "property": "payload", "propertyType": "msg", "rules": [ { "t": "neq", "v": "$flowContext( \"statuses.power.\" & deviceName )", "vt": "jsonata" } ], "checkall": "false", "repair": false, "outputs": 1, "x": 790, "y": 600, "wires": [ [ "9641f718.2ef2b8" ] ] }, { "id": "2b005b2b.52eb84", "type": "change", "z": "b18e26a3.abdb68", "g": "3819abb9.0655f4", "name": "Именование сообщения", "rules": [ { "t": "set", "p": "deviceName", "pt": "msg", "to": "$substring( topic, 0, ( $length(topic) - 18 ) )", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 470, "y": 600, "wires": [ [ "3411c3.c4214e3e" ] ] }, { "id": "ee50fb70.9ef358", "type": "switch", "z": "b18e26a3.abdb68", "g": "3819abb9.0655f4", "name": "Проверка движения", "property": "1", "propertyType": "jsonata", "rules": [ { "t": "neq", "v": "statuses.motion", "vt": "flow" } ], "checkall": "false", "repair": false, "outputs": 1, "x": 720, "y": 660, "wires": [ [ "90578701.c67e78" ] ] }, { "id": "3565833d.d0ae0c", "type": "change", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Сохранение статуса", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$number( payload )", "tot": "jsonata" }, { "t": "set", "p": "statuses.motion", "pt": "flow", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 420, "y": 260, "wires": [ [ "e4432163.9f8fd", "2e0426c6.51b69a" ] ] }, { "id": "5b2acd6f.cfd724", "type": "switch", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Фильтр статуса освещения", "property": "payload = 1 ? \"ON\" : payload = 0 ? \"OFF\"", "propertyType": "jsonata", "rules": [ { "t": "neq", "v": "statuses.power.bathroomlighting", "vt": "flow" } ], "checkall": "false", "repair": false, "outputs": 1, "x": 160, "y": 380, "wires": [ [ "95ef2769.22ba18" ] ] }, { "id": "a073baa6.ad14e8", "type": "switch", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Фильтр статуса вентиляции", "property": "payload = 1 ? \"ON\" : payload = 0 ? \"OFF\"", "propertyType": "jsonata", "rules": [ { "t": "neq", "v": "statuses.power.ventilation", "vt": "flow" } ], "checkall": "false", "repair": false, "outputs": 1, "x": 440, "y": 440, "wires": [ [ "fc81cbf3.d9e598" ] ] }, { "id": "90578701.c67e78", "type": "link out", "z": "b18e26a3.abdb68", "g": "3819abb9.0655f4", "name": "", "links": [ "47a4ae91.ab2e8" ], "x": 895, "y": 660, "wires": [] }, { "id": "47a4ae91.ab2e8", "type": "link in", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "", "links": [ "90578701.c67e78" ], "x": 55, "y": 320, "wires": [ [ "e4432163.9f8fd" ] ] }, { "id": "73484b4a.02ca14", "type": "link in", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "", "links": [ "6a9bbabd.83ee54", "1eb4de14.948162" ], "x": 635, "y": 440, "wires": [ [ "9801df40.8eaf" ] ] }, { "id": "6a9bbabd.83ee54", "type": "link out", "z": "b18e26a3.abdb68", "g": "8c6f543.c72bba8", "name": "", "links": [ "73484b4a.02ca14" ], "x": 895, "y": 160, "wires": [] }, { "id": "3c6e79.67586188", "type": "change", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Настройка задержки", "rules": [ { "t": "set", "p": "delay", "pt": "msg", "to": "settings.switching.on", "tot": "flow" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 720, "y": 320, "wires": [ [ "73e256bd.06ea38" ] ] }, { "id": "95ef2769.22ba18", "type": "change", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Изменение режима", "rules": [ { "t": "set", "p": "statuses.switchOn.bathroomlighting", "pt": "flow", "to": "$exists( deviceName ) ? \"manual\" : \"auto\"", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 140, "y": 440, "wires": [ [ "c337d54b.42fca8", "8c124f67.6e463" ] ] }, { "id": "2e0426c6.51b69a", "type": "switch", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Включение по датчику", "property": "payload", "propertyType": "msg", "rules": [ { "t": "jsonata_exp", "v": "payload = 1 and $flowContext( \"statuses.switchOn.bathroomlighting\" ) = \"auto\"", "vt": "jsonata" }, { "t": "jsonata_exp", "v": "payload = 1 and $flowContext( \"statuses.switchOn.ventilation\" ) = \"auto\"", "vt": "jsonata" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 710, "y": 260, "wires": [ [ "806b8b4f.fc9e28" ], [ "1eb4de14.948162" ] ], "outputLabels": [ "На отвещение", "На вентиляцию" ] }, { "id": "73e256bd.06ea38", "type": "delay", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Задержка режима", "pauseType": "delayv", "timeout": "5", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "x": 830, "y": 380, "wires": [ [ "4ff36372.28fdac" ] ] }, { "id": "4ff36372.28fdac", "type": "change", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Изменение режима", "rules": [ { "t": "set", "p": "statuses.switchOn.ventilation", "pt": "flow", "to": "manual", "tot": "str" }, { "t": "set", "p": "statuses.switchOn.bathroomlighting", "pt": "flow", "to": "manual", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 820, "y": 440, "wires": [ [] ] }, { "id": "fc81cbf3.d9e598", "type": "change", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "Изменение режима", "rules": [ { "t": "set", "p": "statuses.switchOn.ventilation", "pt": "flow", "to": "$exists( deviceName ) ? \"manual\" : \"auto\"", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 520, "y": 500, "wires": [ [ "9801df40.8eaf" ] ] }, { "id": "806b8b4f.fc9e28", "type": "link out", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "", "links": [ "9706c5ee.ed90f8" ], "x": 895, "y": 260, "wires": [] }, { "id": "9706c5ee.ed90f8", "type": "link in", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "", "links": [ "806b8b4f.fc9e28" ], "x": 55, "y": 500, "wires": [ [ "c337d54b.42fca8" ] ] }, { "id": "1eb4de14.948162", "type": "link out", "z": "b18e26a3.abdb68", "g": "b621e9dc.d9a628", "name": "", "links": [ "73484b4a.02ca14" ], "x": 895, "y": 320, "wires": [] }, { "id": "8c124f67.6e463", "type": "debug", "z": "b18e26a3.abdb68", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 240, "y": 560, "wires": [] }, { "id": "8745b931.133868", "type": "mqtt-broker", "name": "localhost", "broker": "localhost", "port": "1883", "clientid": "", "usetls": false, "compatmode": false, "keepalive": "60", "cleansession": true, "birthTopic": "", "birthQos": "0", "birthPayload": "", "closeTopic": "", "closeQos": "0", "closePayload": "", "willTopic": "", "willQos": "0", "willPayload": "" } ]
Обсуждение