This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

best way to store period power usage
#3
(28.02.2022, 08:43)Daniel Wrote: You could make 3 virtual objects and use trends on all 3. Use a fetch function to collect last hour consumption and based on the period add this value to virtula or not. You will be able to compare daily values later only take in to account an hour value shift.

I'm not sure how to collect last hour from trends etc i had a look at trends, fetchone but doc says hour and minute info are ignored, this is what i have so far, anyways to optimize it?, its scheduled script to run every hour 

Code:
-- Peak 7am-9am | off peak shoulder 9am-5pm | peak 5pm-9pm | off peak shoulder 9pm-11pm | Off-peak night 11pm-7am
now =  os.date('*t')
local KWH_now = grp.getvalue('1/6/0')

function conplete_day_vals() --  get all storage and update obj
  peak = storage.get('Peak_val')
  shoulder = storage.get('off_peak_shoulder_val')
  night = storage.get('off_peak_night_val')
 
  grp.write('32/1/1', peak )
  grp.write('32/1/2', shoulder )
  grp.write('32/1/3', night)
end

--************** start ************
if now.hour == 7 then
 
  --off peaknight stop --  and prev day finish
  local last = storage.get('off_peak_night')
  storage.set('off_peak_night_val',last - KWH_now)
   conplete_day_vals()
 
  --peak start
  storage.set('Peak_start', KWH_now)
end

--************** peak stop, off peak, shoulder start ************
if now.hour == 9 then -- peak end
  --peak stop
  local last = storage.get('Peak_start')
  storage.set('Peak_val', KWH_now - last)
 
  --off peak shoulder start
  storage.set('off_peak_shoulder_start', KWH_now)
end

--************** off peak shoulder stop, peak start************
if now.hour == 17 then
  --off peak shoulder stop
  local last = storage.get('off_peak_shoulder_start')
  storage.set('off_peak_shoulder_val', KWH_now - last)
   
  --peak start
  storage.set('Peak_start', KWH_now)
end

--************** peak stop, off peak shoulder start ************
if now.hour == 21 then
 
  --peak stop
  local last = storage.get('Peak_val')
  storage.set('peak_val', last + storage.get('Peak_start') - KWH_now)
 
  --off peak shoulder start
   storage.set('off_peak_shoulder_start', KWH_now)
end

--************** off peak shoulder stop, off peak night start ************
if now.hour == 23 then
 
  --off peak shoulder stop
  local last = storage.get('off_peak_shoulder_val')
  storage.set('off_peak_shoulder_val', last + storage.get('off_peak_shoulder_start') - KWH_now)
 
  --off peaknight start
  storage.set('off_peak_night', KWH_now)
end
Reply


Messages In This Thread
RE: best way to store period power usage - by benanderson_475 - 08.01.2023, 20:08

Forum Jump: