GMTrevis / Homeassistant-NodeRed-Systemair-VTR300

Sytemair VTR300 integration to Homeassistant using Node Red
41 stars 10 forks source link

Energy consumption #13

Open mist0706 opened 1 year ago

mist0706 commented 1 year ago

Hi!

All of the calculations of the tilfört/förbruk are currently not working. I'm not seeing any note of it in the readme. I've changed the tp_link sensor to my own tasmota sensor so i atleast have the consumption tracked.

My suspicion is that the value of "Strompris_tot_kr_kWt" needs to be defined somewhere, perhaps pulled from the "official" nordpool integration?

/David

GMTrevis commented 1 year ago

Hi,

Yes, in order to accumulate the energy costs, you need to set the global variable "Strompris_tot_kr_kWt" in a different node, as this variable is being called in the function nodes that accumulate the daily, weekly, monthly, yearly and total energy costs. I've done it as shown below. Hope it helps.

image

[{"id":"8274e5b2.be80c8","type":"change","z":"a7dcebd6.4440a8","name":"Set flow","rules":[{"t":"set","p":"#:(storeInFile)::Strompris_paslag","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":1500,"wires":[[]]},{"id":"ee83aa99.4821d8","type":"server-state-changed","z":"a7dcebd6.4440a8","name":"Leverandør påslag [Øre/kWh]","server":"2c4e313e.d0fc5e","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.strompris_paslag","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"10","forType":"num","forUnits":"seconds","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":160,"y":1500,"wires":[["68274c9b.c631a4"]]},{"id":"68274c9b.c631a4","type":"function","z":"a7dcebd6.4440a8","name":"Øre -> Kr","func":"var ore = msg.payload;\nvar kr = (ore/100);\n\nmsg.payload = kr;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":1500,"wires":[["8274e5b2.be80c8"]]},{"id":"4ddb4f4e.02241","type":"change","z":"a7dcebd6.4440a8","name":"Set flow","rules":[{"t":"set","p":"#:(storeInFile)::Strompris_avgift_energifondet","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":1460,"wires":[[]]},{"id":"f73311c5.aa5be","type":"server-state-changed","z":"a7dcebd6.4440a8","name":"Energifond avgift [øre/kWt]","server":"2c4e313e.d0fc5e","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.strompris_avgift_energifondet","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":1460,"wires":[["da3f7d22.a1038"]]},{"id":"da3f7d22.a1038","type":"function","z":"a7dcebd6.4440a8","name":"øre/kWt --> Kr/kWt","func":"var ore_kwt = msg.payload;\nvar kr_kwt = (ore_kwt/100);\n\nmsg.payload = kr_kwt;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":1460,"wires":[["4ddb4f4e.02241"]]},{"id":"fc299e80d6668c31","type":"function","z":"a7dcebd6.4440a8","name":"øre/kWt --> Kr/kWt","func":"var ore_kwt = msg.payload;\nvar kr_kwt = (ore_kwt/100);\n\nmsg.payload = kr_kwt;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":1420,"wires":[["56affef30656f11b"]]},{"id":"048469a7c51aa97f","type":"server-state-changed","z":"a7dcebd6.4440a8","name":"Energiledd avgift [øre/kWt]","server":"2c4e313e.d0fc5e","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.strompris_energiledd","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":1420,"wires":[["fc299e80d6668c31"]]},{"id":"acfc813751d58605","type":"function","z":"a7dcebd6.4440a8","name":"øre/kWt --> Kr/kWt","func":"var ore_kwt = msg.payload;\nvar kr_kwt = (ore_kwt/100);\n\nmsg.payload = kr_kwt;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":1380,"wires":[["72f5b6ff111f01fb"]]},{"id":"710ec28bec1db214","type":"server-state-changed","z":"a7dcebd6.4440a8","name":"Forbruksavgift [øre/kWt]","server":"2c4e313e.d0fc5e","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.strompris_forbruksavgift","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":1380,"wires":[["acfc813751d58605"]]},{"id":"56affef30656f11b","type":"change","z":"a7dcebd6.4440a8","name":"Set flow","rules":[{"t":"set","p":"#:(storeInFile)::Strompris_energiledd","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":1420,"wires":[[]]},{"id":"72f5b6ff111f01fb","type":"change","z":"a7dcebd6.4440a8","name":"Set flow","rules":[{"t":"set","p":"#:(storeInFile)::Strompris_forbruksavgift","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":1380,"wires":[[]]},{"id":"22d45609.057bea","type":"function","z":"a7dcebd6.4440a8","name":"Tot. strømpris [Kr/t/s]","func":"var nordpool = msg.payload; // Nordpool strømpris [Kr/kWh]\n//var nordpool = parseFloat(msg.payload); // Nordpool strømpris [Kr/kWh] - Tvinger string til Float...\nvar paslag = flow.get(\"Strompris_paslag\",\"storeInFile\"); // Henter påslags pris fra leverandør lagret i Mem. [Kr/kWh]\nvar energiledd = flow.get(\"Strompris_energiledd\", \"storeInFile\"); // Energiledd avgift [ore/kWt]\nvar forbruksavgift = flow.get(\"Strompris_forbruksavgift\", \"storeInFile\"); // Forbruksavgift [ore/kWt]\nvar avgift_energifondet = flow.get(\"Strompris_avgift_energifondet\", \"storeInFile\"); // Energiledd avgift [ore/kWt]\n\n if (isNaN(nordpool) || isNaN(paslag)) {\n return;\n } \n\nvar tot_kr_kWt = (nordpool + energiledd + forbruksavgift + avgift_energifondet + paslag);\n\nvar solar_fratrekk = 0.01; // 0.01,- Kr fratrekk pr. kWt fra strømleverandør for solgt strøm (beregning av solgt energi til nettleverandør) \nvar sell_price_kr_kwt = (nordpool - solar_fratrekk); // Det man for fra strømleverandør for salg pr. kWt \n\n// Lagrer tot. kW/t kostnad for global bruk (Mem).\nglobal.set(\"Strompris_tot_kr_kWt\", tot_kr_kWt,\"default\");\nglobal.set(\"nordpool_strompris_kr_kWt\", nordpool, \"default\");\n \n// Lagrer tot. kW/5s kostnad for global bruk (Mem).\nglobal.set(\"Solarprice_sell_price_kw\", sell_price_kr_kwt, \"default\"); \n\n// Estimert levert effekt & energi total\nvar tot_kr_kWt_out = {payload:parseFloat((tot_kr_kWt).toFixed(2))};\nvar solarprice_sell_price_out = {payload:parseFloat((sell_price_kr_kwt).toFixed(2))};\n\nreturn [tot_kr_kWt_out, solarprice_sell_price_out];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":940,"wires":[["a3f0693a8df4fce0"],[]],"outputLabels":["tot_kr/kWt","Solar sell price kr/kWt"]},{"id":"899026e1.e15ac8","type":"poll-state","z":"a7dcebd6.4440a8","name":"Noordpol timepris [Øre/kWh]","server":"2c4e313e.d0fc5e","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"10","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":true,"entity_id":"sensor.nordpool_kwh_krsand_nok_3_095_025","state_type":"num","halt_if":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"x":160,"y":940,"wires":[["22d45609.057bea","0f758aaf22a92935"]]},{"id":"a3f0693a8df4fce0","type":"ha-sensor","z":"a7dcebd6.4440a8","name":"Kostnad nåverdi [Kr/kWt]","entityConfig":"8331a6f7.6a4128","version":0,"state":"payload","stateType":"msg","attributes":[{"property":"Nettleie Kr pr dag","value":"Strompris_nettleie_dag","valueType":"flow"},{"property":"Påslag Kr pr kWh","value":"Strompris_paslag","valueType":"flow"}],"inputOverride":"allow","outputProperties":[],"x":630,"y":940,"wires":[[]]},{"id":"2c4e313e.d0fc5e","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"8331a6f7.6a4128","type":"ha-entity-config","server":"2c4e313e.d0fc5e","deviceConfig":"","name":"sensor config for Kostnad nåverdi [Kr/kWt]","version":6,"entityType":"sensor","haConfig":[{"property":"name","value":"strompris_tot_naverdi"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:cash-multiple"},{"property":"unit_of_measurement","value":"Kr"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"resend":true}]

//GM

mist0706 commented 1 year ago

Thanks! But where is this node? I'm looking around like crazy... Sorry for the inconvenience, i really appreciate all the effort you put into this. It has actually taught me how my ventilation works

mist0706 commented 1 year ago

I added the node you posted as i couldn't find an existing one, i selected my price under nordpol timepris. I'm still getting validation error at Tilfört effekt though

image

GMTrevis commented 1 year ago

But where is this node?

The node is in a different flow/page because the flow does not specifically belong to the ventilation flow/page (system). It's global because it's also being used across other flows/pages. Later when i have more time available i will add it to the readme description.

I'm still getting validation error at Tilfört effekt though

Have you added the setpoints in HA and given them vales?, ref. pic. below. If you don't want it like this, you need to change the code to your liking (maybe you only want hardcoded values instead of setpoints as i have?).

If you haven't added the setpoints in HA you can add them as input numbers in HA as i have or select the "Expose to Home Assistant" in the "Edit events: state node" in node red. I've shared the setpoints (input_number) in my HA config below, that's how i did it.

You can also delete the code for solar in the function node "Tot. strømpris [Kr/t/s]" (i just copied what i had). image

Input_number in my HA config: (i have split my HA cofig, the spaces from left in the config can be different from yours)

--------------- Tilleggskostnader strømleverandør ----------------|

strompris_energiledd: name: Energiledd min: 0 max: 1000 step: 0.001 mode: box unit_of_measurement: 'øre/kWt' icon: mdi:cash

strompris_forbruksavgift: name: Forbruksavgift min: 0 max: 1000 step: 0.001 mode: box unit_of_measurement: 'øre/kWt' icon: mdi:cash

strompris_avgift_energifondet: name: Energifond avgift min: 0 max: 1000 step: 0.001 mode: box unit_of_measurement: 'øre/kWt' icon: mdi:cash

strompris_paslag: name: Påslag min: 0 max: 500 step: 0.01 mode: box unit_of_measurement: 'Øre/kWh' icon: mdi:cash

Setpoints look like this in my HA: image

Hope it helps. //GM

mist0706 commented 1 year ago

Added the input_number however it's still getting validation error. I also cleaned up the solar stuff. Any other ideas? Can i get you any debug log or other code from my nodes for troubleshooting?

GMTrevis commented 1 year ago

If you add a debug node, what does it say? (not sure if it's gonna explain the issue). Does the setpoint values get written in the flow context, as shown in the pic. below?

image

mist0706 commented 1 year ago

I'm very unfamiliar with node-red. I did attempt to add a debug node but honestly i think i did it incorrectly Screenshot 2023-05-29 at 11 50 57

GMTrevis commented 1 year ago

No worries, we all start at a point:) Anyway, have you configured the flow context in the settings.js file according to the readme? I suspect you have not added the config for flow context, could that be it? (ref. the "Flow context" chapter in the readme).

In e.g. the change nodes you should have the options to save flow context to either "default" or "storeInFile" as shown in the pic. below. If you have used other names in the settings.js file, you will have to use the names you have given the "localfilesystem" and "memory". The settings.js file is located in config --> nodered folder. image

mist0706 commented 1 year ago

I've now added the flow context to the settings.js file and it's showing up as running. I'm hoping it'll accumulate some values over night because it now longer shows value error!

Screenshot 2023-05-29 at 23 01 47

I do have a lot of questions still though such as why my "settings" buttons aren't working... But lets hope the tilfört/förbruk values start populating during the night

again, thanks a lot for the help. It really means a lot!

GMTrevis commented 1 year ago

Are the flow context now being stored and called in the function nodes correctly? You should now have flow context available according to the pic. below.

The setting buttons are not working after "Browser mod" went through a major change earlier, the yaml pop scripts no longer works after that change and i have not found a way of making further use of the popup scripts. This issue is reported in the following issue https://github.com/GMTrevis/Homeassistant-NodeRed-Systemair-VTR300/issues/10

Anyway, i have "solved" this by moving the popup script (scriptspoup vtr300.yaml) to UI and with minor changes. I would like to have the popup script but as far as i have found out, it's not possible for proper functionality.

image

UI code for popups below. You need to have browser mod installed and remove or comment away the scriptspoup vtr300.yaml. You also have to change some entities like ppm sensors and more, depending if you have change entity names or not) image

VTR300 UI PopUp config.txt