Find out Max value from different variables
Posted: Monday 14 November 2022 15:15
Hi,
I have 13 solarpanels where every panel reports to Domoticz every Minute with how many Watts they are producing at that moment. What I would like to find out what for these 13 solarpanels the max Watt is for that moment and to display this value in Domoticz. And on the next minute i want to recheck this if this is greater and then reset this on a daily basis.
I know in basic how I should write these lines of code, so I think I can manage that, but what I do not know is how to calculate a max value when comparing those different value's
Ofcourse I could do it with the > to find out which of the two value's are greater, but then I would need allot of these entries in the script, I was hoping that It can be done easier with a few lines of code where I can say that this is the max value by comparing the variables. But unfortunately I do not know how to do that..
As a start I have this, this is not a working script yet.. still a rough setup to start with:
Any idea?
Best Regards
I have 13 solarpanels where every panel reports to Domoticz every Minute with how many Watts they are producing at that moment. What I would like to find out what for these 13 solarpanels the max Watt is for that moment and to display this value in Domoticz. And on the next minute i want to recheck this if this is greater and then reset this on a daily basis.
I know in basic how I should write these lines of code, so I think I can manage that, but what I do not know is how to calculate a max value when comparing those different value's
Ofcourse I could do it with the > to find out which of the two value's are greater, but then I would need allot of these entries in the script, I was hoping that It can be done easier with a few lines of code where I can say that this is the max value by comparing the variables. But unfortunately I do not know how to do that..
As a start I have this, this is not a working script yet.. still a rough setup to start with:
Code: Select all
local ScriptVersion = '0.1.9'
local fetchIntervalMins = 1
return
{
on =
{
timer = { 'every minute between 15 minutes after sunset and 15 minutes before sunrise' }
},
logging =
{
level = domoticz.LOG_INFO, -- Uncomment this line to override the dzVents global logging setting LOG_DEBUG for debug loggin
marker = 'SME '.. ScriptVersion,
},
execute = function(dz, item)
-- Read the IDX
local Panel1 = 3330 -- Panel 1
local Panel2 = 3331 -- Panel 2
local Panel3 = 3332 -- Panel 3
local Panel4 = 3333 -- Panel 4
local Panel5 = 3334 -- Panel 5
local Panel6 = 3335 -- Panel 6
local Panel7 = 3336 -- Panel 7
local Panel8 = 3337 -- Panel 8
local Panel9 = 3338 -- Panel 9
local Panel10 = 3339 -- Panel 10
local Panel11 = 3340 -- Panel 11
local Panel12 = 3341 -- Panel 12
local Panel13 = 3342 -- Panel 13
Local MaxWatt = 3343 --MaxValue
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_DEBUG)
end
-- Read Totals Watt
local Panel1Watt = Panel1.sensorValue -- (only three to start with)
local Panel2Watt = Panel2.sensorValue
local Panel3Watt = Panel3.sensorValue
.... -- (Now I want to compare those three to find out which one has the max value)
Best Regards