Need help for Node red flow "How much money I spent to my energy provider"

Moderator: leecollings

Post Reply
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Need help for Node red flow "How much money I spent to my energy provider"

Post 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.
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": ""
}
]
User avatar
FireWizard
Posts: 1763
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Need help for Node red flow "How much money I spent to my energy provider"

Post by FireWizard »

Hello @sailmich,

I loaded your flow in my Node-RED test system and tried to understand what you want to achieve, but I still have a few question.

I hope you can explain a little bit more.

1. In the upper stream you start with a "Function" node.
What is the input of that node? Where does it comes from?
I see something as an OBIS reference. Does it come from a Smartmeter or what you use in Germany, Volkszaehler?

Can you show an example of the input of the "Function" node?

This will give you the consumed energy from the grid AND the produced energy to the grid, all in one OBIS reference?

2. You receive the produced energy from a Shelly Plug by MQTT.This is in Watt!

3 As far as I understand you want to know, which part in percentage is the consumed energy and which part in percentage is production.
What is its intended use?

4. You use a flow variable in order to count.
But this is connected to a Debug node, but not used further on.

If you can explain a little bit more, I think I can help you.

Regards
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Need help for Node red flow "How much money I spent to my energy provider"

Post by sailmich »

Hello @FireWizard,
1. it is comming from node-red-contrib-smartmeter, I take the momentary usage in Watt for the input. If the value is negative I produced more then I need, the rest goes to my provider.
Here is the input.
Spoiler: show

Code: Select all

{"1-0:96.50.1*1":{"medium":1,"channel":0,"measurement":96,"measureType":50,"tariffRate":1,"previousMeasurement":1,"values":[{"value":"HLY","unit":""}]},"1-0:96.1.0*255":{"medium":1,"channel":0,"measurement":96,"measureType":1,"tariffRate":0,"previousMeasurement":255,"values":[{"value":"0a01484c590200045269","unit":""}]},"1-0:1.8.0*255":{"medium":1,"channel":0,"measurement":1,"measureType":8,"tariffRate":0,"previousMeasurement":255,"values":[{"value":17368.5796,"unit":"kWh"}]},"1-0:2.8.0*255":{"medium":1,"channel":0,"measurement":2,"measureType":8,"tariffRate":0,"previousMeasurement":255,"values":[{"value":61.854,"unit":"kWh"}]},"1-0:16.7.0*255":{"medium":1,"channel":0,"measurement":16,"measureType":7,"tariffRate":0,"previousMeasurement":255,"values":[{"value":1459,"unit":"W"}]},"1-0:32.7.0*255":{"medium":1,"channel":0,"measurement":32,"measureType":7,"tariffRate":0,"previousMeasurement":255,"values":[{"value":232.6,"unit":"V"}]},"1-0:52.7.0*255":{"medium":1,"channel":0,"measurement":52,"measureType":7,"tariffRate":0,"previousMeasurement":255,"values":[{"value":233.3,"unit":"V"}]},"1-0:72.7.0*255":{"medium":1,"channel":0,"measurement":72,"measureType":7,"tariffRate":0,"previousMeasurement":255,"values":[{"value":232.9,"unit":"V"}]},"1-0:31.7.0*255":{"medium":1,"channel":0,"measurement":31,"measureType":7,"tariffRate":0,"previousMeasurement":255,"values":[{"value":5,"unit":"A"}]},"1-0:51.7.0*255":{"medium":1,"channel":0,"measurement":51,"measureType":7,"tariffRate":0,"previousMeasurement":255,"values":[{"value":1.39,"unit":"A"}]},"1-0:71.7.0*255":{"medium":1,"channel":0,"measurement":71,"measureType":7,"tariffRate":0,"previousMeasurement":255,"values":[{"value":0.33,"unit":"A"}]},"1-0:81.7.1*255":{"medium":1,"channel":0,"measurement":81,"measureType":7,"tariffRate":1,"previousMeasurement":255,"values":[{"value":219,"unit":"°"}]},"1-0:81.7.2*255":{"medium":1,"channel":0,"measurement":81,"measureType":7,"tariffRate":2,"previousMeasurement":255,"values":[{"value":239,"unit":"°"}]},"1-0:81.7.4*255":{"medium":1,"channel":0,"measurement":81,"measureType":7,"tariffRate":4,"previousMeasurement":255,"values":[{"value":7,"unit":"°"}]},"1-0:81.7.15*255":{"medium":1,"channel":0,"measurement":81,"measureType":7,"tariffRate":15,"previousMeasurement":255,"values":[{"value":328,"unit":"°"}]},"1-0:81.7.26*255":{"medium":1,"channel":0,"measurement":81,"measureType":7,"tariffRate":26,"previousMeasurement":255,"values":[{"value":295,"unit":"°"}]},"1-0:14.7.0*255":{"medium":1,"channel":0,"measurement":14,"measureType":7,"tariffRate":0,"previousMeasurement":255,"values":[{"value":49.9,"unit":"Hz"}]},"1-0:0.2.0*0":{"medium":1,"channel":0,"measurement":0,"measureType":2,"tariffRate":0,"previousMeasurement":0,"values":[{"value":"1.02.007","unit":""}]},"1-0:96.90.2*1":{"medium":1,"channel":0,"measurement":96,"measureType":90,"tariffRate":2,"previousMeasurement":1,"values":[{"value":"A01A","unit":""}]},"1-0:96.5.0*255":{"medium":1,"channel":0,"measurement":96,"measureType":5,"tariffRate":0,"previousMeasurement":255,"values":[{"value":1835268,"unit":""}]}}
2. Yes that's correct.
3. To get a better understanding if my balcony power station was a good investment, and if I want to install a bigger pv system to get more information, eg. if a accumulator would be need. I know I could take the log of domoticz but with 5 minutes interval it's seems not accurate enough.
4. I thought I could take this count later for calculation.
Thanks for helping me and taking time!
User avatar
FireWizard
Posts: 1763
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Need help for Node red flow "How much money I spent to my energy provider"

Post by FireWizard »

Hello @sailmich,

I have studied your output and I believe, it has not be that complicated.

You want to use the power output, but I suggest you consider the energy instead of power.

You wanted to use: 16.7.0, but you have also available 1.8.0 and 2.8.0, which represents, according to https://www.promotic.eu/en/pmdoc/Subsys ... 6_OBIS.htm:

1.8.0: Positive active energy (A+) total [kWh]
2.8.0: Negative active energy (A+) total [kWh]

while 16.7.0: Sum active instantaneous power (A+ - A-) [kW]

So with 1.8.0. and 2.8.0 you have it already separated.
Also the Shelly can give you the energy, but in Wmin.
If you divide the value of the Shelly by 60,000, you have it in kWh

kWh is the commonly used unit for Energy, and that is also where you have to pay for.
So there is no need to calculate that from the power.

You can create any comparison and push e.g. the percentage to a "Percentage" sensor on Domoticz.

You have the value of the Energy consumed from the grid (A), delivered to the grid (B) and produced by yourself (C).

E.g
Your house consumes A + C
You loose to the provider B >The percentage you loose (B/C * 100) or you use ((C -B)/C * 100) in your house.

What do you want to know more?

Let me know , if you like that idea and if you need support?

Regards
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Need help for Node red flow "How much money I spent to my energy provider"

Post by sailmich »

Hello FireWizard, thank you very much for the hint with the energy! I will check if I can solve it by myself, will take a while. I will sent you feedback.
Cheers
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Need help for Node red flow "How much money I spent to my energy provider"

Post by sailmich »

Hello @FireWizard,
I'm happy I don't need (A) for calculation :). But negative values are absolute. I need a start time when first input is coming from my shelly(C). Then I have to set (B) to zero relative to the value eg. (B) 64 kWh = 0 kWh or have to store the value somehow. At 23:00 I have to make the calculation. Therefore I must get the new value of (B) value (C) I can get from Domoticz. My problem is how do I can get the values in the morning and at the evening. Do I have to use inject nodes?
Cheers
User avatar
FireWizard
Posts: 1763
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Need help for Node red flow "How much money I spent to my energy provider"

Post by FireWizard »

Good evening @sailmich,

You said:
I'm happy I don't need (A) for calculation :)
Then we do not have to touch that.
But negative values are absolute
I do not hope, that you mean "absolute value", but that you need this negative value as being "delivered to the grid".
I need a start time when first input is coming from my shelly(C). Then I have to set (B) to zero relative to the value eg. (B) 64 kWh = 0 kWh or have to store the value somehow.
Why? Why do you need that "start time". You will receive a MQTT message, when there is an update from the Energy value.
I assume you want the data to compare over a certain time, probably a day, but can be also a month or a year.

Suppose you want to compare the relation of the self-produced energy and the energy delivered to the grid for each day.

The only thing you have to do is to save the data from the Shelly (C) and the data to the grid (B) to two flow variables at 00:00 h.
The next day at 00:00 h you deduct that value from the current value, so that you have the different values of the previous day.
And save back the new value, and so on. Do the calculations you want.

