LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Moderator: leecollings

eddieb
Posts: 335
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by eddieb »

Is there a place to find the latest version ? like on github ?
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jake »

eddieb wrote:Is there a place to find the latest version ? like on github ?
I shared the original LUA script in the initial post. I have no yet shared the dzVents version. Although I have a github account, I never published anything myself.

The script had some little errors today, I hope they're fixed by now. However, I have to wait for more sun and high energy consumers like boiling water or making coffee to test the results of the limited inverter capacity. For now I restricted it to 1000W.

When the script is correct, I will publish it here. In the mean time I will check out how to publish something on github.
jeroenkl
Posts: 113
Joined: Sunday 14 July 2013 22:00
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: NL
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jeroenkl »

jake wrote: Friday 19 March 2021 22:31
eddieb wrote:Is there a place to find the latest version ? like on github ?
I shared the original LUA script in the initial post. I have no yet shared the dzVents version. Although I have a github account, I never published anything myself.

The script had some little errors today, I hope they're fixed by now. However, I have to wait for more sun and high energy consumers like boiling water or making coffee to test the results of the limited inverter capacity. For now I restricted it to 1000W.

When the script is correct, I will publish it here. In the mean time I will check out how to publish something on github.
Great!
eddieb
Posts: 335
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by eddieb »

That would be great Jake, I would like to test this dzevents version if possible 8-)
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jake »

Update 02-04-201: DzVents version of the script, with additional functionality, can be found on GitHub!
Please test the new published version. Also, please help with suggestions how to handle GitHub for modifications
eddieb
Posts: 335
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by eddieb »

Hi, I installed the version from github, testing now ;-)
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
eddieb
Posts: 335
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by eddieb »

debugging looks OK

Code: Select all

 2021-04-05 17:38:13.117 Status: dzVents: Info: Hey solar battery: ------ Start internal script: SimSolarBattery: Device: "P1 kWh totaal (p1meter)", Index: 192
2021-04-05 17:38:13.120 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery: Custom sensor device adapter
2021-04-05 17:38:13.122 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery Usage: P1 smart meter energy device adapter
2021-04-05 17:38:13.123 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Lost Solar Energy: kWh device adapter
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: energymeter type = P1 Smart Meter
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: P1 meter: usage and return values will be used
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: maxBbatteryInverterEnergy = 3800 x (0 / 3600) = 0.0 Wh
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: Energy balance = -1 Wh (negative = consumption)
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: Negative Energybalance below max inverter capacity. inverterLostEnergy = 1 - 0.0 = 1.0
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: solar battery value = 1632.0 Wh, battery capacity is 8000 Wh, new solar battery value = 1632.0
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: batteryUsedEnergy = 0Wh
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: inverterLostEnergy = 1.0Wh
But the Virtual Solar Battery Value makes no sense ... it is either 0 (zero) or 3800 (the value of maxBatteryInverterEnergy) ... Even when the p1 usage is +1000w ... (the value in the bar of VirtualSolarBatteryValue should be about that ...)
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jake »

eddieb wrote: Monday 05 April 2021 17:43 debugging looks OK

Code: Select all

 2021-04-05 17:38:13.117 Status: dzVents: Info: Hey solar battery: ------ Start internal script: SimSolarBattery: Device: "P1 kWh totaal (p1meter)", Index: 192
2021-04-05 17:38:13.120 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery: Custom sensor device adapter
2021-04-05 17:38:13.122 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery Usage: P1 smart meter energy device adapter
2021-04-05 17:38:13.123 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Lost Solar Energy: kWh device adapter
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: energymeter type = P1 Smart Meter
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: P1 meter: usage and return values will be used
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: maxBbatteryInverterEnergy = 3800 x (0 / 3600) = 0.0 Wh
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: Energy balance = -1 Wh (negative = consumption)
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: Negative Energybalance below max inverter capacity. inverterLostEnergy = 1 - 0.0 = 1.0
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: solar battery value = 1632.0 Wh, battery capacity is 8000 Wh, new solar battery value = 1632.0
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: batteryUsedEnergy = 0Wh
2021-04-05 17:38:13.124 Status: dzVents: Debug: Hey solar battery: inverterLostEnergy = 1.0Wh
But the Virtual Solar Battery Value makes no sense ... it is either 0 (zero) or 3800 (the value of maxBatteryInverterEnergy) ... Even when the p1 usage is +1000w ... (the value in the bar of VirtualSolarBatteryValue should be about that ...)
The problem seems to be in this log line "maxBbatteryInverterEnergy = 3800 x (0 / 3600) = 0.0 Wh"

The '0' is the amount of seconds ago that the latest energy value was stored in the domoticz 'persistent data'. This is ok for the 1st time the script runs, because it did not contain a valid value, but for the 2nd time around it should be xxx seconds ago, giving a decent amount of Wh that can pass through the solar battery inverter.

