Proszę. Wklejam zanonimizowany kod do Node-red. Jako, że mój zasobnik c.w.u. jest hybrydowy, to rozbudowałem ten flow niedawno o sprawdzanie temperatury na piecu. Jeśli piec grzeje, to ma priorytet nad grzaniem z paneli. Jeśli go po sezonie wyłączę, lub byłaby jakas awaria, to woda nagrzeje się elektrycznie.
[
{
"id": "node_1",
"type": "server-state-changed",
"z": "main_flow",
"name": "gridUsage",
"server": "home_assistant_server",
"version": 6,
"outputs": 1,
"entities": {
"entity": ["sensor.grid_usage"],
"substring": [],
"regex": []
},
"outputInitially": false,
"stateType": "str",
"ifState": "",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": true,
"for": "0",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "gridUsage",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 120,
"y": 280,
"wires": [["node_2"]]
},
{
"id": "node_3",
"type": "api-current-state",
"z": "main_flow",
"name": "HeaterControl",
"server": "home_assistant_server",
"version": 3,
"outputs": 1,
"entity_id": "water_heater.heater_control",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "heaterTemp",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"x": 700,
"y": 320,
"wires": [["node_4"]]
},
{
"id": "node_5",
"type": "function",
"z": "main_flow",
"name": "Calculate Brightness",
"func": "const gridUsage = parseFloat(msg.gridUsage);\nconst nominalHeaterPower = 2.0;\nconst maxGrid = 0.1;\nlet brightness = 0;\nif (-gridUsage > nominalHeaterPower) {\n brightness = 255;\n} else {\n const excessToGive = Math.max(-gridUsage - maxGrid, 0);\n brightness = Math.min(Math.max(0, Math.round(255 * excessToGive / nominalHeaterPower)), 255);\n}\nreturn { payload: brightness };",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"x": 880,
"y": 420,
"wires": [["node_6"]]
},
{
"id": "node_6",
"type": "switch",
"z": "main_flow",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{ "t": "lte", "v": "25", "vt": "str" },
{ "t": "gt", "v": "25", "vt": "str" }
],
"outputs": 2,
"x": 1030,
"y": 420,
"wires": [["node_off"], ["node_on"]]
},
{
"id": "node_off",
"type": "api-call-service",
"z": "main_flow",
"name": "Turn Heater Off",
"server": "home_assistant_server",
"version": 7,
"action": "light.turn_off",
"entityId": ["light.heater_brightness"],
"x": 1250,
"y": 300,
"wires": []
},
{
"id": "node_on",
"type": "api-call-service",
"z": "main_flow",
"name": "Turn Heater On + Brightness",
"server": "home_assistant_server",
"version": 7,
"action": "light.turn_on",
"entityId": ["light.heater_brightness"],
"data": "{\"brightness\":msg.payload}",
"dataType": "jsonata",
"x": 1250,
"y": 480,
"wires": []
},
{
"id": "node_4",
"type": "function",
"z": "main_flow",
"name": "Temperature Delta",
"func": "const data = msg.data;\nconst targetTempHigh = data.attributes.target_temp_high;\nconst currentTemp = data.attributes.current_temperature;\nconst difference = targetTempHigh - currentTemp;\nreturn { payload: difference };",
"outputs": 1,
"timeout": "",
"noerr": 0,
"x": 250,
"y": 420,
"wires": [["node_7"]]
},
{
"id": "node_7",
"type": "switch",
"z": "main_flow",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{ "t": "lt", "v": "1", "vt": "str" },
{ "t": "btwn", "v": "1", "vt": "num", "v2": "8", "v2t": "num" },
{ "t": "gt", "v": "8", "vt": "num" }
],
"outputs": 3,
"x": 430,
"y": 420,
"wires": [["node_off"], ["node_8"], ["node_max_brightness"]]
},
{
"id": "node_max_brightness",
"type": "api-call-service",
"z": "main_flow",
"name": "Turn Heater On + Max Brightness",
"server": "home_assistant_server",
"version": 7,
"action": "light.turn_on",
"entityId": ["light.heater_brightness"],
"data": "{\"brightness\":255}",
"dataType": "jsonata",
"x": 1280,
"y": 580,
"wires": []
},
{
"id": "node_8",
"type": "api-current-state",
"z": "main_flow",
"name": "Check Grid Usage",
"server": "home_assistant_server",
"version": 3,
"outputs": 1,
"entity_id": "sensor.grid_usage",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{ "property": "gridUsage", "propertyType": "msg", "value": "", "valueType": "entityState" },
{ "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }
],
"x": 670,
"y": 420,
"wires": [["node_5"]]
},
{
"id": "home_assistant_server",
"type": "server",
"name": "Home Assistant",
"version": 5,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true
}
]