Keep in mind that you save that values to the filesystem and not to memory. Otherwise the values will not survive a reboot or power cut of your device.
See: Working with context
https://nodered.org/docs/user-guide/context

Let me know, if you need more help.

Regards
Therefore I must get the new value of (B) value (C) I can get from Domoticz. My problem is how do I can get the values in the morning and at the evening. Do I have to use inject nodes?
I do not know if the P1 Smart meter node gives the output automatically or that you have to use an "Inject" node.
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Need help for Node red flow "How much money I spent to my energy provider"

Post by sailmich »

Hello @FireWizard,
Keep in mind that you save that values to the filesystem and not to memory. Otherwise the values will not survive a reboot or power cut of your device.
See: Working with context
https://nodered.org/docs/user-guide/context
Looks like I have to change my settings.js first, don't have context storage.
The only thing you have to do is to save the data from the Shelly (C) and the data to the grid (B) to two flow variables at 00:00 h.
The next day at 00:00 h you deduct that value from the current value, so that you have the different values of the previous day.
And save back the new value, and so on. Do the calculations you want.
I got your point, but working with variables is something I do not understand right now. So I will try to understand this first and change my settings.js.
When I need further help I will ask.
Thanks again for your help and time.
Cheers
User avatar
FireWizard
Posts: 1763
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Need help for Node red flow "How much money I spent to my energy provider"

Post by FireWizard »

Hello @sailmich
Looks like I have to change my settings.js first, don't have context storage.
No, if your Node-RED configuration not has been changed after you installed it, your context store is in memory.
It is safe to use that for the time being.
I will try to understand this first
It is quit easy.

Let me explain with an example:

You know we have 4 seasons, called "Spring", "Summer", "Autumn" and "Winter".

We "Inject" these string variables and we store them in a flow variable, called Season.

Later on we Inject an e.g. empty message as a trigger to retrieve the value from the flow variable season.

I made a simple example flow.

Code: Select all