2 questions:
do you have multiple triggers to trigger the script? Is your P1 meter triggering the script multiple times?
what is your script interval? did you change the default 60 to 0? Should be allowed, but worth the check.
eddieb
Posts: 335
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by eddieb »

jake wrote: Monday 05 April 2021 18:29 The problem seems to be in this log line "maxBbatteryInverterEnergy = 3800 x (0 / 3600) = 0.0 Wh"

The '0' is the amount of seconds ago that the latest energy value was stored in the domoticz 'persistent data'. This is ok for the 1st time the script runs, because it did not contain a valid value, but for the 2nd time around it should be xxx seconds ago, giving a decent amount of Wh that can pass through the solar battery inverter.

2 questions:
do you have multiple triggers to trigger the script? Is your P1 meter triggering the script multiple times?
what is your script interval? did you change the default 60 to 0? Should be allowed, but worth the check.
1 NO, I did not change anything in the script EXCEPT putting the correct device names in it
2 YES I changed the 60 to 0 ....

consumedEnergyMeter_name and producedEnergyMeter_name are both pointing to the same device (my p1 meter)

as my P1 updates every second, this script is triggered every second too
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jake »

eddieb wrote:
jake wrote: Monday 05 April 2021 18:29 The problem seems to be in this log line "maxBbatteryInverterEnergy = 3800 x (0 / 3600) = 0.0 Wh"

The '0' is the amount of seconds ago that the latest energy value was stored in the domoticz 'persistent data'. This is ok for the 1st time the script runs, because it did not contain a valid value, but for the 2nd time around it should be xxx seconds ago, giving a decent amount of Wh that can pass through the solar battery inverter.

2 questions:
do you have multiple triggers too trigger the script? Is your P1 meter triggering the script multiple times?
what is your script interval? did you change the default 60 to 0? Should be allowed, but worth the check.
1 NO, I did not change anything in the script EXCEPT putting the correct device names in it
2 YES I changed the 60 to 0 ....

consumedEnergyMeter_name and producedEnergyMeter_name are both pointing to the same device (my p1 meter)

as my P1 updates every second, this script is triggered every second too
Ah, the p1 updating every second is the 'issue'. Please update the script interval to 30 or 60 and the script should run fine.

I advise to not run the script too often: the amount of change in Wh in a few seconds is so small that calculations of the max inverter energy (based on power in Watt times script interval (in hours)) will result in a wrong interpretation due to rounding of numbers.
Currently I don't use the wattage from the p1 meter, but in case the script interval equals the p1 meter update, is would be a way to avoid the issues that you experience now.

eddieb
Posts: 335
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by eddieb »

Ok, so I need to change the trigger from "p1 meter" to a timed interval ?
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jake »

eddieb wrote:Ok, so I need to change the trigger from "p1 meter" to a timed interval ?
Nope, just the script interval value within the script (default value is 60)
eddieb
Posts: 335
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by eddieb »

Code: Select all

2021-04-05 19:12:00.086 Status: dzVents: Info: Hey solar battery: ------ Start internal script: SimSolarBattery: Device: "P1 kWh totaal (p1meter)", Index: 192
2021-04-05 19:12:00.089 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery: Custom sensor device adapter
2021-04-05 19:12:00.090 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery Usage: P1 smart meter energy device adapter
2021-04-05 19:12:00.091 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Lost Solar Energy: kWh device adapter
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: energymeter type = P1 Smart Meter
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: P1 meter: usage and return values will be used
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: maxBbatteryInverterEnergy = 3800 x (60 / 3600) = 63.333333333333 Wh
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: Energy balance = 21 Wh (negative = consumption)
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: Energy balance within capacity of battery inverter
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: solar battery value = 1928.0 Wh, battery capacity is 8000 Wh, new solar battery value = 1949.0
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: batteryUsedEnergy = 0Wh
2021-04-05 19:12:00.093 Status: dzVents: Debug: Hey solar battery: inverterLostEnergy = 0Wh
2021-04-05 19:12:00.095 Status: dzVents: Info: Hey solar battery: ------ Finished SimSolarBattery
Ok, changed that back to 60 ...

the "maxBbatteryInverterEnergy = 3800 x (60 / 3600) = 63.333333333333 Wh" still makes no sense to me ...
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jake »

eddieb wrote: Monday 05 April 2021 19:15

Code: Select all

