Help with some Logic?

Discussion in 'General Discussion' started by Ingo, Jan 13, 2007.

  1. Ingo

    Ingo

    Joined:
    Dec 2, 2006
    Messages:
    290
    Likes Received:
    1
    Location:
    South Africa
    Hi,
    I am trying to get my head around a solution but I can't seem to get it right.
    I am trying to do the following:

    When the Kitchen light on and if no movement detected for 15 minutes then dim the light to 50% of what the original value was. If no further movement is detected for another 15 minutes then switch the light off. IF however movement is detected in the dimmed state then restore the level to the original level and start the process from the beginning.

    I know I can keep it simple by just switching the light off after 30 minutes but I want to do something different.

    Does anyone have any ideas?

    Ingo
     
    Ingo, Jan 13, 2007
    #1
  2. Ingo

    PSC

    Joined:
    Aug 3, 2004
    Messages:
    626
    Likes Received:
    0
    Location:
    Brisbane, Australia
    Hi Ingo,

    The solution is quite simple :)

    The Group Address (GA) for the Kitchen lights = Kitchen Lights.

    The GA for the movement sensor = Kitchen Sensor.

    Set the Kitchen Sensor (PIR) to pulse ON for 2 sec when movement is detected.

    Set the Kitchen Sensor (PIR) to "Enable" when the "Kitchen Lights" are ON.

    Using a PAC or a Colour C-Touch create a timer (see Homegate / Schedule Plus programming manual) for the kitchen sensor.

    You code will read something like this -

    If “Kitchen Light” is on, then start “Kitchen Timer”.

    If “Kitchen Lights” is on, and “Kitchen Sensor” is on, then re-start “Kitchen Timer”.

    If “Kitchen timer” = 15min, then set “Kitchen Lights” to 50%.

    If “Kitchen timer” = 30min, then set “Kitchen Lights” to 0%.

    If “Kitchen Timer” = 30min, then stop “Kitchen Timer”.

    You may want to override the sensor controlling the Kitchen Lights i.e. turning them off from a switch or disabling the PIR. These options are also available to you, however I would suggest getting the above functionality working correctly first and then expanding onto the more complex programming options.

    Obviously you will have to write it in the correct format, but this should give you something to start with :)

    *** read the programmers guide C:\CLIPSAL\PICED(HOMEGATE OR SCHEDULEPLUS)\MANUALS\PROGRAMMERS GUIDE.PDF & LOGIC.PDF, this will give you all the information you need ***
     
    Last edited by a moderator: Jan 13, 2007
    PSC, Jan 13, 2007
    #2
  3. Ingo

    ukdavros

    Joined:
    Aug 22, 2005
    Messages:
    40
    Likes Received:
    0
    Location:
    Co Meath Ireland
    something like this

    once (GetLightingState("KITCHEN") = ON) and

    (GetLightingState("DETECT") = OFF) then

    begin
    TimerStart(2);
    end;

    if TimerTime(2) = 900 then
    begin
    SetLightingLevel("KITCHEN", 50%, "0s");


    end;

    if TimerTime(2) = 1800 then
    begin
    SetLightingState("KITCHEN", OFF);
    TimerStop(2);

    end;
     
    Last edited by a moderator: Jan 13, 2007
    ukdavros, Jan 13, 2007
    #3
  4. Ingo

    Ingo

    Joined:
    Dec 2, 2006
    Messages:
    290
    Likes Received:
    1
    Location:
    South Africa
    Thanks guys, I'll give it a try and let you know what happens. I did go through the Logic manual but there are so many options of doing things that I just needed a nudge in the right direction.
     
    Ingo, Jan 14, 2007
    #4
  5. Ingo

    ukdavros

    Joined:
    Aug 22, 2005
    Messages:
    40
    Likes Received:
    0
    Location:
    Co Meath Ireland
    This is probably closer to what you want.

    you will need to declare your variables L1 And L2 Integers



    once (GetLightingState("KITCHEN") = ON) and

    (GetLightingState("DETECT") = OFF) then

    begin
    L1 := (GetLightingLevel("KITCHEN"));
    l2 := l1 DIV 2 ;
    TimerStart(2);
    end;

    if TimerTime(2) = 900 then
    begin
    SetLightingLevel("KITCHEN", L2, "0s");
    end;

    ONCE (GetLightingState("DETECT") = ON) then
    BEGIN
    SetLightingLevel("KITCHEN", L1, "0s");
    TimerSTOP(2);
    END;

    if TimerTime(2) = 1800 then
    begin
    SetLightingState("KITCHEN", OFF);
    TimerSTOP(2);
    end;
     
    ukdavros, Jan 14, 2007
    #5
  6. Ingo

    Ingo

    Joined:
    Dec 2, 2006
    Messages:
    290
    Likes Received:
    1
    Location:
    South Africa
    I think I got it. Below is my actual code with smaller time frames to test with. I think I am looking out for all eventualities like lights changing levels and going off in the middle of a calculation. Thanks for pointing me in the right direction.

    Init:
    SavedStatus := False;

    Module:
    { This module saves the current Kitchen light level, if the motion detector
    doesn't detect motion for 10 seconds it will dim the lights to 50% of the original level
    If movement is detected in the next 10 second time period, the original level is restored.
    If there is no movement in this period the light is switched off.
    If the level changes in the first 1-9 seconds then the level is saved just before it is dimmed.
    If the light goes off at any time the module stops. }

    once GetLightingState("Group 117 - Kitchen Downlighters") and (GetLightingState("Group 219 - Kitchen PIR") = OFF) then
    begin
    TimerStart(2);
    end;

    if (TimerTime(2) = 10) and GetLightingState("Group 117 - Kitchen Downlighters") then
    begin
    if not SavedStatus then
    begin
    SavedLevel := GetLightingLevel("Group 117 - Kitchen Downlighters"); { Only save when lights need to dim }
    SavedStatus := True; { Set variable to TRUE to indicate value already saved }
    end;
    SetLightingLevel("Group 117 - Kitchen Downlighters", (SavedLevel div 2), "0s"); { Dim light here }
    end;

    once (TimerTime(2) > 10) and (TimerTime(2) < 20) and GetLightingState("Group 219 - Kitchen PIR")
    and GetLightingState("Group 117 - Kitchen Downlighters") then { If movement is detected, restore light level }
    begin
    SetLightingLevel("Group 117 - Kitchen Downlighters", SavedLevel, "0s");
    SavedStatus := False; { Clear Status so that level can change and be saved again }
    end;

    if TimerTime(2) = 20 then { If no movement is detected for 20s then it's time to switch the lights off }
    begin
    SetLightingState("Group 117 - Kitchen Downlighters", OFF);
    TimerStop(2);
    SavedStatus := False;
    end;
     
    Ingo, Jan 15, 2007
    #6
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.