[
    {
        "id": "e01d1ef652048847",
        "type": "inject",
        "z": "972c14d502141bb6",
        "name": "Spring",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "Spring",
        "payloadType": "str",
        "x": 110,
        "y": 520,
        "wires": [
            [
                "b1141abd39e762c2"
            ]
        ]
    },
    {
        "id": "0d6e81ea7bad64d5",
        "type": "inject",
        "z": "972c14d502141bb6",
        "name": "Summer",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "Summer",
        "payloadType": "str",
        "x": 120,
        "y": 580,
        "wires": [
            [
                "b1141abd39e762c2"
            ]
        ]
    },
    {
        "id": "5890df61a7e263d4",
        "type": "inject",
        "z": "972c14d502141bb6",
        "name": "Autumn",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "Autumn",
        "payloadType": "str",
        "x": 110,
        "y": 640,
        "wires": [
            [
                "b1141abd39e762c2"
            ]
        ]
    },
    {
        "id": "e6e06dafdee96060",
        "type": "inject",
        "z": "972c14d502141bb6",
        "name": "Winter",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "Winter",
        "payloadType": "str",
        "x": 110,
        "y": 700,
        "wires": [
            [
                "b1141abd39e762c2"
            ]
        ]
    },
    {
        "id": "bb8d129a8f935d3d",
        "type": "inject",
        "z": "972c14d502141bb6",
        "name": "Trigger",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 110,
        "y": 780,
        "wires": [
            [
                "ad90aea5d8ab0a9e"
            ]
        ]
    },
    {
        "id": "ad90aea5d8ab0a9e",
        "type": "change",
        "z": "972c14d502141bb6",
        "name": "Get Season",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "season",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 310,
        "y": 780,
        "wires": [
            [
                "86233c92499871fa"
            ]
        ]
    },
    {
        "id": "b1141abd39e762c2",
        "type": "change",
        "z": "972c14d502141bb6",
        "name": "Set Season",
        "rules": [
            {
                "t": "set",
                "p": "season",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 310,
        "y": 620,
        "wires": [
            [
                "c4a780b6b9023a4b"
            ]
        ]
    },
    {
        "id": "c4a780b6b9023a4b",
        "type": "debug",
        "z": "972c14d502141bb6",
        "name": "debug 192",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 620,
        "wires": []
    },
    {
        "id": "86233c92499871fa",
        "type": "debug",
        "z": "972c14d502141bb6",
        "name": "debug 193",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 780,
        "wires": []
    }
]
Play with it, and then you will notice, it is very simple.

I also came across in the Node-RED forum a discussion: https://discourse.nodered.org/t/reset-s ... node/79492

Is this something you are interested in?

Regards
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Need help for Node red flow "How much money I spent to my energy provider"

Post by sailmich »

Hello @FireWizard,
again thank you very much, took me some time. I don't know if this is the best way but I hope it will run. I will observe it within the next days.
Spoiler: show

Code: Select all

[
    {
        "id": "27421d68571a5c13",
        "type": "function",
        "z": "0c833d4010de4b96",
        "name": "Usage/Electric idx358",
        "func": "msg.payload = { \"command\": \"udevice\", \"idx\": 358, \"nvalue\": 0, \"svalue\": (msg.payload[\"1-0:16.7.0*255\"].values[0].value).toString()};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 200,
        "wires": [
            [
                "6698212646ef8d52"
            ]
        ]
    },
    {
        "id": "6698212646ef8d52",
        "type": "mqtt out",
        "z": "0c833d4010de4b96",
        "name": "",
        "topic": "domoticz/in",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "f9f13036.e28b58",
        "x": 870,
        "y": 180,
        "wires": []
    },
    {
        "id": "808b95b995a23a6c",
        "type": "function",
        "z": "0c833d4010de4b96",
        "name": "RFX Counter kWh idx357",
        "func": "msg.payload = { \"command\": \"udevice\", \"idx\": 357, \"nvalue\": 0, \"svalue\": (msg.payload[\"1-0:1.8.0*255\"].values[0].value*1000).toString()};\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 310,
        "y": 160,
        "wires": [
            [
                "6698212646ef8d52"
            ]
        ]
    },
    {
        "id": "c192604df03245cd",
        "type": "smartmeter",
        "z": "0c833d4010de4b96",
        "name": "",
        "datasource": "34d070e3e0bdda8b",
        "protocol": "SmlProtocol",
        "transport": "SerialRequestResponseTransport",
        "requestInterval": 0,
        "d0WakeupCharacters": "",
        "d0SignOnMessage": "",
        "d0BaudrateChangeoverOverwrite": "",
        "protocolSmlIgnoreInvalidCRC": false,
        "debugging": false,
        "x": 70,
        "y": 180,
        "wires": [
            [
                "808b95b995a23a6c",
                "27421d68571a5c13",
                "aaee8db1fe3511f3",
                "4fc968a6b47f4844",
                "f4bcbda158a120d6"
            ]
        ]
    },
    {
        "id": "4fc968a6b47f4844",
        "type": "function",
        "z": "0c833d4010de4b96",
        "name": "negative.energy",
        "func": "msg.topic=\"to_provider\"\nmsg.payload = msg.payload[\"1-0:2.8.0*255\"].values[0].value;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 280,
        "y": 240,
        "wires": [
            [
                "b62a9e5c8a6096cd",
                "4f46922d002f8c1e"
            ]
        ]
    },
    {
        "id": "78c7e0be89559a89",
        "type": "http request",
        "z": "0c833d4010de4b96",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://192.168.178.102:6219/json.htm?type=graph&sensor=counter&idx=636&range=week",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 350,
        "y": 600,
        "wires": [
            [
                "630f2aca36207a94"
            ]
        ]
    },
    {
        "id": "630f2aca36207a94",
        "type": "json",
        "z": "0c833d4010de4b96",
        "name": "",
        "property": "payload",
        "action": "obj",
        "pretty": false,
        "x": 490,
        "y": 600,
        "wires": [
            [
                "3d692197ef7ff2d2"
            ]
        ]
    },
    {
        "id": "3d692197ef7ff2d2",
        "type": "function",
        "z": "0c833d4010de4b96",
        "name": "get.daily.production",
        "func": "msg.topic=\"day_production\"\nmsg.payload = msg.payload.result[7].v\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 600,
        "wires": [
            [
                "8f85345ddcedcc4e"
            ]
        ]
    },
    {
        "id": "8f85345ddcedcc4e",
        "type": "json",
        "z": "0c833d4010de4b96",
        "name": "day production",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 840,
        "y": 600,
        "wires": [
            [
                "890d55757f19d622"
            ]
        ]
    },
    {
        "id": "890d55757f19d622",
        "type": "join",
        "z": "0c833d4010de4b96",
        "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": 550,
        "y": 500,
        "wires": [
            [
                "30a78b5a4a9f416e"
            ]
        ]
    },
    {
        "id": "30a78b5a4a9f416e",
        "type": "change",
        "z": "0c833d4010de4b96",
        "name": "calculate",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.day_production-payload.calculate",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 680,
        "y": 500,
        "wires": [
            [
                "2832c0e3fe494ab4"
            ]
        ]
    },
    {
        "id": "b62a9e5c8a6096cd",
        "type": "change",
        "z": "0c833d4010de4b96",
        "name": "set neg mor",
        "rules": [
            {
                "t": "set",
                "p": "morning",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "evening",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 490,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "12dbffec1de34568",
        "type": "change",
        "z": "0c833d4010de4b96",
        "name": "get neg mor",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "negative",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "morning",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 390,
        "y": 340,
        "wires": [
            [
                "3a44088a33250087"
            ]
        ]
    },
    {
        "id": "02e53a5cafd679cd",
        "type": "inject",
        "z": "0c833d4010de4b96",
        "name": "00:05",
        "props": [],
        "repeat": "",
        "crontab": "05 00 * * *",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 220,
        "y": 340,
        "wires": [
            [
                "12dbffec1de34568"
            ]
        ]
    },
    {
        "id": "e72719bf3cad0d84",
        "type": "change",
        "z": "0c833d4010de4b96",
        "name": "get neg eve",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "negative",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "evening",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 390,
        "y": 380,
        "wires": [
            [
                "3a44088a33250087"
            ]
        ]
    },
    {
        "id": "a7b2f56e4e452d65",
        "type": "inject",
        "z": "0c833d4010de4b96",
        "name": "23:50",
        "props": [],
        "repeat": "",
        "crontab": "50 23 * * *",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 220,
        "y": 380,
        "wires": [
            [
                "e72719bf3cad0d84"
            ]
        ]
    },
    {
        "id": "3a44088a33250087",
        "type": "join",
        "z": "0c833d4010de4b96",
        "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": 530,
        "y": 360,
        "wires": [
            [
                "93efafe13bd245bc"
            ]
        ]
    },
    {
        "id": "93efafe13bd245bc",
        "type": "change",
        "z": "0c833d4010de4b96",
        "name": "cal neg",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.evening-payload.morning",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "calculate",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "calculate",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 660,
        "y": 360,
        "wires": [
            []
        ]
    },
    {
        "id": "4f46922d002f8c1e",
        "type": "change",
        "z": "0c833d4010de4b96",
        "name": "set neg eve",
        "rules": [
            {
                "t": "set",
                "p": "evening",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "evening",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 490,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "2832c0e3fe494ab4",
        "type": "function",
        "z": "0c833d4010de4b96",
        "name": "to domoticz",
        "func": "msg.payload = { \"command\": \"udevice\", \"idx\": 641, \"nvalue\": 0, \"svalue\": msg.payload.toString() };\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 850,
        "y": 500,
        "wires": [
            [
                "6698212646ef8d52"
            ]
        ]
    },
    {
        "id": "2925feb899166d20",
        "type": "change",
        "z": "0c833d4010de4b96",
        "name": "get cal neg",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "calculate",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "calculate",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 390,
        "y": 500,
        "wires": [
            [
                "890d55757f19d622"
            ]
        ]
    },
    {
        "id": "26d116068ce8f3b3",
        "type": "inject",
        "z": "0c833d4010de4b96",
        "name": "23:55",
        "props": [],
        "repeat": "",
        "crontab": "55 23 * * *",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 220,
        "y": 500,
        "wires": [
            [
                "2925feb899166d20"
            ]
        ]
    },
    {
        "id": "d748dcc441b58410",
        "type": "inject",
        "z": "0c833d4010de4b96",
        "name": "23:55",
        "props": [],
        "repeat": "",
        "crontab": "55 23 * * *",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 200,
        "y": 600,
        "wires": [
            [
                "78c7e0be89559a89"
            ]
        ]
    },
    {
        "id": "f4bcbda158a120d6",
        "type": "debug",
        "z": "0c833d4010de4b96",
        "name": "debug 12",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 120,
        "y": 240,
        "wires": []
    },
    {
        "id": "f9f13036.e28b58",
        "type": "mqtt-broker",
        "name": "localhost",
        "broker": "192.xxx.xxx.x",
        "port": "4711",
        "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": ""
    },
    {
        "id": "34d070e3e0bdda8b",
        "type": "smartmeter-connection",
        "sourcetype": "serial",
        "serialport": "/dev/ttyUSB0",
        "serialbaud": "9600",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "httphost": "localhost",
        "httpport": "80",
        "tcphost": "localhost",
        "tcpport": "502",
        "filepath": "/dev/null"
    }
]
I also came across in the Node-RED forum a discussion: https://discourse.nodered.org/t/reset-s ... node/79492

Is this something you are interested in?
I will have a closer look in near future.
Cheers
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests