Page 1 of 1

dzVents calculations energy solar panels

Posted: Thursday 01 June 2023 18:41
by mvveelen
Hi,

I have 2 solar systems (SunnyBoy) and have them added to Domoticz. To see what the totals of both systems are, I have a dummy called "Zonnepanelen". With below script I calculate the current and the total of today until 'now':

Code: Select all

return
{
    on =
    {
        timer = { 'every minute' }
},
	
	execute = function(domoticz, item)
	    
	    local garagePower = domoticz.devices(2013)     -- garage
	    local woningPower = domoticz.devices(2039)     -- woning
	    local totalPower = domoticz.devices(2037)  -- totaal (garage + woning)
	    
	    totalPower.updateElectricity(
            	garagePower.WhActual + woningPower.WhActual,
            	garagePower.WhTotal + woningPower.WhTotal
            )
--domoticz.variables('HighestZonnepanelenDaily').set(garagePower.WhActual + woningPower.WhActual)
	end
	
}
To register the highest power, I use

Code: Select all

commandArray = {}

solar = otherdevices_svalues['Zonnepanelen']
now, total = solar:match("([^;]+);([^;]+)")
      
-- Retrieve the current value of the "Zonnepanelen" sensor
local current_value = tonumber(now)   

-- Retrieve the highest value stored in the user variable "Zonnepanelen"
local highest_value = tonumber(uservariables['HighestZonnepanelen'])

-- Check if the current value is higher than the stored highest value
if current_value > highest_value then
-- Update the user variable with the new highest value
commandArray['Variable:HighestZonnepanelen'] = tostring(current_value)
end

return commandArray
to update the uservariable 'HighestZonnepanelen' as soon as the current registered value is lower than the value that is registered by the solar panels. And that value is shown on my dashboard with another script. So far, so good and it's fun to see what the highest power, voltage or whatever has been so far.

Now, I would like to write the highest total power that day. That script should be triggered once a day of course, but whatever I do.....I get very strange values and I don't know what I'm doing wrong.

I use this script:

Code: Select all

commandArray = {}

solar = otherdevices_svalues['Zonnepanelen']
now, total = solar:match("([^;]+);([^;]+)")
      
-- Retrieve the current value of the "Zonnepanelen" sensor
local current_value = tonumber(total)   

-- Retrieve the highest value stored in the user variable "Zonnepanelen"
local highest_value = tonumber(uservariables['HighestZonnepanelenDaily'])

-- Check if the current value is higher than the stored highest value
if current_value > highest_value then
-- Update the user variable with the new highest value
commandArray['Variable:HighestZonnepanelenDaily'] = tostring(current_value)
end

return commandArray
But the total (day)value at that moment was 30.227kWh and the uservariable is updated with something like 1729803.0 and it doesn't even look like the value I expect. Mind you, this was during the day and it would be better if I got the values when the systems have shut down during the evening.

What am I doing wrong with this last script?

Re: dzVents calculations energy solar panels

Posted: Thursday 01 June 2023 20:18
by roblom
The first script is DzEvents, the other ones are lua I think, is that correct?

Re: dzVents calculations energy solar panels

Posted: Thursday 01 June 2023 20:52
by mvveelen
Yes, I use them both. If/when it works, it works :-)

Re: dzVents calculations energy solar panels

Posted: Thursday 01 June 2023 22:13
by roblom
Is it possible that the "total" is the overall generated power in watts since the inverter started generating?

Re: dzVents calculations energy solar panels

Posted: Thursday 01 June 2023 22:21
by mvveelen
Let me think about that.

The total of both inverters (Zonnepanelen) is now: 1894293.0 Wh

Total inverter SB3.6 is: 1129,29 kWh
Total inverter SB2.0 is: 765,01 kWh
Total SB3.6 + SB2.0 is: 1894,30 kWh

So the answer is: yes, you are right!

So, the calculation should be changed, but how ?

Re: dzVents calculations energy solar panels

Posted: Friday 02 June 2023 0:26
by roblom
Take today's value and lower it with yesterday's value. Or if I'm right with DzEvents you can use .WhToday to receive it directly.

Re: dzVents calculations energy solar panels

Posted: Friday 02 June 2023 14:25
by mvveelen
I don't know how to rewrite the Lua script to dzVents, I will have a try though, but if someone could help?

Update: I've made several time based Lua scripts to update a user variable early in the morning, one to update a user variable in the evening, one that calculates the difference between the two values and update another user variable AND checks if the value that is already there is lower than the new value. If no, do nothing, if yes, overwrite the current value with the new and higher value.

Kind of messy because this could probably be done in 1 script, but I think it works for now. Let's see in a day or 2 what the values are.