Power Measurement Logic - Wiser & Touch Screens

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by bmerrick, May 16, 2013.

  1. bmerrick

    bmerrick

    Joined:
    Jun 13, 2007
    Messages:
    437
    Likes Received:
    35
    Location:
    Sydney
    Hi All,

    I wrote some logic to give to a client and thought you might find it useful for your own use.

    It pulls the last 12 months of Current Measurement Data and the last month and gives a useful output to assess your power use for the period.


    Output is as follows:

    Code:
    C-Bus Network Power Measurement
         
    Total Energy (in kWh) Use Measured as at 17/05/2013
    This Months Power Use To Date  = 665 kWh
    This Months Expected Power Use = 1241 kWh
        
    Previous 12 Months
        April 2013 Power Use = 1238 KWh
        March 2013 Power Use = 2166 KWh
      Febuary 2013 Power Use = 2324 KWh
      January 2013 Power Use = 1527 KWh
     December 2012 Power Use = 1514 KWh
     November 2012 Power Use = 1826 KWh
      October 2012 Power Use = 1607 KWh
    September 2012 Power Use = 1353 KWh
       August 2012 Power Use = 1708 KWh
         July 2012 Power Use = 1850 KWh
         June 2012 Power Use = 1784 KWh
          May 2012 Power Use = 1632 KWh
         
    Average Monthly Energy Use          =  1711 kWh
    This Month's Expected Power Use     =  1241 kWh
    This Month's Energy Use vs Average  =     -27.5 %
    

    Code:
    in logic module [Power Monitor] 
    WriteLn('C-Bus Network Power Measurement');
    WriteLn('     ');
    DateToString(Date, Today);
    DataString := Today;
    WriteLn('Total Energy (in kWh) Use Measured as at ',DataString);
    MonthPower := GetRealIBSystemIO("Power Meter Total Energy",3, 1, 0, 0, 0, -1);
    Format(DataString, 'This Months Power Use To Date  = ', (MonthPower/1000):0:0,' kWh');
    WriteLn(DataString);
    CMonthPower := GetRealIBSystemIO("Power Meter Total Energy",3, 1, 0, 0, 1, -1);
    Format(DataString, 'This Months Expected Power Use = ', (CMonthPower/1000):0:0,' kWh');
    WriteLn(DataString);
    WriteLn('    ');
    WriteLn('Previous 12 Months');
    countup := 1;
    while countup <= 12 do
      begin
      MonthPower := GetRealIBSystemIO("Power Meter Total Energy", 3, 1, countup, 0, 0, -1);
      Format(DataString, ' Power Use = ', (MonthPower/1000):0:0);
      MonthValue:=Date-(31*countup);
      DecodeDate(MonthValue, CYear, CMonth, CDay);
        case CMonth of //Select Month
        1 : DMonth:='January';
        2 : DMonth:='Febuary';
        3 : DMonth:='March';
        4 : DMonth:='April';
        5 : DMonth:='May';
        6 : DMonth:='June';
        7 : DMonth:='July';
        8 : DMonth:='August';
        9 : DMonth:='September';
        10 : DMonth:='October';
        11 : DMonth:='November';
        12 : DMonth:='December';
        end; 
    WriteLn(DMonth:9,CYear:5,DataString,' KWh');
      countup := Succ(countup);
      MonthAv:=MonthAv + MonthPower; 
      end;
    WriteLn('     ');
    WriteLn('Average Monthly Energy Use          = ',(MonthAv/12)/1000:5:0,' kWh');
    Format(DataString, 'This Month''s Expected Power Use     = ', (CMonthPower/1000):5:0,' kWh');
    WriteLn(DataString);
    WriteLn('This Month''s Energy Use vs Average  = ',(-((MonthAv/12)-CMonthPower)/(MonthAv/12)*100):9:1,' %');  
    DisableModule("Power Monitor");
    
    It is designed to just run once and you can use it from PICED or your touch screen using a button etc.


    It requires

    Code:
    Global Variables
    countup : integer;
    DataString : string;
    Today :string;
    s :string;
    MonthPower : real;
    CMonthPower : real;
    CYear:integer;
    CMonth:integer;
    MonthAv : real;
    DMonth:string;
    CDay:integer;
    MonthValue:integer;
    
    I spent a while playing around with an array for the month name but as it was getting on toward 2AM, I just settled for a 'Case' instead. I will post the array version after I tidy it up.

    Well that's it......I'm off to bed!!!


    Enjoy,

    Brad
     
    Last edited by a moderator: May 16, 2013
    bmerrick, May 16, 2013
    #1
  2. bmerrick

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    Your creativity continues to impress me!! :-D

    Cheers..
     
    Roosta, May 17, 2013
    #2
  3. bmerrick

    bmerrick

    Joined:
    Jun 13, 2007
    Messages:
    437
    Likes Received:
    35
    Location:
    Sydney
    Thanks Roosta,

    glad you like it.

    To save you modifying it yourself:

    In the case you wanted to write the output to a text file to keep as a power history, either on a CTC or from PICED after downloading the power data from the touch screen, use the following:

    Code:
    AssignFile(file2, '12Month_Power_Data.txt');
    ReWrite(file2);
    WriteLn(file2,'C-Bus Network Power Measurement');
    WriteLn(file2,'     ');
    DateToString(Date, Today);
    DataString := Today;
    WriteLn(file2,'Total Energy (in kWh) Use Measured as at ',DataString);
    MonthPower := GetRealIBSystemIO("Power Meter Total Energy",3, 1, 0, 0, 0, -1);
    Format(DataString, 'This Months Power Use To Date  = ', (MonthPower/1000):0:0,' kWh');
    WriteLn(file2,DataString);
    CMonthPower := GetRealIBSystemIO("Power Meter Total Energy",3, 1, 0, 0, 1, -1);
    Format(DataString, 'This Months Expected Power Use = ', (CMonthPower/1000):0:0,' kWh');
    WriteLn(file2,DataString);
    WriteLn(file2,'    ');
    WriteLn(file2,'Previous 12 Months');
    countup := 1;
    while countup <= 12 do
      begin
      MonthPower := GetRealIBSystemIO("Power Meter Total Energy", 3, 1, countup, 0, 0, -1);
      Format(DataString, ' Power Use = ', (MonthPower/1000):0:0);
      MonthValue:=Date-(31*countup);
      DecodeDate(MonthValue, CYear, CMonth, CDay);
        case CMonth of //Select Month
        1 : DMonth:='January';
        2 : DMonth:='Febuary';
        3 : DMonth:='March';
        4 : DMonth:='April';
        5 : DMonth:='May';
        6 : DMonth:='June';
        7 : DMonth:='July';
        8 : DMonth:='August';
        9 : DMonth:='September';
        10 : DMonth:='October';
        11 : DMonth:='November';
        12 : DMonth:='December';
        end; 
    WriteLn(file2,DMonth:9,CYear:5,DataString,' KWh');
      countup := Succ(countup);
      MonthAv:=MonthAv + MonthPower; 
      end;
    WriteLn(file2,'     ');
    WriteLn(file2,'Average Monthly Energy Use          = ',(MonthAv/12)/1000:5:0,' kWh');
    Format(DataString, 'This Month''s Expected Power Use     = ', (CMonthPower/1000):5:0,' kWh');
    WriteLn(file2,DataString);
    WriteLn(file2,'This Month''s Energy Use vs Average  = ',(-((MonthAv/12)-CMonthPower)/(MonthAv/12)*100):9:1,' %');  
    CloseFile(file2);
    DisableModule("Power Monitor");
    
    Have a good one,

    Brad
     
    bmerrick, May 17, 2013
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.