Page 5 of 6

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

Posted: Tuesday 06 April 2021 7:47
by eddieb
running the 0.1.3 version now ...

Code: Select all

2021-04-06 07:45:04.002 Status: dzVents: Info: Hey solar battery: ------ Start internal script: SimSolarBattery: Device: "P1 kWh totaal (p1meter)", Index: 192
2021-04-06 07:45:04.005 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery: Custom sensor device adapter
2021-04-06 07:45:04.006 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery Usage: P1 smart meter energy device adapter
2021-04-06 07:45:04.007 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Lost Solar Energy: kWh device adapter
2021-04-06 07:45:04.008 Status: dzVents: Debug: Hey solar battery: energymeter type = P1 Smart Meter
2021-04-06 07:45:04.008 Status: dzVents: Debug: Hey solar battery: P1 meter: usage and return values will be used
2021-04-06 07:45:04.008 Status: dzVents: Debug: Hey solar battery: maxBbatteryInverterEnergy = 3800 x (61 / 3600) = 64.4 Wh
2021-04-06 07:45:04.008 Status: dzVents: Debug: Hey solar battery: Energy balance = -4 Wh (negative = consumption)
2021-04-06 07:45:04.009 Status: dzVents: Debug: Hey solar battery: Energy balance within capacity of battery inverter
2021-04-06 07:45:04.009 Status: dzVents: Debug: Hey solar battery: solar battery value = 0.0 Wh, battery capacity is 8000 Wh, new solar battery value = -4.0
2021-04-06 07:45:04.009 Status: dzVents: Debug: Hey solar battery: battery Used Energy = 0Wh
2021-04-06 07:45:04.009 Status: dzVents: Debug: Hey solar battery: battery Prod Energy = 0Wh
2021-04-06 07:45:04.009 Status: dzVents: Debug: Hey solar battery: battery Lost Energy = 4.0Wh
2021-04-06 07:45:04.009 Status: dzVents: Debug: Hey solar battery: inverter Lost Energy = 0Wh
2021-04-06 07:45:04.011 Status: dzVents: Info: Hey solar battery: ------ Finished SimSolarBattery
do you have a preferred way to receive some screenshots ? (PM/github/??)

Eddie

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

Posted: Tuesday 06 April 2021 8:31
by jake
With an empty battery, the log is normal. Therefore please post some screenshots to clarify the problem. Let's do that on github (that whole system is a learning curve for me), so we can close the issue as soon as it is solved.

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

Posted: Tuesday 06 April 2021 8:37
by eddieb
Ok, I created an issue on github.

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

Posted: Tuesday 06 April 2021 16:24
by McMelloW
jake wrote: Friday 02 April 2021 13:57 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
Hi Jake,
Going to try out your latest script. Created the devices and variables as explained in the source. Just copied your source into the event editor and changed the names to my P1 Meter Names. Switched it on and saved and off it went. Good job.

Just two questions.
I cannot get rid of a load on loglines.

Code: Select all

2021-04-06 16:01:39.048 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;120"
2021-04-06 16:01:40.062 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;123"
2021-04-06 16:01:41.048 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;124"
2021-04-06 16:01:42.056 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;123"
2021-04-06 16:01:43.115 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;120"
2021-04-06 16:01:44.071 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;128"
2021-04-06 16:01:45.050 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;129"
2021-04-06 16:01:46.068 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;132"
2021-04-06 16:01:47.060 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;135"
2021-04-06 16:01:48.044 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;134"
2021-04-06 16:01:49.062 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;140"
2021-04-06 16:01:50.080 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648214;0;153"
2021-04-06 16:01:51.075 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648215;0;160"
2021-04-06 16:01:52.062 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648215;0;165"
2021-04-06 16:01:53.089 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648215;0;175"
2021-04-06 16:01:54.069 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648215;0;172"
2021-04-06 16:01:55.081 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648215;0;179"
2021-04-06 16:01:56.061 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648215;0;174"
2021-04-06 16:01:57.085 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648215;0;171"
2021-04-06 16:01:58.053 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648215;0;169"
2021-04-06 16:01:59.084 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648215;0;168"
2021-04-06 16:02:00.065 Status: dzVents: Info: Handling events for: "Power", value: "4055887;3431466;2522893;5648215;0;161"
Changed line 54 to level = domoticz.LOG_ERROR but still a lot of lines. Actually, I would like to see only a log line in case of an ERROR.
Also the interval is ever 1/10th second as you can see on the time stamp. Line 26 the scriptinterval = 60

Second question.
Why are reading the produced power from the P1 Meter and not directly from the inverter?

Thanks for al your work on this script, keep you updated on my experiences

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

Posted: Tuesday 06 April 2021 17:23
by jake
McMelloW wrote: Tuesday 06 April 2021 16:24
jake wrote: Friday 02 April 2021 13:57 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
Hi Jake,
Going to try out your latest script. Created the devices and variables as explained in the source. Just copied your source into the event editor and changed the names to my P1 Meter Names. Switched it on and saved and off it went. Good job.

