[
{
"id": "f1a001",
"type": "tab",
"label": "Ueberschuss Shelly Relais",
"disabled": false,
"info": ""
},
{
"id": "f1a010",
"type": "mqtt in",
"z": "f1a001",
"name": "Victron Grid Power",
"topic": "N/+/system/0/Ac/Grid/Power",
"qos": "0",
"datatype": "auto",
"broker": "f1a900",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 180,
"y": 120,
"wires": [
[
"f1a020"
]
]
},
{
"id": "f1a020",
"type": "function",
"z": "f1a001",
"name": "Ueberschuss Logik",
"func": "const now = Date.now()\n\nconst exportOnW = 300\nconst importOffW = 150\n\nconst onDelayMs = 30000\nconst offDelayMs = 15000\n\nconst minOnMs = 120000\nconst minOffMs = 60000\n\nconst shellyTopic = \"shellypro3em/relay/0/command\"\n\nlet gridW = msg.payload\nif (typeof gridW === \"string\") gridW = Number(gridW)\nif (typeof gridW === \"object\" && gridW !== null) {\n if (gridW.value !== undefined) gridW = Number(gridW.value)\n}\nif (!Number.isFinite(gridW)) return [null, { payload: { error: \"gridW not numeric\", raw: msg.payload } }]\n\nlet relay = flow.get(\"relay\")\nif (relay === undefined) relay = false\n\nlet lastChange = flow.get(\"lastChange\")\nif (!lastChange) lastChange = 0\n\nlet exportStart = flow.get(\"exportStart\") || null\nlet importStart = flow.get(\"importStart\") || null\n\nconst sinceChange = now - lastChange\n\nconst isExport = gridW < 0 && Math.abs(gridW) >= exportOnW\nconst isImport = gridW > importOffW\n\nlet cmd = null\n\nif (!relay) {\n if (isExport) {\n if (!exportStart) exportStart = now\n const exportFor = now - exportStart\n if (exportFor >= onDelayMs && sinceChange >= minOffMs) {\n cmd = \"on\"\n relay = true\n lastChange = now\n exportStart = null\n importStart = null\n }\n } else {\n exportStart = null\n }\n} else {\n if (isImport) {\n if (!importStart) importStart = now\n const importFor = now - importStart\n if (importFor >= offDelayMs && sinceChange >= minOnMs) {\n cmd = \"off\"\n relay = false\n lastChange = now\n exportStart = null\n importStart = null\n }\n } else {\n importStart = null\n }\n}\n\nflow.set(\"relay\", relay)\nflow.set(\"lastChange\", lastChange)\nflow.set(\"exportStart\", exportStart)\nflow.set(\"importStart\", importStart)\n\nconst status = {\n gridW,\n relay,\n isExport,\n isImport,\n exportStart,\n importStart,\n lastChange\n}\n\nif (!cmd) return [null, { payload: status }]\n\nreturn [{ topic: shellyTopic, payload: cmd }, { payload: { ...status, cmd } }]\n",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 430,
"y": 120,
"wires": [
[
"f1a030"
],
[
"f1a040"
]
]
},
{
"id": "f1a030",
"type": "mqtt out",
"z": "f1a001",
"name": "Shelly Relais Command",
"topic": "",
"qos": "0",
"retain": "false",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "f1a900",
"x": 700,
"y": 100,
"wires": []
},
{
"id": "f1a040",
"type": "debug",
"z": "f1a001",
"name": "Status",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 690,
"y": 160,
"wires": []
},
{
"id": "f1a900",
"type": "mqtt-broker",
"name": "MQTT Broker",
"broker": "127.0.0.1",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {}
}
]
Grundsätzlich lassen sich Shelly Geräte ein und ausschalten im Cerbo, Ekrano etc.
Direkte Einbindung als Widget wäre mir neu. Derzeit sind die Shelly geräte auch im OS einfach zu steuern.