feat: force heater button

This commit is contained in:
2026-02-04 23:40:59 +01:00
parent 85ebf4fc69
commit 70e2114288

View File

@@ -25,8 +25,8 @@
"name": "batt_temp", "name": "batt_temp",
"onlyChanges": true, "onlyChanges": true,
"roundValues": "0", "roundValues": "0",
"x": 380, "x": 80,
"y": 380, "y": 200,
"wires": [ "wires": [
[ [
"7e04d0fa828e9868" "7e04d0fa828e9868"
@@ -46,8 +46,8 @@
"targetType": "msg", "targetType": "msg",
"statusVal": "", "statusVal": "",
"statusType": "auto", "statusType": "auto",
"x": 1040, "x": 740,
"y": 220, "y": 40,
"wires": [] "wires": []
}, },
{ {
@@ -68,8 +68,8 @@
"name": "pv_power", "name": "pv_power",
"onlyChanges": true, "onlyChanges": true,
"roundValues": "0", "roundValues": "0",
"x": 380, "x": 80,
"y": 440, "y": 260,
"wires": [ "wires": [
[ [
"7e04d0fa828e9868" "7e04d0fa828e9868"
@@ -80,10 +80,10 @@
"id": "de555a35fee6404c", "id": "de555a35fee6404c",
"type": "ui-switch", "type": "ui-switch",
"z": "cf255672ab90a22f", "z": "cf255672ab90a22f",
"name": "heater_switch", "name": "heater_on",
"label": "Calefacción", "label": "Calefacción",
"group": "aa9cdf043b4ff6f3", "group": "aa9cdf043b4ff6f3",
"order": 0, "order": 1,
"width": 0, "width": 0,
"height": 0, "height": 0,
"passthru": false, "passthru": false,
@@ -92,8 +92,8 @@
"topicType": "msg", "topicType": "msg",
"style": "", "style": "",
"className": "", "className": "",
"layout": "row-left-swapped", "layout": "row-spread",
"clickableArea": "switch", "clickableArea": "none",
"onvalue": "true", "onvalue": "true",
"onvalueType": "bool", "onvalueType": "bool",
"onicon": "", "onicon": "",
@@ -102,8 +102,8 @@
"offvalueType": "bool", "offvalueType": "bool",
"officon": "", "officon": "",
"offcolor": "", "offcolor": "",
"x": 1220, "x": 940,
"y": 360, "y": 160,
"wires": [ "wires": [
[] []
] ]
@@ -112,7 +112,7 @@
"id": "fb3c661bf8c01d98", "id": "fb3c661bf8c01d98",
"type": "shelly-gen2", "type": "shelly-gen2",
"z": "cf255672ab90a22f", "z": "cf255672ab90a22f",
"hostname": "10.0.1.11", "hostname": "172.24.24.2",
"description": "shelly", "description": "shelly",
"mode": "callback", "mode": "callback",
"verbose": false, "verbose": false,
@@ -126,8 +126,8 @@
"devicetypemustmatchexactly": false, "devicetypemustmatchexactly": false,
"captureblutooth": false, "captureblutooth": false,
"outputs": 1, "outputs": 1,
"x": 810, "x": 490,
"y": 660, "y": 520,
"wires": [ "wires": [
[ [
"bd1f36a1d9afba8d" "bd1f36a1d9afba8d"
@@ -151,8 +151,8 @@
"drop": true, "drop": true,
"allowrate": false, "allowrate": false,
"outputs": 1, "outputs": 1,
"x": 610, "x": 310,
"y": 340, "y": 160,
"wires": [ "wires": [
[ [
"4f2f81e6c9c20a90" "4f2f81e6c9c20a90"
@@ -177,8 +177,8 @@
"name": "batt_power", "name": "batt_power",
"onlyChanges": true, "onlyChanges": true,
"roundValues": "0", "roundValues": "0",
"x": 380, "x": 80,
"y": 320, "y": 140,
"wires": [ "wires": [
[ [
"7e04d0fa828e9868" "7e04d0fa828e9868"
@@ -197,11 +197,12 @@
"initialize": "", "initialize": "",
"finalize": "", "finalize": "",
"libs": [], "libs": [],
"x": 700, "x": 280,
"y": 500, "y": 360,
"wires": [ "wires": [
[ [
"4f2f81e6c9c20a90" "4f2f81e6c9c20a90",
"0f85c811db6b90cb"
] ]
] ]
}, },
@@ -210,15 +211,15 @@
"type": "function", "type": "function",
"z": "cf255672ab90a22f", "z": "cf255672ab90a22f",
"name": "heater_switch_manager", "name": "heater_switch_manager",
"func": "context.set(msg.topic, msg.payload)\n\nlet batt_temp = context.get(\"batt_temp\")\nlet batt_power = context.get(\"batt_power\")\nlet batt_soc = context.get(\"batt_soc\")\nlet box_temp = context.get(\"box_temp\")\nlet room_temp = context.get(\"room_temp\")\nlet pv_power = context.get(\"pv_power\")\nlet relay = context.get(\"relay\")\n\nlet log = \"\"\nfor (const key of context.keys()) {\n log += key + \"=\" + context.get(key) + \" \"\n}\nnode.warn(log)\n\n// Si estamos iniciando y faltan datos apagar el radiador.\nif (batt_temp == undefined || batt_power == undefined || box_temp == undefined\n || room_temp == undefined || pv_power == undefined) {\n node.warn(\"INITIALIZING\")\n msg.payload = false\n return msg;\n}\n\n// Si la temperatura ambiente o de la batería es alta apagar el radiador.\nif (batt_temp > 20 || room_temp > 20) {\n msg.payload = false\n return msg;\n}\n\n// Si la temperatura del sarcofago es baja desmarcar que se ha llegado al límite.\nif (box_temp < 15) {\n context.set(\"box_temp_upper_limit_reached\", false)\n}\n// Si la temperatura del sarcofago es alta marcar que se ha llegado al límite.\nelse if (box_temp > 25) {\n context.set(\"box_temp_upper_limit_reached\", true)\n}\n\n// Si se ha llegado al límite superior de temperatura del sarcófago apagar el\n// radiador, hay que esperar a cruzar el límite inferior.\nif (context.get(\"box_temp_upper_limit_reached\")) {\n msg.payload = false\n return msg;\n}\n\n// Encender el radiador si la potencia de carga es alta teniendo en cuenta el SOC.\nif ((pv_power > 700 && batt_soc > 50) || (pv_power > 300 && batt_soc > 70) ||\n (pv_power > 200 && batt_soc > 90)) {\n msg.payload = true\n return msg;\n}\n\n// Encender el radiador si la potencia de carga está limitada por la temperatura\n// de la batería.\nif ((pv_power > 1200 && batt_temp < 8) || (pv_power > 2500 && batt_temp < 16)) {\n msg.payload = true\n return msg;\n}\n\n// La batería debe estar por encima de 5º, a menos que el SOC sea menor que 50%.\nif (batt_temp < 5 && batt_soc > 50) {\n msg.payload = true\n return msg;\n}\n\n// En el resto de casos apagamos el radiador.\nmsg.payload = false\nreturn msg;\n", "func": "context.set(msg.topic, msg.payload)\n\nlet batt_temp = context.get(\"batt_temp\")\nlet batt_power = context.get(\"batt_power\")\nlet batt_soc = context.get(\"batt_soc\")\nlet box_temp = context.get(\"box_temp\")\nlet room_temp = context.get(\"room_temp\")\nlet pv_power = context.get(\"pv_power\")\nlet relay = context.get(\"relay\")\nlet force_heater = context.get(\"force_heater\")\n\nlet log = \"\"\nfor (const key of context.keys()) {\n log += key + \"=\" + context.get(key) + \" \"\n}\n//node.warn(log)\n\n// Si estamos iniciando y faltan datos apagar el radiador.\nif (batt_temp == undefined || batt_power == undefined || box_temp == undefined\n || room_temp == undefined || pv_power == undefined) {\n node.warn(\"INITIALIZING\")\n msg.payload = false\n return msg;\n}\n\n// Si la temperatura ambiente o de la batería es alta apagar el radiador.\nif (batt_temp > 20 || room_temp > 20) {\n msg.payload = false\n return msg;\n}\n\n// Si la temperatura del sarcofago es baja desmarcar que se ha llegado al límite.\nif (box_temp < 15) {\n context.set(\"box_temp_upper_limit_reached\", false)\n}\n// Si la temperatura del sarcofago es alta marcar que se ha llegado al límite.\nelse if (box_temp > 25) {\n context.set(\"box_temp_upper_limit_reached\", true)\n}\n\n// Si se ha llegado al límite superior de temperatura del sarcófago apagar el\n// radiador, hay que esperar a cruzar el límite inferior.\nif (context.get(\"box_temp_upper_limit_reached\")) {\n msg.payload = false\n return msg;\n}\n\n// Comprobar si se ha pedido explicitamente encender la calefacción.\nif (context.get(\"force_heater\")) {\n msg.payload = true\n return msg;\n}\n\n// Encender el radiador si la potencia de carga es alta teniendo en cuenta el SOC.\nif ((pv_power > 700 && batt_soc > 50) || (pv_power > 300 && batt_soc > 70) ||\n (pv_power > 200 && batt_soc > 90)) {\n msg.payload = true\n return msg;\n}\n\n// Encender el radiador si la potencia de carga está limitada por la temperatura\n// de la batería.\nif ((pv_power > 1200 && batt_temp < 8) || (pv_power > 2500 && batt_temp < 16)) {\n msg.payload = true\n return msg;\n}\n\n// Encender el radiador si la batería está fría y hay suficiente SOC.\nif ((batt_temp < 5 && batt_soc > 50) || (batt_temp < 6 && batt_soc > 60) ||\n (batt_temp < 8 && batt_soc > 70) || (batt_temp < 12 && batt_soc > 80) ||\n (batt_temp < 16 && batt_soc > 90)) {\n msg.payload = true\n return msg;\n}\n\n// En el resto de casos apagamos el radiador.\nmsg.payload = false\nreturn msg;\n",
"outputs": 1, "outputs": 1,
"timeout": 0, "timeout": 0,
"noerr": 0, "noerr": 0,
"initialize": "", "initialize": "",
"finalize": "", "finalize": "",
"libs": [], "libs": [],
"x": 850, "x": 550,
"y": 340, "y": 160,
"wires": [ "wires": [
[ [
"cd1a8c477cfe992a", "cd1a8c477cfe992a",
@@ -238,8 +239,8 @@
"initialize": "", "initialize": "",
"finalize": "", "finalize": "",
"libs": [], "libs": [],
"x": 1170, "x": 970,
"y": 460, "y": 380,
"wires": [ "wires": [
[ [
"fb3c661bf8c01d98" "fb3c661bf8c01d98"
@@ -250,7 +251,7 @@
"id": "cd1a8c477cfe992a", "id": "cd1a8c477cfe992a",
"type": "rbe", "type": "rbe",
"z": "cf255672ab90a22f", "z": "cf255672ab90a22f",
"name": "", "name": "filter equal",
"func": "rbe", "func": "rbe",
"gap": "", "gap": "",
"start": "", "start": "",
@@ -258,8 +259,8 @@
"septopics": false, "septopics": false,
"property": "payload", "property": "payload",
"topi": "topic", "topi": "topic",
"x": 1050, "x": 770,
"y": 340, "y": 160,
"wires": [ "wires": [
[ [
"de555a35fee6404c", "de555a35fee6404c",
@@ -280,8 +281,8 @@
"complete": "false", "complete": "false",
"statusVal": "", "statusVal": "",
"statusType": "auto", "statusType": "auto",
"x": 1220, "x": 940,
"y": 300, "y": 100,
"wires": [] "wires": []
}, },
{ {
@@ -302,14 +303,129 @@
"name": "batt_soc", "name": "batt_soc",
"onlyChanges": true, "onlyChanges": true,
"roundValues": "0", "roundValues": "0",
"x": 380, "x": 80,
"y": 260, "y": 80,
"wires": [ "wires": [
[ [
"7e04d0fa828e9868" "7e04d0fa828e9868"
] ]
] ]
}, },
{
"id": "0f85c811db6b90cb",
"type": "switch",
"z": "cf255672ab90a22f",
"name": "",
"property": "topic",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "box_temp",
"vt": "str"
},
{
"t": "eq",
"v": "room_temp",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 530,
"y": 360,
"wires": [
[
"9593b9b734c4e4f9"
],
[
"62d7f8dd71fa7b38"
]
]
},
{
"id": "9593b9b734c4e4f9",
"type": "ui-text",
"z": "cf255672ab90a22f",
"group": "aa9cdf043b4ff6f3",
"order": 3,
"width": 0,
"height": 0,
"name": "box_temp",
"label": "Sarcófago",
"format": "{{msg.payload}}",
"layout": "row-spread",
"style": false,
"font": "",
"fontSize": 16,
"color": "#717171",
"wrapText": false,
"className": "",
"value": "payload",
"valueType": "msg",
"x": 680,
"y": 340,
"wires": []
},
{
"id": "62d7f8dd71fa7b38",
"type": "ui-text",
"z": "cf255672ab90a22f",
"group": "aa9cdf043b4ff6f3",
"order": 4,
"width": 0,
"height": 0,
"name": "room_text",
"label": "Habitación",
"format": "{{msg.payload}}",
"layout": "row-spread",
"style": false,
"font": "",
"fontSize": 16,
"color": "#717171",
"wrapText": false,
"className": "",
"value": "payload",
"valueType": "msg",
"x": 680,
"y": 380,
"wires": []
},
{
"id": "91d7f7d3a52c6875",
"type": "ui-switch",
"z": "cf255672ab90a22f",
"name": "force_heater",
"label": "Forzar calefacción",
"group": "aa9cdf043b4ff6f3",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"decouple": false,
"topic": "force_heater",
"topicType": "str",
"style": "",
"className": "",
"layout": "row-spread",
"clickableArea": "switch",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"x": 310,
"y": 100,
"wires": [
[
"4f2f81e6c9c20a90"
]
]
},
{ {
"id": "aa9cdf043b4ff6f3", "id": "aa9cdf043b4ff6f3",
"type": "ui-group", "type": "ui-group",
@@ -318,7 +434,7 @@
"width": "6", "width": "6",
"height": "1", "height": "1",
"order": 1, "order": 1,
"showTitle": true, "showTitle": false,
"className": "", "className": "",
"visible": "true", "visible": "true",
"disabled": "false", "disabled": "false",
@@ -333,32 +449,32 @@
{ {
"id": "545b3851d8568f59", "id": "545b3851d8568f59",
"type": "ui-page", "type": "ui-page",
"name": "Page 1", "name": "Calefacción",
"ui": "cf2bb7479e560f99", "ui": "cf2bb7479e560f99",
"path": "/page1", "path": "/heater",
"icon": "home", "icon": "home",
"layout": "grid", "layout": "grid",
"theme": "43a2d84f031e3dc7", "theme": "43a2d84f031e3dc7",
"breakpoints": [ "breakpoints": [
{ {
"name": "Default", "name": "Default",
"px": 0, "px": "0",
"cols": 3 "cols": "3"
}, },
{ {
"name": "Tablet", "name": "Tablet",
"px": 576, "px": "576",
"cols": 6 "cols": "6"
}, },
{ {
"name": "Small Desktop", "name": "Small Desktop",
"px": 768, "px": "768",
"cols": 9 "cols": "9"
}, },
{ {
"name": "Desktop", "name": "Desktop",
"px": 1024, "px": "1024",
"cols": 12 "cols": "12"
} }
], ],
"order": 1, "order": 1,