2021-04-05 19:12:00.086 Status: dzVents: Info: Hey solar battery: ------ Start internal script: SimSolarBattery: Device: "P1 kWh totaal (p1meter)", Index: 192
2021-04-05 19:12:00.089 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery: Custom sensor device adapter
2021-04-05 19:12:00.090 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery Usage: P1 smart meter energy device adapter
2021-04-05 19:12:00.091 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Lost Solar Energy: kWh device adapter
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: energymeter type = P1 Smart Meter
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: P1 meter: usage and return values will be used
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: maxBbatteryInverterEnergy = 3800 x (60 / 3600) = 63.333333333333 Wh
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: Energy balance = 21 Wh (negative = consumption)
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: Energy balance within capacity of battery inverter
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: solar battery value = 1928.0 Wh, battery capacity is 8000 Wh, new solar battery value = 1949.0
2021-04-05 19:12:00.092 Status: dzVents: Debug: Hey solar battery: batteryUsedEnergy = 0Wh
2021-04-05 19:12:00.093 Status: dzVents: Debug: Hey solar battery: inverterLostEnergy = 0Wh
2021-04-05 19:12:00.095 Status: dzVents: Info: Hey solar battery: ------ Finished SimSolarBattery
Ok, changed that back to 60 ...

the "maxBbatteryInverterEnergy = 3800 x (60 / 3600) = 63.333333333333 Wh" still makes no sense to me ...
It is running just fine for you now, but I will explain:

you set the maximum (simulated) inverter power to 3800W. An inverter with this value can therefore in 1 hour convert a maximum of 3800W x 1h =3800Wh. However, your script triggers now every 60 seconds. In this time only 1/60th (60 / 3600 seconds/hr) of 3800Wh can be converted. This is the 63.3Wh that you see in your log file. Any value below will be dealt with, everything above is above the inverter power level and will be counted as 'lost energy'. (Since I don't care about an inverter power level (I have no clue what options of inverters there are out there) I have set mine at 10.000W.

Anyway, in your log file it shows that you had 21Wh of positive energy (most likely the sun was still shining at your place). Calculated back, the power of your PV?-system =~ 21 / (60/3600) =~ 1260W (+the directly consumed energy in the house, of course). You battery is topped up with the 21Wh, going from 1928 to 1949 (+21) Wh.
eddieb
Posts: 335
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by eddieb »

And there is the exact problem ...
my p1 was still sending more than 600w to the grid at that moment ...
the total counters on the p1battery device are fine, but the "current" counter in the top is not making sense to me ...

my SolarPanels produced more than 16kWh today with peaks up to 3700w ...
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jake »

Based on your initial setting (script interval set to 0 and P1-hardware updating every second) I have been thinking about a script improvement:

if (script interval = 0 AND energy meter is a p1-meter) then
use the P1-meter wattage to compare to the 'inverter power level')
calculate maximum battery by usage on the P1-meter wattage (when this is higher than the 'inverter power level')
else
use existing method
end

In 2 situations this might lead to unwanted results:
- 'inverter power level' is rather small (<3600W?)
- P1-meter update frequency is high (every second)

Example of unwanted situation:
If consumption or production is 1800W and update frequency is 1 second, then every second just 0.5Wh is used/generated. When the P1-meter updates in Wh only, it will update the first second 1Wh, but the 2nd second 0Wh etc.

My recommendation:
With a small 'inverter power level' make the script interval high, 60 seconds
With a big 'inverter power level' you can decrease the script interval and still be accurate
With an 'unlimited inverter power level' it doesn't matter what the script interval is, the solar battery status will be very accurate in any case (remember that Domoticz will simplify the graphs to 5 minutes intervals anyway and therefore nuances around maximum of empty battery values won't be seen and have minor effect)
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jake »

eddieb wrote: Monday 05 April 2021 19:41 And there is the exact problem ...
my p1 was still sending more than 600w to the grid at that moment ...
the total counters on the p1battery device are fine, but the "current" counter in the top is not making sense to me ...

my SolarPanels produced more than 16kWh today with peaks up to 3700w ...
Yes, but the script only started running an hour ago? (correctly) and therefore it is not aware of anything that happened before that. Compare it to buying a phyical solar battery and plugging it in at 17:00 in the afternoon. It would show you the same numbers as on your virtual battery at the moment. Tomorrow you will see numbers that make more sense to you, because it will go one-to-one with the P1-meter.

PS: number of returned energy of the P1-meter won't be equal to the battery level, since you will be using from the virtual battery as well.
eddieb
Posts: 335
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by eddieb »

Hi Jake,

tnx for trying to explain ...
I am aware that this script did start halfway this day, it will not match other counters ...

I am trying to understand what is happening.

My p1meter goes from -3500 to +7000 depending on my consumption and the performance of the solarpanels ...
I assume that what my p1meter tells me is correct, so if my p1meter tells me for 1 hour that it pushes 3500w to the grid,
that should be the same value that goes in the virtual battery, the charge should go from zero to 3500 in that hour and the p1battery should do approximatly the same, in the topbar it should say 3500 for an hour and both counters should match.
The counter lost solar energy will grow it the virtual battery is empty ...

And now I am lost ...

there are 3 values on the p1battery, both totalcounters are correct but the counter in the top bar does not make sense to me ...

You explained that putting the interval to zero could produce 0 on second 1 and 3800 on second 2 and so on ...
That is exactly what it did ...

BUT, no device is producing 3800, the max is 3500. and that number is not used in the top-bar of the p1battery device...

I tried changing the interval to several values (0,1,2,5,10,20,30,60) but none is giving me a value I expect.

Of course this could be my misunderstanding ...
I tried to include a screenprint but the forum will not accept screenprint because of some max reached
Eddie
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jake »


eddieb wrote:Hi Jake,

tnx for trying to explain ...
I am aware that this script did start halfway this day, it will not match other counters ...

I am trying to understand what is happening.

My p1meter goes from -3500 to +7000 depending on my consumption and the performance of the solarpanels ...
I assume that what my p1meter tells me is correct, so if my p1meter tells me for 1 hour that it pushes 3500w to the grid,
To be precise: you mean there is a constant production of 3500W to the grid for 1 hr, resulting in 3500Wh.?
that should be the same value that goes in the virtual battery, the charge should go from zero to 3500 in that hour and the p1battery should do approximatly the same, in the topbar it should say 3500 for an hour and both counters should match.
The 'Virtual Solar Battery' shows the absolute level of energy in the battery
The 'Virtual Solar Battery Usage' shows power and energy in and out of the battery. The daily energy is or course reset to 0 at midnight, like any other P1-meter daily value. Only on your first day (or an empty battery before midnight) should result in an easy calculation: 'solar battery' = ' solar battery usage (return1)' - 'solar battery usage (usage1)'.
In my situation this is the case: my 'battery was empty at midnight (due to little sunshine on Sunday) and my battery level is currently: 0.121kWh. My P1 usage meter shows for 'Energy Returned': 3.739 kWh and the 'Energy usage': 3.618 kWh. Subtracted makes exactly the 0.121kW remaining in the battery.

Your hardware P1 meter log shows for that mentioned hour a flat -3500W of 'return 1' (or return 2, depending on tariff)? if yes, than the solar battery indeed should be filled to 3.5 kWh. and the top bar of the virtual P1-meter should show the same -3500W (actually, as long as the power is between -3800 and +3800W, the virtual P1-meter should show an equivalent number. It can be slightly off, because your P1-meter updates every second and the virtual battery usage P1-meter only at the specified interval. It will therefore show an average number.
The counter lost solar energy will grow it the virtual battery is empty ...
Meaning that power levels were at least constantly below the max. level of 3800W
And now I am lost ...

there are 3 values on the p1battery, both totalcounters are correct but the counter in the top bar does not make sense to me ...

You explained that putting the interval to zero could produce 0 on second 1 and 3800 on second 2 and so on ...
That is exactly what it did ...

BUT, no device is producing 3800, the max is 3500. and that number is not used in the top-bar of the p1battery device...
I tried changing the interval to several values (0,1,2,5,10,20,30,60) but none is giving me a value I expect.
So, the power, shown in the top of the "Virtual Solar Battery Usage' P1-device is showing jumping numbers between 0 and 3800? These numbers are only updated at the specified 'script interval' seconds that you specificy in the script, no more.

If it shows 3800W in your case, you should also find some information in the log file at the same time with a text like: "Positive energybalance above max inverter capacity. inverterLostEnergy = xyz".

The same when your power consumption from the grid > 3800W, than it should read in the log " Negative Energybalance below max inverter capacity. inverterLostEnergy = "
at the same time the 'lost energy' counter should start increasing.

(Disclaimer: the Power shown in the top bar of the virtual P1-device is only for 'show', the device itself acts on the supplied energy counter numbers and even the displayed power in the graphs is based on calculation from 'energy'. It therefore sometimes shows a power level which is slightly higher/lower than the given maximum 'inverter power level'.)
Of course this could be my misunderstanding ...
I tried to include a screenprint but the forum will not accept screenprint because of some max reached
Eddie
Too bad. It learned me another lesson today: progamming something that is used in another environment than your own, is tough. I already added a lot more error checking or options than every needed for my own, but obviously I still didn't think through all user cases so far.

But never mind, I see small errors in my code, or optimizations, based on (your) feedback. Let's see what tomorrow's numbers say. Hopefully they give better results.
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy

Post by jake »

I have updated the code a little, some cleaning up, additional debug logging + a check if a small inverter power level and short script interval are not causing unacceptable calculation deviations (now set at max. 10%).

Still, at very low power levels at the hardware P1-meter (< 300W), the virtual meters power levels may jump up and down around the actual number, due to reporting in whole Wh numbers. For the calculated Wh numbers this is no problem. The displayed power levels are more easthetic than useful, it just gives a better interpretation than Energy in Wh.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest