Page 1 of 1

WhToday error

Posted: Saturday 17 July 2021 14:00
by hclardij
Hi all,
I am new to programming and started with a little script to add the power generation of my 2 SMA inverters. Somehow I see something weird that I cannot explan. Please help.
First I created a 'dummy', sensor type 'electric (instant + counter)'
Then created this script:

return {

on = {
timer = { 'every 1 minutes' }
},

execute = function(domoticz, item)

local SolarPowerE = domoticz.devices(1) -- Power Erker
local SolarPowerG = domoticz.devices(3) -- Power Garage
local SolarPowerT = domoticz.devices(5) -- Total Solar Power

SolarPowerT.updateElectricity(
SolarPowerE.WhActual + SolarPowerG.WhActual,
SolarPowerE.WhToday + SolarPowerG.WhToday
)

end

}

Where SolarPowerT is the sum of my 2 generated powers of the inverters.
What I see is the following: SolarPowerT. WhActual is displaying the right value; SolarPowerT.WhToday starts with the negative value of what has been produced the day before. So if I have generated 35kWh on monday, it starts at tuesday 0.00 hours with -35kWh and then slowly ramps up.
Both the Inverters start the day with 0 so the total should be 0 too.

What am I overlooking here?

Thanks in advance !

Re: WhToday error

Posted: Saturday 17 July 2021 23:47
by waltervl
The counter value should be the total counter until now, like what you read on the display of your electricity meter.

So today 35
Tomorrow 35+30.
Etc

So you should combine the .WhTotal values instead of WhToday and put that in your combined dummy device.

Domoticz will do the today calculation for you.

Re: WhToday error

Posted: Monday 19 July 2021 8:51
by Derik
Like to have this script also..
I do also have multiple inverters..

Re: WhToday error

Posted: Monday 19 July 2021 10:30
by hclardij
Hi,
That could be an explanation although that would be agains what I read in the manual and that is 100% not what I see;
Every night the counter starts at a negative number This morning the value started at -37.4 kWh or so... During the day the numbers add up nicely,...but it always starts with the wrong number at midnight.
domoticz.jpg
domoticz.jpg (20.37 KiB) Viewed 741 times

Re: WhToday error

Posted: Monday 19 July 2021 13:01
by hclardij
I see what you mean with the counter; I don't see why I start with the negative still. I tried with the WhToday but that is for the moment displaying the wrong value; I need to check what happens after midnight

Re: WhToday error

Posted: Monday 19 July 2021 15:04
by waltervl
This script should work

Code: Select all

return {

	on = {
		timer = { 'every 1 minutes' }
},

	execute = function(domoticz, item)

	local SolarPowerE = domoticz.devices(1) -- Power Erker
	local SolarPowerG = domoticz.devices(3) -- Power Garage
	local SolarPowerT = domoticz.devices(5) -- Total Solar Power
	
	SolarPowerT.updateElectricity(SolarPowerE.WhActual + SolarPowerG.WhActual, SolarPowerE.WhTotal + SolarPowerG.WhTotal)

	end

}

Re: WhToday error

Posted: Monday 19 July 2021 15:49
by hclardij
Hi,
I have tried that; I see a value but not the value that I want to see. This is displaying the total kWh that has been generated in its lifetime for both inverters.

Lets take 1 stap back to explain what I want to have displayed: I want the actual generated power and the total generated power for that day.
The value should be set to 0 at the beginning of the day.
Each inverter is giving those values individually, but I want to have the sum of both inverters.

I did a little test and created a second dummy sensor SolarPowerTT; Furthermore I set the value for the 2nd variable in the function to 0 instead of the sum of 2 other values.

return {

on = {
timer = { 'every 1 minutes' }
},

execute = function(domoticz, item)

local SolarPowerE = domoticz.devices(1) -- Power Erker
local SolarPowerG = domoticz.devices(3) -- Power Garage
local SolarPowerT = domoticz.devices(5) -- Total Solar Power Actual
local SolarPowerTT = domoticz.devices(6) -- Total Solar Power Today

SolarPowerT.updateElectricity(SolarPowerE.actualWatt + SolarPowerG.actualWatt, 0)
SolarPowerTT.updateElectricity(SolarPowerE.WhToday + SolarPowerG.WhToday, 0)

end

}

This is the output:
domo.jpg
domo.jpg (35.52 KiB) Viewed 725 times


So the SolarTotalToday sensor is working as it is displaying the right value.
The 'Today' value in the SolarTotal sensor is constant at minus 37.441 kWh . So by the looks it starts at -37k and then adds 0 everytime the script runs. Hence the steady -37441.

I think the electricity function in not appropriate for what I am looking for; I just need 2 values and no counter.

NB: This is a test setup with nothing else attached to it.

Thanks for your help!

Re: WhToday error

Posted: Monday 19 July 2021 15:54
by waltervl
hclardij wrote: Monday 19 July 2021 15:49 Hi,
I have tried that; I see a value but not the value that I want to see. This is displaying the total kWh that has been generated in its lifetime for both inverters.
This is because it is the first time you did the calculation. If you keep on sending the data it will behave exactly the same as your normal 2 single solar panel counters. So you have to be patient...... keep it running for a couple of days.

Re: WhToday error

Posted: Monday 19 July 2021 16:09
by hclardij
Ok, I'll do that ! Thanks !

Re: WhToday error

Posted: Tuesday 20 July 2021 10:10
by hclardij
You are right,..it works now.!!
Thanks a lot!
domo.jpg
domo.jpg (36.36 KiB) Viewed 702 times