Just two questions.
I cannot get rid of a load on loglines.
...
Changed line 54 to level = domoticz.LOG_ERROR but still a lot of lines. Actually, I would like to see only a log line in case of an ERROR.
Also the interval is ever 1/10th second as you can see on the time stamp. Line 26 the scriptinterval = 60

Second question.
Why are reading the produced power from the P1 Meter and not directly from the inverter?

Thanks for al your work on this script, keep you updated on my experiences
Thanks for your kind words!

Changing to lOG_ERROR should do it. Have you checked your dzVents settings itself? Please make sure that log level there is also just set to 'ERROR'.

0th and 2nd question: the script is triggered on the P1-meter update, but only executed at the specified interval.
Reason for specifying the P1-meter and not the solar inverter (keep in mind, in this script is now introduced a virtual! battery inverter, that simulates charging/depleting the battery from/to 230V), is that in this script we only care about energy leaving the house, not so much about production of the solar system. In the ideal situation all generated energy is consumed at once, but unfortunately most times the production and consumption are at different times (in my case, I use around 30% of the solar energy directly, the rest is fed back to the grid)

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

Posted: Tuesday 06 April 2021 17:35
by waaren
McMelloW wrote: Tuesday 06 April 2021 16:24 Changed line 54 to level = domoticz.LOG_ERROR but still a lot of lines. Actually, I would like to see only a log line in case of an ERROR.
Also the interval is ever 1/10th second as you can see on the time stamp. Line 26 the scriptinterval = 60
According to the time stamp, the script is triggered every second and that is most likely the result of the setting for the P1 hardware update frequency.

With regards to the log; the above loglines are not specific for this script but are generic for all dzVents scripts based on the settings.

Did you try to change the event / dzVents log settings via [setup][settings][other] bottom of the page (see below)?
log settings.png
log settings.png (22.26 KiB) Viewed 2400 times

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

Posted: Tuesday 06 April 2021 17:46
by jake
waaren wrote: Tuesday 06 April 2021 17:35 ...
According to the time stamp, the script is triggered every second and that is most likely the result of the setting for the P1 hardware update frequency.

With regards to the log; the above loglines are not specific for this script but are generic for all dzVents scripts based on the settings.

Did you try to change the event / dzVents log settings via [setup][settings][other] bottom of the page (see below)?
log settings.png
@waaren: question to you: is it possible to avoid the following log line as well?
"Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua"

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

Posted: Tuesday 06 April 2021 18:10
by McMelloW
jake wrote: Tuesday 06 April 2021 17:23 Thanks for your kind words!

Changing to lOG_ERROR should do it. Have you checked your dzVents settings itself? Please make sure that log level there is also just set to 'ERROR'.

0th and 2nd question: the script is triggered on the P1-meter update, but only executed at the specified interval.
Reason for specifying the P1-meter and not the solar inverter (keep in mind, in this script is now introduced a virtual! battery inverter, that simulates charging/depleting the battery from/to 230V), is that in this script we only care about energy leaving the house, not so much about production of the solar system. In the ideal situation all generated energy is consumed at once, but unfortunately most times the production and consumption are at different times (in my case, I use around 30% of the solar energy directly, the rest is fed back to the grid)
Thanks for your reply.
Forgot to check dzVents Setting. I see the triggering is set meterName So far the script works OK.

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

Posted: Tuesday 06 April 2021 19:16
by waaren
jake wrote: Tuesday 06 April 2021 17:46 @waaren: question to you: is it possible to avoid the following log line as well?
"Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua"
Yes.
logging.png
logging.png (24.99 KiB) Viewed 2396 times

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

Posted: Monday 19 April 2021 14:16
by jake
Version 0.2 released with better registration of all elements that impact maximum efficiency of solar battery usage.

File available at GitHub!

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

Posted: Monday 19 April 2021 14:20
by eddieb
Hi Jake,

the code is working fine here, tnx for the great work so far.

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

Posted: Monday 26 April 2021 21:05
by hclardij
I am not an experienced programmer so excuse me if I do not read this correctly.
By the looks you charge the battery with the same amount of returned power. This assumes a charger that can modulate the charge power, correct?
Same the other way around: If you want to deliver power from your battery to your home, ideally you want this so that you do not supply energy to the grid, with a maximum of the inverter capacity.
This means that there must be communication between the powermeter and the charger/inverter. The ones II have seen use a modbus connection for this purpose and these cost serious money.
This idea I had was to build this using Domoticz by having 3 chargers: 250, 500 and 1000 watt. With this I can charge 250, 500, 750, 1000, 1250, 1500 and 1750 watt. Same principle for the discharge. Chargers cost 40 euro each on Ali so with this idea you can build a low cost system.

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

Posted: Tuesday 27 April 2021 22:26
by jake
You correctly described the way the script works.

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

