diy solar

diy solar

How to calculate kWh from PV watts?? (for home assistant)

Archerite

New Member
Joined
Sep 22, 2021
Messages
102
Location
Netherlands
Over the last 12-15 months I have been starting with a solar setup on a balcony. It works great! And over the year I have made upgrades here and there, learned a lot about wires, electricity, amps, watts and all that. It's mostly victron equipment and I use VenusOS on a Raspberry Pi to upload to the VRM dashboard. As said this all works perfectly...but I wanted to make it more "smart" by hooking it into my Home Assistant!

For that I use node-red (not on the rpi) that connects to the MQTT on VenusOS and collect the statistics, reformat the raw values and put them into HomeAssistant. It took me a couple day's to get it right but I can now see total solar production from 4 SCC's and the battery percentage directly in home assistant! And based on these values I can trigger any automation I want! The only useful one right now is turning on the grid-charger when SoC is at 25% and then off at 50%-75%. This all works great and now I don't have to worry about plugging the charger in on time....it's connected on a "Smart plug" that I can turn on-off from HomeAssistant. And having the battery SoC in there to means it all goes automatic now! :)

Inside Home Assistant there is a "energy dashboard" and for "grid input" I have chosen the smartplug that my charger is plugged into. That works fine as the required kWh counter with history is generated automatically. But since the solar production is coming from node-red entities...I need to do some more work on it. Instead of just giving it the current watt's produced I need to give it a kWh value that is incremented slowly with actual production. I think. Because just dividing by 1000 does not give me the desired results...to say the least.

So that is my situation....now here is my actual question: How do I convert the current total watts from the PV into an accumulated kWh counter?

I am terrible at math...and I have no idea how to effectively search for the answer online or in this forum. Nearly everything I got is related to how to calculate how much an appliance uses over a period of time. That bit I got just fine and is not what I need. I need to keep a counter of the solar production...and therefore convert the watts reported by the SCC's into an accumulated kWh counter.

While my math skills are limited....I can convert "simple" calculations into programming code. On another site more related to gaming....I have talked about my homebrew game project. It's a platform game and the character jumps on platforms and there is gravity and things like that. LOT's of calculations...that I do wrong...but for the most part it's working fine for a prototype. Just mentioning this to make clear I do know a little about programming. ;)

Sorry if this is a stupid beginners question. But it's something you take for granted when using a dashboard like VRM or automatic counters from smart plugs. And I do know if something uses 100 watts it will have used 1 kWh after 10 hours. And that in my small solar system 130 watts of PV for an hour is 0.130 kWh. But I have no idea how to reduce that in case the PV goes to 160 or down to 50 watts for 5 minutes. And then still keep track of the kWh that were produced.

I hope anything above here makes sense to understand my question. Sorry if it's not. ?

Thanks in advance for any helps or tips.
 
Should be relatively simple for you then... all you need to do is integrate the power over time to give you an energy value.

Measure the power at regular intervals, accumulate them together and divide the result by the elapsed time. The smaller the sampling period, the more accurate the result will be (e.g. every 5 - 10s would be good).
 
Should be relatively simple for you then... all you need to do is integrate the power over time to give you an energy value.

Measure the power at regular intervals, accumulate them together and divide the result by the elapsed time. The smaller the sampling period, the more accurate the result will be (e.g. every 5 - 10s would be good).
Thanks for the confidence boost! :):ROFLMAO:

I do already limit the number of updates to Home Assistant at 5 second intervals from the Node-Red flow. I am using a function block before that right now to reformat the values from MQTT and send it to the HA sensor nodes. I was using that block for this calculation too...but now I think of it that code might run more often than I think it does! Every MQTT message...actually!

I might need to place a second function node AFTER the 5 second limiter and do the kWh counter there instead! But then I still don't know the exact formula (is that what it's called?) to do the calculation correctly. Is something like this correct?:

kwh_increment = ((pv_watts / 60) / 12) / 1000;

if pv_watts would have been 100....I get: 0.000138889 from the calculation above. So if I keep a counter and increment it with this every 5 seconds for an hour that gives me 0.1000008! (since a minute is 12 x 5 second intervals...times 60 is 720. Then 720 x 0.000138889 gives me this result)

I think this will actually work! Thanks for the push in the right direction...I will let you know if it worked. :)
 
I just recently solved a similar issue in HA
I have power sensors from my emporia vue system that are sent to HA, they only provide the current power being used in watts

the energy dashboard in HA requires that the input sensor are in kwh
the solution was to use a helper in HA, called https://www.home-assistant.io/integrations/integration/

no changes to the yaml are required
let me know if you have any issues getting it working

The energy dashboard takes energy sensors (measured in Wh or kWh).

If your devices do not report energy consumption you can calculate it from the power sensors using the Riemann Sum integration:

favicon.ico
Home Assistant
default-social.png

Integration - Riemann sum integral 2

Instructions on how to integrate Integration Sensor into Home Assistant.



Integrating power with respect to time gives you energy.

Pay particular attention to the Integral method option. You probably want the left method.

These will be always increasing sensors. Which is fine for the energy dashboard
 
Last edited:
let me know if you have any issues getting it working
I have added the helper using the mppt_yield value as the input source. But I assume it won't work until some actual values are updated right? I have 0 watts of solar at the moment! :ROFLMAO: .... sunset is setting in.

I can't select the helper as the solar input source yet unfortunately. I'll try again tomorrow after some power is generated....if this works then it's a far better solution than my own calculations in node-red. no need to reinvent the wheel if someone already did that ofcourse. :)

Thanks for the suggestion.
 
I have added the helper using the mppt_yield value as the input source. But I assume it won't work until some actual values are updated right? I have 0 watts of solar at the moment! :ROFLMAO: .... sunset is setting in.

I can't select the helper as the solar input source yet unfortunately. I'll try again tomorrow after some power is generated....if this works then it's a far better solution than my own calculations in node-red. no need to reinvent the wheel if someone already did that ofcourse. :)

Thanks for the suggestion.
the new entity will not show up to be input into the energy dashboard until it does get some data, should be avbl after the sun comes up
 
1671449002202.png

While it was literally freezing there were also a few hours of direct sun light! Just enough to get some statistics and see that the helper is working. Thanks again for the suggestions.
 
Back
Top