Logic Help

Discussion in 'Pascal Logic Code Examples' started by TomDowden, Nov 15, 2021.

  1. TomDowden

    TomDowden

    Joined:
    Nov 15, 2021
    Messages:
    3
    Likes Received:
    0
    Hi All,

    Am looking for a bit of guidance with some logic. I have bathroom lights that are triggered with a PIR but would like the on times to be different depending on the time.

    For example between 7am - 11pm want the lights to be on for 2 minutes, then between 11pm - 7am want the lights to be on for 30 seconds.

    I have written this in a PAC. Would this work fine? or is there any other or more efficient ways of doing so.

    Code:
    once (GetCBusState("Manor Farm House", "PICED Triggers", "TRIGGER - MSTR BATHROOM - NICHE") = ON)
          then
    begin
      SetLightingLevel("MASTER BED - LED STRIP / GLO19", 100%, "0s");
    end;
    
    once (GetCBusState("Manor Farm House", "PICED Triggers", "TRIGGER - MSTR BATHROOM - NICHE") = OFF)
          then
    begin
    if (Time >= "07:00:00") and
       (Time <= "22:59:59") then
    begin
      Delay("0:02:00");  { CHANGE TIME HERE }
      SetLightingLevel("MASTER BED - LED STRIP / GLO19", 0%, "0s");
    end;
    
    if (Time >= "23:00:00") and
       (Time <= "06:59:59") then
    begin
      Delay("0:00:30"); { CHANGE TIME HERE }
      SetLightingLevel("MASTER BED - LED STRIP / GLO19", 0%, "0s");
    end;
     
    end;
    Thanks for you help
     
    TomDowden, Nov 15, 2021
    #1
  2. TomDowden

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    There are a couple of issues here when you turn the light off.
    Using a delay stops the module running for that length of time. This means any sensor triggers during that time will be missed, so it won't retrigger if you have continuous movement. At the end of the delay, the lights will turn off, then if there is movement, turn on again immediately. This results in the lights flashing off then on again which is not ideal.
    Also, the line (Time >= "23:00:00") and (Time <= "06:59:59") can never be true since it can't be after 11pm and before 7am on the same day.

    A better way to do this is using the Cbus pulse command which does all the work for you:

    Code:
    once (GetCBusState("Manor Farm House", "PICED Triggers", "TRIGGER - MSTR BATHROOM - NICHE") = ON) then
        SetLightingLevel("MASTER BED - LED STRIP / GLO19", 100%, "0s");
    
    once (GetCBusState("Manor Farm House", "PICED Triggers", "TRIGGER - MSTR BATHROOM - NICHE") = OFF) then
       if (Time >= "07:00:00") and (Time <= "22:59:59") then
          PulseCBusLevel("Local", "Lighting", "MASTER BED - LED STRIP / GLO19", 100%, "0s", "0:02:00", 0%)
       else
          PulseCBusLevel("Local", "Lighting", "MASTER BED - LED STRIP / GLO19", 100%, "0s", "0:0:30", 0%);
    You don't need begin/end around single statements, but it doesn't matter if you put them there.
    The ELSE statement is executed if the IF statement isn't so you only need a single test.
    I'm assuming the lights are on the local/lighting application. Change it as required.
     
    Ashley, Nov 15, 2021
    #2
    TomDowden likes this.
  3. TomDowden

    TomDowden

    Joined:
    Nov 15, 2021
    Messages:
    3
    Likes Received:
    0

    Thanks soo much, had been a while since writing some logic. Was going around in circles.

    Thanks for your help again :)
     
    TomDowden, Nov 16, 2021
    #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.