Это дополнение к потоку сохранения телеметрии отопления для уведомления о включении и выключении горячего водоснабжения,.. что в условиях России очень актуально.
В этом потоке используются следующие узлы, которых нет в стандартной поставке:
Узел «link in» получает консолидированные данные от вышеуказанного родительского потока, проверяет пороги, устанавливаемые в цепочке «Настройки», и, если произошел выход за один из порогов, но уведомление еще не отправлялось, отправляет сообщение по электронной почте. Помимо статуса горячего водоснабжения, к письму добавляются данные с других датчиков отопления. При успешной отправке в потоковый контекст и базу данных записывается новый статус.
[ { "id": "6cb8ef9e9ee1cac6", "type": "group", "z": "775261a030fb4543", "name": "Уведомления о воде", "style": { "label": true }, "nodes": [ "590f308482548b0c", "9b0e50a545771b4f", "48ba8c0aa807cedc", "9f189515e23a4f5f", "7c0aecfa1f5e11df", "83398ffc208d9229", "77e8e483801efd67", "543beb8d849e3c0a", "83c605c99d7670d8", "1f09b2fd8cf937cc", "f80be41919d6b26e", "01ed492c5e4726c4", "2f0eb4e1e5f98b04", "121b9c9bb892e875" ], "x": 14, "y": 639, "w": 932, "h": 202 }, { "id": "590f308482548b0c", "type": "change", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Установка статуса", "rules": [ { "t": "set", "p": "status", "pt": "msg", "to": "( temperature.devices.bathroom > $flowContext( \"settings.levels.normal\" ) and $not( $flowContext( \"settings.status\" ) ) ) ? true : ( temperature.devices.bathroom < $flowContext( \"settings.levels.low\" ) and $flowContext( \"settings.status\" ) ) ? false : \"nohow\"", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 370, "y": 740, "wires": [ [ "77e8e483801efd67" ] ] }, { "id": "9b0e50a545771b4f", "type": "email-send", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "transport": "07868703c10c6510", "from": "nodered@domain.zone", "to": "nikolay@soloshin.su", "cc": "", "bcc": "", "subject": "", "contentType": "text", "name": "Отправка почты", "x": 130, "y": 800, "wires": [ [ "543beb8d849e3c0a" ] ] }, { "id": "48ba8c0aa807cedc", "type": "inject", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Настройки", "props": [ { "p": "topic", "vt": "str" }, { "p": "settings.levels", "v": "{\"normal\":48,\"low\":45}", "vt": "json" }, { "p": "settings.names", "v": "{\"nursery\":\"детская\",\"kitchen\":\"кухня\",\"bedroom\":\"спальня\"}", "vt": "json" } ], "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "topic": "SELECT previousStatus FROM assets", "x": 130, "y": 680, "wires": [ [ "01ed492c5e4726c4" ] ] }, { "id": "9f189515e23a4f5f", "type": "sqlite", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "mydb": "97614cf90bc2b1ed", "sqlquery": "msg.topic", "sql": "", "name": "Запрос к базе данных", "x": 760, "y": 680, "wires": [ [ "f80be41919d6b26e" ] ] }, { "id": "7c0aecfa1f5e11df", "type": "change", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Запись в контекст", "rules": [ { "t": "set", "p": "settings", "pt": "flow", "to": "settings", "tot": "msg" }, { "t": "set", "p": "settings.status", "pt": "flow", "to": "payload[0].previousStatus = 0 ? false : true", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 490, "y": 680, "wires": [ [] ] }, { "id": "83398ffc208d9229", "type": "change", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Подготовка письма", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "( $localNames := $flowContext( \"settings.names\" );\t \"Кажется, \" & ( status ? \"можно \" : \"нельзя \" ) & \"идти в ванну!\\n\\nТемпература горячей воды \" &\t $round( temperature.devices.bathroom ) & \"℃!\\n\\nЗначения других датчиков:\\n\\n\" &\t ( $.temperature.devices ~> | $ | {}, \"bathroom\" | ~>\t $each( function( $value, $key ) {\t $lookup( $localNames, $key ) & \": \" & $round( $value ) & \"℃\" \t } ) ~> $join( \",\\n\" ) ) & \".\" )", "tot": "jsonata" }, { "t": "set", "p": "email.subject", "pt": "msg", "to": "\"Изменился статус теплоснабжения (\" & $now('[H01]:[m01]:[s01] [D01].[M01].[Y0001]', '+1000') & \")!\"", "tot": "jsonata" }, { "t": "delete", "p": "temperature", "pt": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 820, "y": 740, "wires": [ [ "9b0e50a545771b4f" ] ] }, { "id": "77e8e483801efd67", "type": "switch", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Фильтр статуса", "property": "status", "propertyType": "msg", "rules": [ { "t": "istype", "v": "boolean", "vt": "boolean" } ], "checkall": "false", "repair": false, "outputs": 1, "x": 580, "y": 740, "wires": [ [ "83398ffc208d9229" ] ] }, { "id": "543beb8d849e3c0a", "type": "switch", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Фильтр статуса ответа", "property": "payload.response", "propertyType": "msg", "rules": [ { "t": "cont", "v": "250 OK", "vt": "str" } ], "checkall": "false", "repair": false, "outputs": 1, "x": 370, "y": 800, "wires": [ [ "83c605c99d7670d8" ] ] }, { "id": "83c605c99d7670d8", "type": "change", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Обновление статуса", "rules": [ { "t": "set", "p": "settings.status", "pt": "flow", "to": "status", "tot": "jsonata" }, { "t": "set", "p": "topic", "pt": "msg", "to": "\"UPDATE assets SET previousStatus = \" & status", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 640, "y": 800, "wires": [ [ "2f0eb4e1e5f98b04" ] ] }, { "id": "1f09b2fd8cf937cc", "type": "link in", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "База данных", "links": [], "x": 615, "y": 680, "wires": [ [ "9f189515e23a4f5f" ] ] }, { "id": "f80be41919d6b26e", "type": "link out", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Возврат запроса", "mode": "return", "links": [], "x": 905, "y": 680, "wires": [] }, { "id": "01ed492c5e4726c4", "type": "link call", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Вызов БД", "links": [ "1f09b2fd8cf937cc" ], "linkType": "static", "timeout": "30", "x": 300, "y": 680, "wires": [ [ "7c0aecfa1f5e11df" ] ] }, { "id": "2f0eb4e1e5f98b04", "type": "link call", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Вызов БД", "links": [ "1f09b2fd8cf937cc" ], "linkType": "static", "timeout": "30", "x": 860, "y": 800, "wires": [ [] ] }, { "id": "121b9c9bb892e875", "type": "link in", "z": "775261a030fb4543", "g": "6cb8ef9e9ee1cac6", "name": "Датчик температуры", "links": [ "42765c1e13d9a88a" ], "x": 140, "y": 740, "wires": [ [ "590f308482548b0c" ] ], "l": true }, { "id": "07868703c10c6510", "type": "email-transport", "name": "General", "host": "smtp.com", "port": "465", "secure": true, "authType": "none", "proxy": "" }, { "id": "97614cf90bc2b1ed", "type": "sqlitedb", "db": "/databases/telemetry/heating.db", "mode": "RWC" } ]
Обсуждение