Some advice on this simple "lived in look" code...

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by mattyb, Dec 5, 2007.

  1. mattyb

    mattyb

    Joined:
    Jul 29, 2005
    Messages:
    78
    Likes Received:
    0
    Location:
    Sydney, Australia
    G'day

    I'm looking for a bit of a sanity check on the code below and hope someone will be kind enough to offer their thoughts.

    This is meant to be a very simple "lived in look" but the client reports that whenever they, or their cleaners, arrive home after being away that "Holiday Scene 1" is always set. Apparently the code that sets the following scenes to turn all the lights OFF never gets called.

    I have tested the code just on PICED with shorter random times and have found that sometimes the code gets to "Holiday Scene 2" and has never got to "Holiday Scene 3".

    Any thoughts on why it's not working properly or ways to improve it would be appreciated.

    Thanks

    Matt

    Code:
    {Initialise Random Times Each Day}
    if (Time = "2:00:00 AM") then
    begin
     RandomTime2 := random("03:00:00");
     RandomTime3 := random("01:05:00");
    end;
    
    
    
    once (time > (sunset)) then
    begin
    if (GetEnableState("HOLIDAY MODE") = ON) then
     begin
       SetScene("Holiday Scene 1");
       {Evening}
       TimerStart(1);
     end;
    end;
    
    once (TimerTime(1) > RandomTime2) then
    begin
      SetScene("Holiday Scene 2");
      {Bedtime}
      TimerStop(1);
      TimerStart(2);
    end;
    
    once (TimerTime(2) > RandomTime3) then
    begin
      SetScene("Holiday Scene 3");
      {Goodnight}
      TimerStop(2);
    end;
    
    
     
    mattyb, Dec 5, 2007
    #1
  2. mattyb

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    275
    Likes Received:
    98
    Location:
    Sydney, NSW, Australia
    I tested it in homegate with shorter times , and it worked.

    Maybe the random time is some times set to 0 so the code doesnt see a (once ) change. Try adding a few minutes to the random time.


    eg
    RandomTime2 := random("03:00:10")+ 120;
     
    lcrowhurst, Dec 5, 2007
    #2
  3. mattyb

    mattyb

    Joined:
    Jul 29, 2005
    Messages:
    78
    Likes Received:
    0
    Location:
    Sydney, Australia
    Thanks Laurence

    While testing out your suggestion I realised another of my modules was using a whole bunch of timers and I had two pieces of code doing things based on the same timer...:eek:

    I had been conscientious when I began coding and done things like
    Code:
    GARAGE_PIR_TIMER=1;
    
    ...
    
    TimerStart(GARAGE_PIR_TIMER);
    
    but then fell into slackness and just threw around things like TimerStart(1)...

    Anyway, another lesson learned...thanks for your help!
     
    mattyb, Dec 5, 2007
    #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.