Dark hours only code

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by markdem, Apr 24, 2008.

  1. markdem

    markdem

    Joined:
    Sep 22, 2004
    Messages:
    10
    Likes Received:
    0
    Hi everyone, sorry if this has been asked before, but I searched the forum, and can't find anything.

    I would like to turn on some outdoor lights on with a PIR, but only at night time. i have tried the following code, but it does not work;

    once GetEnableState("Outside Entry PIR") = ON and (Time > SunSet) and (Time < SunRise) then
    begin
    SetLightingState("Outside Entry", ON);
    SetLightingState("Driveway Lights", ON);
    end;

    once GetEnableState("Outside Entry PIR") = Off then
    begin
    SetLightingState("Outside Entry", OFF);
    SetLightingState("Driveway Lights", OFF);
    end;

    I am guessing, from what i have read here, is as the PAC calculates the sunrise and sunset time once per day, the sunrise time is for that days sunrise, not the next. (Hope that make sence:confused: )

    i also know that there is a light setting on the PIR, but it is under a roof line, so it is always dark there, so I can use it.

    Is there any way that I can make the lights only turn on at night?

    Thanks, Mark
     
    markdem, Apr 24, 2008
    #1
  2. markdem

    PSC

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

    You need to create a 'Day / Night' group address in the 'Trigger' application in Toolkit and two action selectors 0 = Day, 1 = Night.

    Then have the following code in the logic engine -

    Once time = sunset, set 'Day / Night' to 'Night'
    Once time = sunrise, set 'Day / Night' to 'Day'

    Then you code would read -

    Once 'Driveway PIR' is on and Day / Night = Night then pulse lights on for 180 seconds.

    As I stated before this is more like Minder coding but it should give you the idea.

    P.S. You should have your PIR pulsing a phantom GA i.e 'Driveway PIR' for 1-2 seconds and let the logic take care of the timing. Also, set the PIR for night and day movement.

    I hope this helps.
     
    PSC, Apr 24, 2008
    #2
  3. markdem

    Lucky555

    Joined:
    Aug 13, 2007
    Messages:
    229
    Likes Received:
    0
    Wow Markdem you have got it really mixed up - bloody mess but hey, 10 out of 10 for having a go.

    PSC your post didn't help much - you old Minder head you. You're starting to show your age on this stuff.

    Markdem - please confirm you have a C-Bus PIR and I will send you back the details and real PICED code - not some basic half arsed semi minder script...

    PS if it is a C-Bus PIR then that will do everything you need in terms of detecting night/day and turning on/off lights with a programable time period. If you want two or more groups turned on/off and want different times etc then we set the PIR to send a "trigger(ing) message and let the PAC act on that. Eg I have a C-Bus PIR that sends a triggering message. early in the evening the lights come on for time period x and later in the evening the lights come on for time period Y (less) this stuff is really easy with a PAC - provided you don't have PSC giving you advice :D

    PSS the help file for logic in PICED is nothing less than excellent and comprehensive - Hello uncle Darren...

    Actually I have an internal PIR in the bedroom hallway - between sunset and 9.30pm the hallway lights come on @ 25%. Between 9.30pm and sunrise (the wee hours of the night - as in get up to do a weeeee) the lights in the halway AND the lights in the toilet come on at 18%. (There is a lot of difference in light levels between 18 and 25% when you have developed good night vision) I didn't mention this example originally for two reasons;
    1 - I didn't want to show off too much - especially in contrast to PSC's lame post...
    2 - I know someone is going to ask me for the code and I will have to dig it out of my home PICED file ;)
     
    Last edited by a moderator: Apr 25, 2008
    Lucky555, Apr 25, 2008
    #3
  4. markdem

    johnl

    Joined:
    Aug 12, 2004
    Messages:
    23
    Likes Received:
    0
    OR you could do this

    just change a bit of your code from
    (Time > SunSet) and (Time < SunRise)

    to
    ((Time > SunSet) or (Time < SunRise))
     
    johnl, Apr 25, 2008
    #4
  5. markdem

    filpee

    Joined:
    May 31, 2006
    Messages:
    204
    Likes Received:
    0
    Location:
    Western Australia
    Here is the code that I use for my hallway. (1 pir + 2 single gang switches)
    Lights only work at 25% between sunset (+ 1 hour) though to sunrise (+ 3 hours). All other times they run at 100%.

    As JohnL mentioned your problem seems to be with the placement of brackets.


    Code:
    {PIR}
    once (GetLightingLevel("Dimmer 1_04 - Passage") > 1) then
    begin
      if (GetLightingLevel("Logic 002 - Passage Switch") < 1) then
      begin
        if ((TIME > SUNSET + "1:00:00") or (TIME < SUNRISE + "3:00:00"))then
        begin
          SetLightingLevel("Dimmer 1_04 - Logic Max", 25%, "0s");
        end
        else
        begin
          SetLightingLevel("Dimmer 1_04 - Logic Max", 100%, "0s");
        end
      end
    end;
    
    
    {KEY Inputs}
    once (GetLightingLevel("Logic 002 - Passage Switch") > 1) then
    begin
      SetLightingLevel("Dimmer 1_04 - Logic Max", 100%, "0s");
    end;
    once (GetLightingLevel("Logic 002 - Passage Switch") < 1) then
    begin
      SetLightingLevel("Dimmer 1_04 - Passage", 0%, "0s");
    end;
    
    if (GetLightingLevel("Logic 002 - Passage Switch") > 1) then
    begin
      TrackGroup("My House", "Lighting", "Logic 002 - Passage Switch", "Dimmer 1_04 - Passage");
    end;
    
    {KEY Input status indication}
    once (GetLightingLevel("Dimmer 1_04 - Passage") > 1) then
    begin
      SetLightingState("Status - Hallway Lighting", ON);
    end;
    once (GetLightingLevel("Dimmer 1_04 - Passage") < 1) then
    begin
      SetLightingState("Status - Hallway Lighting", OFF);
    end;
    
     
    filpee, Apr 25, 2008
    #5
  6. markdem

    PSC

    Joined:
    Aug 3, 2004
    Messages:
    626
    Likes Received:
    0
    Location:
    Brisbane, Australia
    Uh, thanks for all the compliments Lucky!!!

    With friends like you who needs enemies???

    Hey Lucky, does this sound familiar "I used to be an integrator" - was that pre or post electricity? :eek:

    I don't know, you try and help a guy and you get shot down in flames :( :( :(

    I was going to mention logic timers, gee I'm glad I didn't now!

    Lucky, that PIR hallway night light would come in handy, considering that you're at that age now where you have to get up 3-4 time per night to do a weeeee :p
     
    PSC, Apr 25, 2008
    #6
  7. markdem

    Lucky555

    Joined:
    Aug 13, 2007
    Messages:
    229
    Likes Received:
    0
    It is interesting to see how different people address similar situations very differently. I think one of main controlling factors for the comparison below is the fact that you have single gang key inputs, however for anyone planning the comparisons are worth thinking about.

    For bedrooms and the toilet we have a single set of downlights (each room). I install 2 gang key inputs. The first button increments a counter in my PAC (very important - button programmed as on off, when the PAC sees the GA transition to on the first part of the action code turns the triggering GA off giving it a bell press type function - don't program the button as bell press because it is possible to bell press on and off a GA in C-Bus and have the PAC miss it inside a loop - trust me)
    The counter value is then tied to a dim level. Very practical and very simple code. The second button is a standard dimmer for the room GA so you have normal 100% dim plus you turn the group off with this second button. When the GA is turned off the counter in PAC is reset.

    I very very rarely use the dimmer button to turn the lights on now that I have this feature set up.

    If you wanted to be tricky you could start the dim levels differently based on time.

    When I get a moment I will dig some code examples out of my work machine.

    PS - PSC all in good humour ;) If need be next time I run into you I can give you a big hug to prove it :)
     
    Lucky555, Apr 25, 2008
    #7
  8. markdem

    Lucky555

    Joined:
    Aug 13, 2007
    Messages:
    229
    Likes Received:
    0
    Keeping it simple

    The code below is really simple - which is usually the best way to go.
    You need to understand some aspects around the functions. If the lights were already on and the PIR can still send its trigger message the code will run after which the lights will turn off. Remember a pulse is a one shot timer so if another device controlls the same GA which was pulsed then the pulse timer will be cancelled. Hope that makes sense..

    Code:
    {Global Variables Module}
    
    FlagSunset : boolean;       
    
    
    {Module}
    
    once (Time >= sunrise) then
    begin
      FlagSunset := false;
    end;
    
    once (Time >= sunset) then
    begin
      FlagSunset := true;
    end;
    
    
    once GetLightingState("Trigger PIR")= ON then
      if FlagSunset = true then
      begin
         PulseCBusLevel("Backbone", "Lighting", "Result1", 100%, "0s", "0:05:00", 0%);
         PulseCBusLevel("Backbone", "Lighting", "Result2", 100%, "0s", "0:10:00", 0%);
    end;
    
     
    Last edited by a moderator: Apr 25, 2008
    Lucky555, Apr 25, 2008
    #8
  9. markdem

    PSC

    Joined:
    Aug 3, 2004
    Messages:
    626
    Likes Received:
    0
    Location:
    Brisbane, Australia
    Ok
     
    PSC, Apr 25, 2008
    #9
  10. markdem

    Guff

    Joined:
    Feb 6, 2008
    Messages:
    31
    Likes Received:
    0
    Is there a difference between the above code and PSC's recommendation? I can't pick the difference (aside from the code / pseudo code). :confused:
     
    Guff, Apr 25, 2008
    #10
  11. markdem

    Lucky555

    Joined:
    Aug 13, 2007
    Messages:
    229
    Likes Received:
    0
    Nope - pretty much the same thing, except for the code / pseudo code thing... We both offered info based on the original profile by markdem...

    Honestly - read the logic help files they are surprisingly good compared to most help files...
     
    Last edited by a moderator: Apr 25, 2008
    Lucky555, Apr 25, 2008
    #11
  12. markdem

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    A time can not be both after sunset AND before sunrise, hence the above will never be executed.

    Change to ((Time > SunSet) OR (Time < SunRise)) as suggested by johnl.

    The logic help file gives a similar example in the "Time Function" topic.

    Thanks :D
     
    Darren, Apr 28, 2008
    #12
  13. markdem

    markdem

    Joined:
    Sep 22, 2004
    Messages:
    10
    Likes Received:
    0
    I changed the code to ((Time > SunSet) OR (Time < SunRise)), and it works like a charm.

    One quick question, is there any way to get the sunset\rise times to display on a C-Touch page? it would be nice to know, withot needing PICED.

    Thanks, Mark
     
    markdem, Apr 28, 2008
    #13
  14. markdem

    filpee

    Joined:
    May 31, 2006
    Messages:
    204
    Likes Received:
    0
    Location:
    Western Australia

    Yeah mate, easy.
    Put a clock button (or 1 each for sunrise & sunset) on the page and set its "Time/Date Displayed" option field to 'Sunset' or 'Sunrise'.
    I've got this on my panel :)
     
    filpee, Apr 28, 2008
    #14
  15. markdem

    markdem

    Joined:
    Sep 22, 2004
    Messages:
    10
    Likes Received:
    0
    That was easy, I should have looked.

    Thanks guys

    Mark
     
    markdem, Apr 28, 2008
    #15
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.