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
}
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
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
What am I doing wrong with this last script?