Page 1 of 1

whats wrong in this script?

Posted: Sunday 14 April 2024 8:21
by edwin1234
im a noob at scripting but this is a atempt
to add my total enphase produced energy with solaredge produced energy
but keep getting errors:
2024-04-14 08:14:00.479 Error: dzVents: Error: (3.1.7) Method updateCustomSensor is not available for device "Opbrengst" (deviceType=General, deviceSubType=kWh).

this was my atempt:

return {
on = { timer = { "every 1 minutes" }}, -- Change to your liking to 1,2,3,4,5,6,10,12,15 or 20

execute = function(dz, item)

local Opbrengst = dz.devices(1813)
local Enphase = dz.devices("Enphase Panelen - total").counterToday
local Solaredge = dz.devices("OpbrengstTotaal").counterToday

Opbrengst.updateCustomSensor(dz.utils.round(Enphase + Solaredge,2)) -- Rounded to two decimals

end
}

"Opbrengst"=dummy device
"Enphase Panelen - Total=enphase total energy device
"OpbrengstTotaal= solaredge total energy device

whats wrong?

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 9:36
by habahabahaba
if it is kWh device you should use updateElectricity(power, energy)

WiKi

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 12:44
by edwin1234
Thanks for your help
But where and how to place that in the script?

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 12:48
by habahabahaba
Opbrengst.updateElectricity(power, energy) instead of Opbrengst.updateCustomSensor(value)

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 13:04
by edwin1234
its still not working now i get this error :
atempt to call a table value

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 13:25
by habahabahaba
You have to realy know the type/subtype of your sensor (setup -> Devices page) to choose the right method of updating.
2024-04-14_14-21-28.png
2024-04-14_14-21-28.png (26.64 KiB) Viewed 1090 times

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 17:09
by edwin1234
Opbrengst device is type is general subtype kwh
The value in the device is correct but it needs to be kw instead of watt

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 17:20
by RonkA
Is this something for you?

Code: Select all

return {
on = { timer = { "every 1 minutes" }}, -- Change to your liking to 1,2,3,4,5,6,10,12,15 or 20

execute = function(dz, item)

	local Opbrengst = dz.devices(1813) -- should be a dummy type: General - kWh
	local Enphase = dz.devices("Enphase Panelen - total").counterToday
	local Solaredge = dz.devices("OpbrengstTotaal").counterToday

	local OpbrengstValue = Enphase + Solaredge
	local OpbrengstValueRound = tonumber(domoticz.utils.round(OpbrengstValue,2)) -- Rounded to two decimals
	
	domoticz.devices(Opbrengst).updateElectricity(OpbrengstValueRound, OpbrengstValue)

end
}
I cannot remember why but in a script of mine this works for me..

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 17:32
by edwin1234
Thanks
I will try it
Is in your device the value in kw?

Your script doesnt work
Gives errors

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 17:55
by RonkA
No its a counter to see how much power my Quooker uses in Kw, so i divide the calculated value by 1000 to get the correct value for 'energy'
Hmm.. maybe you have to divide OpbrengstValue by 1.000.000 to get the correct 'kWh' to display..
But you will soon enough if the values are correct on your setup.

-EDIT-
my bad; The device shows watts and kWh; the energy part is in watt (like habahabahaba states)

Code: Select all

	local OpbrengstValue = Enphase + Solaredge / 1000

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 18:31
by edwin1234
Ok thanks
How do you divide the value of “Opbrengst” by 1000 in the script?

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 18:50
by habahabahaba
edwin1234 wrote: Sunday 14 April 2024 17:09 Opbrengst device is type is general subtype kwh
The value in the device is correct but it needs to be kw instead of watt
this type of device shows only in Watts

Re: whats wrong in this script?

Posted: Sunday 14 April 2024 22:55
by edwin1234
Thanks for your help

I did *1000 so now i have 19.500,00watt
In stead of 19,5 watt good enough for me.

Re: whats wrong in this script?

Posted: Monday 15 April 2024 0:01
by RonkA
set domoticz.utils.round(OpbrengstValue,2) to domoticz.utils.round(OpbrengstValue,0) to loose those extra zero's after comma

Re: whats wrong in this script?

Posted: Monday 15 April 2024 5:45
by edwin1234
Thanks for the reply
Good suggestion i change that.