Posted: Friday 17 September 2021 9:07
by mcmikev
Hi ,

I have been using this script for a while and like the concept very much, Is it worth to spend money for a Solarbattery or not.
This script can give a good insight into that.

Now I have an issue I cannot seem to fix myself
Last friday my smart P! meter died and I got a new one, but now my Log is flooding with lines:

Code: Select all

 2021-09-17 09:01:19.209 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73995 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:20.277 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73995 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:21.278 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73995 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:22.285 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73995 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:23.286 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73996 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:24.293 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73996 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:25.309 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73997 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:26.320 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73997 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:27.305 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73997 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:28.305 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73997 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:29.305 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73998 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:30.294 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73998 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:31.265 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73999 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:32.296 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73999 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:33.264 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73999 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:34.265 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73999 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:35.273 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (73999 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:36.263 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (74000 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:37.264 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (74000 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:38.260 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (74000 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:39.261 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (74000 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:40.260 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (74000 Wh < previous value of 16690262 Wh. Script will not continue
2021-09-17 09:01:41.260 Error: dzVents: Error: (3.1.8) Hey solar battery: New value of consumed enery meter (74000 Wh < previous value of 16690262 Wh. Script will not continue 
I checked the variables but it is not visible. What must or can I do to fix this error?

Thanks for the script and help :-)

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

Posted: Friday 17 September 2021 12:25
by jake
I understand where the issue is coming from, it protects the script from incorrect input. In your case the low meter has a logic explanation. I am currently not able to review the code. The variable is stored in a dzvents variable. (Scripts/dzvents/data). Update that file (with sudo nano) with your current meter value. It should start calculating afterwards with the new meter values

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

Posted: Friday 17 September 2021 12:52
by mcmikev
Hi Jake,

yes that did the trick!!

Thank you very much!

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

Posted: Sunday 03 October 2021 20:22
by MartinManders
Hi Jake,

You did an incredible job!
I understand you’re logic, and thanks for the extra logging.

The program works like a charm.
I’ve learned a lot ;)

Thank you!

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

Posted: Thursday 11 November 2021 11:51
by CrosstownTee
Hi Jake,

I can't read values from a P1 port, but I do have several S0 pulse meters providing output about energy use of different appliances (the biggest consumers) and the output of my solar panels.
In the script I can see only one variable for energy consumers; how would you script a new variable summing up the output variables of the energy consumers?

-> One returned energy meter
-> Multiple consumed energy meters

I'm not sure if this is a big task, but I'm very new to Domoticz, and definitely new in scripting...

Thanks in advance for your suggestions!

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

Posted: Thursday 11 November 2021 19:05
by jake

CrosstownTee wrote:Hi Jake,

I can't read values from a P1 port, but I do have several S0 pulse meters providing output about energy use of different appliances (the biggest consumers) and the output of my solar panels.
In the script I can see only one variable for energy consumers; how would you script a new variable summing up the output variables of the energy consumers?

-> One returned energy meter
-> Multiple consumed energy meters

I'm not sure if this is a big task, but I'm very new to Domoticz, and definitely new in scripting...

Thanks in advance for your suggestions!
The idea behind the current script is the net consumption or usage through your p1-meter.

It seems like you will use the script differently. Please explain.

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

Posted: Tuesday 01 November 2022 22:46
by THBR
Hello,

(hopefully this item is still active?)

I recently installed and edited the script as described on Github and the Wiki page. But although the script apparently runs without errors, the created virtual devices are from the start not filled with any data and therefore not updated at all.

What could be wrong?

Status log Domoticz (level = domoticz.LOG_DEBUG):

Code: Select all

"2022-11-01 22:35:59.848 Status: dzVents: Info: Handling events for: "Power", value: "6719258;8511998;981986;2149440;306;0" 
2022-11-01 22:35:59.848 Status: dzVents: Info: Hey solar battery: ------ Start external script: SimSolarBattery.lua: Device: "Power (P1 LAN)", Index: 135 
2022-11-01 22:35:59.852 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery: Custom sensor device adapter 
2022-11-01 22:35:59.854 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Virtual Solar Battery Usage: P1 smart meter energy device adapter 
2022-11-01 22:35:59.856 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Lost Solar Battery Energy: P1 smart meter energy device adapter 
2022-11-01 22:35:59.858 Status: dzVents: Debug: Hey solar battery: Processing device-adapter for Lost Solar Battery Inverter Energy: P1 smart meter energy device adapter 
2022-11-01 22:35:59.859 Status: dzVents: Debug: Hey solar battery: scriptInterval value increased to inf seconds to have a maximum deviation of 10 percent 
2022-11-01 22:35:59.859 Status: dzVents: Debug: Hey solar battery: script trigger interval < than set value for scriptInterval (inf) 
2022-11-01 22:35:59.860 Status: dzVents: Info: Hey solar battery: ------ Finished SimSolarBattery.lua 
"
Regards, Theo (NL).