Need help for Node red flow "How much money I spent to my energy provider"
Posted: Sunday 25 June 2023 12:57
by sailmich
Hello all,
I'm from Germany and since a few months I got a balcony power station. The power station has no accumulator to store the unused power. Here in Germany we gave unused power for free to the provider. I created a flow to see the percentage I use in nearly real time. This is nice to have but I would like to add all negative values from my provider counter and divide them by the numbers of incoming negative values at the end of the day. My programming skills are nearly zero. I mostly grab code here and there, change it a bit and sometimes it's working. Maybe somebody did it quite similar or chosen better way and is willing to help me.
I'm from Germany and since a few months I got a balcony power station. The power station has no accumulator to store the unused power. Here in Germany we gave unused power for free to the provider. I created a flow to see the percentage I use in nearly real time. This is nice to have but I would like to add all negative values from my provider counter and divide them by the numbers of incoming negative values at the end of the day. My programming skills are nearly zero. I mostly grab code here and there, change it a bit and sometimes it's working. Maybe somebody did it quite similar or chosen better way and is willing to help me.
- Spoiler: show
- [
{
"id": "972c14d502141bb6",
"type": "tab",
"label": "Flow 4",
"disabled": false,
"info": "",
"env": []
},
{
"id": "6b747ed4c8bbc0e7",
"type": "function",
"z": "972c14d502141bb6",
"name": "power",
"func": "msg.topic=\"Zaehlerschrank\";\nmsg.payload = msg.payload[\"1-0:16.7.0*255\"].values[0].value.toString();\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 110,
"y": 240,
"wires": [
[
"8fddc2ae2eca6224"
]
]
},
{
"id": "8fddc2ae2eca6224",
"type": "switch",
"z": "972c14d502141bb6",
"name": "provider",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "gte",
"v": "0",
"vt": "num"
},
{
"t": "lt",
"v": "0",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 260,
"y": 240,
"wires": [
[
"2ac8e9dbbbd718e3"
],
[
"512eecb78dc62215",
"c14be0b01e724802"
]
]
},
{
"id": "5f756b8d16099d28",
"type": "mqtt in",
"z": "972c14d502141bb6",
"name": "PV",
"topic": "shellies/shellyplug-s-6E7620/relay/0/power",
"qos": "0",
"datatype": "utf8",
"broker": "f9f13036.e28b58",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 110,
"y": 340,
"wires": [
[
"9abe5d7a82864ec9"
]
]
},
{
"id": "3f0a5d9017fdc00b",
"type": "change",
"z": "972c14d502141bb6",
"name": "topic.consumption",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "Verbrauch",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 670,
"y": 240,
"wires": [
[
"0356f777fbf1ed46"
]
]
},
{
"id": "12652f65be6d6155",
"type": "change",
"z": "972c14d502141bb6",
"name": "topic.generation",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "Erzeugung",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 660,
"y": 340,
"wires": [
[
"0356f777fbf1ed46",
"a30647b79595ef44"
]
]
},
{
"id": "0356f777fbf1ed46",
"type": "join",
"z": "972c14d502141bb6",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 890,
"y": 280,
"wires": [
[
"cc590317870bd12a"
]
]
},
{
"id": "cc590317870bd12a",
"type": "change",
"z": "972c14d502141bb6",
"name": "calculate",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "(payload.Verbrauch+payload.Erzeugung)/payload.Erzeugung*100",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1020,
"y": 280,
"wires": [
[
"5e6bc759c3dd040b"
]
]
},
{
"id": "512eecb78dc62215",
"type": "json",
"z": "972c14d502141bb6",
"name": "object.negativ",
"property": "payload",
"action": "",
"pretty": false,
"x": 480,
"y": 240,
"wires": [
[
"3f0a5d9017fdc00b",
"ed9b6ccdf737baf0"
]
]
},
{
"id": "3b29678e6a020f37",
"type": "json",
"z": "972c14d502141bb6",
"name": "object.1",
"property": "payload",
"action": "",
"pretty": false,
"x": 460,
"y": 340,
"wires": [
[
"12652f65be6d6155"
]
]
},
{
"id": "c28aea6cb639ef43",
"type": "function",
"z": "972c14d502141bb6",
"name": "to domoticz",
"func": "msg.payload = { \"command\": \"udevice\", \"idx\": 639, \"nvalue\": 0, \"svalue\": msg.payload.toString() };\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1510,
"y": 280,
"wires": [
[]
]
},
{
"id": "5e6bc759c3dd040b",
"type": "switch",
"z": "972c14d502141bb6",
"name": "max 100%",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "lte",
"v": "100",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 1170,
"y": 280,
"wires": [
[
"c28aea6cb639ef43"
]
]
},
{
"id": "d233082d62f8d88a",
"type": "function",
"z": "972c14d502141bb6",
"name": "to domoticz",
"func": "msg.payload = { \"command\": \"udevice\", \"idx\": 639, \"nvalue\": 0, \"svalue\": \"100\" };\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1330,
"y": 200,
"wires": [
[]
]
},
{
"id": "c14be0b01e724802",
"type": "function",
"z": "972c14d502141bb6",
"name": "counter",
"func": "var count = context.get('count') ||0;\ncount += 1;\nmsg.payload = count;\ncontext.set('count', count);\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 280,
"wires": [
[
"1438377f2f0efd57"
]
]
},
{
"id": "1438377f2f0efd57",
"type": "debug",
"z": "972c14d502141bb6",
"name": "debug 4",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 620,
"y": 280,
"wires": []
},
{
"id": "9abe5d7a82864ec9",
"type": "switch",
"z": "972c14d502141bb6",
"name": "sunshine",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "gt",
"v": "0",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 260,
"y": 340,
"wires": [
[
"3b29678e6a020f37"
]
]
},
{
"id": "2ac8e9dbbbd718e3",
"type": "json",
"z": "972c14d502141bb6",
"name": "object.positiv",
"property": "payload",
"action": "",
"pretty": false,
"x": 470,
"y": 200,
"wires": [
[
"1a6058c030ff9e13"
]
]
},
{
"id": "1a6058c030ff9e13",
"type": "change",
"z": "972c14d502141bb6",
"name": "topic.consumption",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "Verbrauch",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 670,
"y": 200,
"wires": [
[
"a30647b79595ef44"
]
]
},
{
"id": "a30647b79595ef44",
"type": "join",
"z": "972c14d502141bb6",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 850,
"y": 200,
"wires": [
[
"d0728344146b8c1b"
]
]
},
{
"id": "d0728344146b8c1b",
"type": "change",
"z": "972c14d502141bb6",
"name": "calculate",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "(payload.Verbrauch+payload.Erzeugung)/payload.Erzeugung*100",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 980,
"y": 200,
"wires": [
[
"83dce01448fd2603"
]
]
},
{
"id": "83dce01448fd2603",
"type": "switch",
"z": "972c14d502141bb6",
"name": "above 100%",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "gte",
"v": "100",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 1170,
"y": 200,
"wires": [
[
"d233082d62f8d88a"
]
]
},
{
"id": "ed9b6ccdf737baf0",
"type": "debug",
"z": "972c14d502141bb6",
"name": "debug 5",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 660,
"y": 60,
"wires": []
},
{
"id": "f9f13036.e28b58",
"type": "mqtt-broker",
"name": "localhost",
"broker": "192.xxx.xxx.xx",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]