Logic Machine Forum
Minimum power consumption - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Minimum power consumption (/showthread.php?tid=4252)



Minimum power consumption - gilles38 - 20.09.2022

Hi all,
Since years I'm calculating the "always on" power value by taking the minimum value in the data base everyday.
the power value is coming from the main power meter of my installation, and is placed in a trend.

I just have installed some PV... so I need to modify my calculation ... and need now to do the calculation when the PV is not producing ... 
between 0:00AM and 6AM and from 9PM to 11h59PM

 
Code:
require('trends')

function get_days_in_month(month, year)
  local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }   
  local d = days_in_month[month]
   
  -- check for leap year
  if (month == 2) then
    if (math.mod(year,4) == 0) then
     if (math.mod(year,100) == 0)then               
      if (math.mod(year,400) == 0) then                   
          d = 29
      end
     else               
      d = 29
     end
    end
  end
  return d 
end

dates = {}
dates['start'] = os.date('*t')
dates['end'] = os.date('*t')


if(dates['start'].day==1)then
  if(dates['start'].month==1) then
    month=12
    year=dates['start'].year-1
  else
    month=dates['start'].month
    year=dates['start'].year
  end
  day=get_days_in_month(month,year)
  month=dates['start'].month
  year=dates['start'].year
else
  day=dates['start'].day-1
  month=dates['start'].month
  year=dates['start'].year
end

    dates['start'].day=day
  dates['start'].month=month
  dates['start'].year=year
 

-- fetch value
resolution = 86400/4
Values = trends.fetch('Total Power', dates, resolution)
min = math.min(unpack(Values))*1000

grp.write('15/1/61', min)

as in documentation I have seen that for dates [start] and [ends] the time is not taken in consideration ....how can I do ?

thanks all for support 
Gilles