Logic Machine Forum
best way to store period power usage - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: General (https://forum.logicmachine.net/forumdisplay.php?fid=2)
+--- Thread: best way to store period power usage (/showthread.php?tid=3906)



best way to store period power usage - benanderson_475 - 27.02.2022

Hi, 

i am looking to shift power plans but want to log for a few weeks the times i use power as they have different rates for each periods for the proposed new plan, so i want to check if it is worth while, i have LM5 connected to modbus IEM power meter to read total consumption KWH.

time periods are 
7am-9am to 5pm-9pm (period 1)
9am-5pm to 9pm-11pm (period 2)
11pm to 7am (period 3) 

best case would be daily data for each period and store it in a virtual object with its date?

Any ideas?


RE: best way to store period power usage - Daniel - 28.02.2022

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.


RE: best way to store period power usage - benanderson_475 - 08.01.2023

(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