Re: LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy
Posted: Friday 19 March 2021 7:17
Is there a place to find the latest version ? like on github ?
Open source Home Automation System
https://forum.domoticz.com/
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.eddieb wrote:Is there a place to find the latest version ? like on github ?
Great!jake wrote: ↑Friday 19 March 2021 22:31I 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.eddieb wrote:Is there a place to find the latest version ? like on github ?
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.
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
The problem seems to be in this log line "maxBbatteryInverterEnergy = 3800 x (0 / 3600) = 0.0 Wh"eddieb wrote: ↑Monday 05 April 2021 17:43 debugging looks OK
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 ...)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
1 NO, I did not change anything in the script EXCEPT putting the correct device names in itjake 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.
Ah, the p1 updating every second is the 'issue'. Please update the script interval to 30 or 60 and the script should run fine.eddieb wrote:1 NO, I did not change anything in the script EXCEPT putting the correct device names in itjake 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.
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
Nope, just the script interval value within the script (default value is 60)eddieb wrote:Ok, so I need to change the trigger from "p1 meter" to a timed interval ?
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
It is running just fine for you now, but I will explain:eddieb wrote: ↑Monday 05 April 2021 19:15Ok, changed that back to 60 ...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
the "maxBbatteryInverterEnergy = 3800 x (60 / 3600) = 63.333333333333 Wh" still makes no sense to me ...
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.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 ...
To be precise: you mean there is a constant production of 3500W to the grid for 1 hr, resulting in 3500Wh.?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,
The 'Virtual Solar Battery' shows the absolute level of energy in the batterythat 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.
Meaning that power levels were at least constantly below the max. level of 3800WThe counter lost solar energy will grow it the virtual battery is empty ...
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.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.
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.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