Holiday mode Please asist

Discussion in 'General Discussion' started by ADL, Mar 4, 2008.

  1. ADL

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,420
    Likes Received:
    62
    Location:
    Adelaide
    If you look at the definition of the SetCBusLevel procedure :

    "The SetCBusLevel procedure sets the level of a C-Bus Group Address.

    Syntax

    SetCBusLevel(Network, Application, GroupAddress, NewLevel, RampRate);

    Network is an Integer or Network Tag.
    Application is an Integer or Application Tag.
    GroupAddress is an Integer or Group Address Tag.
    NewLevel is an Integer, Percent or Level Tag
    RampRate is an integer (number of seconds) or Ramp Rate Tag"

    You can see that that parameter is the Group Address, so "Result1" must be the result of some other procedure elsewhere in the code which I'm guessing chooses a group address from a list in order to give an amount of randomness to the particular light that gets switched on.

    Nick
     
    NickD, Jan 5, 2009
    #21
  2. ADL

    Lucky555

    Joined:
    Aug 13, 2007
    Messages:
    229
    Likes Received:
    0
    Hi Guys,

    I wrote the example code more as a training example than as real code. As NickD pointed out the action of the above example is a SetCBusLevel procedure, so in this case the "Result1" represents a C-Bus Group Address Tag. For a real domestic project the tag might be "Entry Lights" or "Lounge Lights " etc. The result could also be a SetCBusScene etc.

    In relation to the "FlagSecurityArmed" this is a declared Boolean variable that would typically follow the state of a C-Bus group address that is linked to the armed state of a security system - typically via a bus coupler or Aux input unit. You obviously don't want this sort of behavior going on when the house is occupied. If you have a bus coupler or Aux input you could also have a C-Bus group address follow the armed state of the security system, to either check before actioning code, or as stated, to enable a module containing the security lighting code. Used FlagSecurityArmed again just as a training example... (Will check the code example to make sure I didn't leave out the bit handling the FlagSecurityArmed control.

    Hope this clears it up for you... ;)

    P.S.
    Yep - left out the bit controlling the FlagSecurityArmed. Once declared you can easily write some code to link this to a C-Bus Group Address from a bus coupler etc that follows the armed state of a security system. Easier still you can just use the C-Bus group address from the coupler and test it's state instead of a flag - bool variable. For this to work your security armed state / relay must latch. Relay / GA on whilst armed, then relay / GA turns off when disarmed...
     
    Last edited by a moderator: Jan 6, 2009
    Lucky555, Jan 5, 2009
    #22
  3. ADL

    inpowers

    Joined:
    Jul 1, 2007
    Messages:
    44
    Likes Received:
    0
    Location:
    Sydney
    Thanks for all the replies
    Lucky555 would it be to much to ask for a example of the logic that you have used with the FlagSecurityArmed using a Bus Coupler (Alarm ON) as the trigger.

    Code:
    {Module}
    once (Time = "23:00:00")then
    begin
      RandomTime1 := random ("0:30:00") + "0:10:00";
      RandomTime1a := random ("0:30:00") + "0:10:00";
      RandomTime2 := random ("0:30:00") + "0:10:00";
      RandomTime2a := random ("0:30:00") + "0:10:00";
    end;
    
    {Note in the code below we are using RandomTime1 in conjunction with nominated time of 1900 hours
    also note our PulseCBusLevel code uses RandomTime1a in lieu of the standard timer time. Remember
    if the Result1 group is controlled by any other device inside the pulse duration, the pulse timer
    will be cancelled.}
    
    once (Time = "19:00:00" + RandomTime1) then
    begin
      if FlagSecurityArmed = true then
      begin
        PulseCBusLevel("Backbone", "Lighting", "Result1", 100%, "0s", RandomTime1a, 0%);
      end;
    end;
    
    once (Time = "19:30:00" + RandomTime2) then
    begin
      if FlagSecurityArmed = true then
      begin
        PulseCBusLevel("Backbone", "Lighting", "Result2", 100%, "0s", RandomTime2a, 0%);
      end;
    end;

    Thank in advance
    Rob
     
    inpowers, Jan 6, 2009
    #23
  4. ADL

    Lucky555

    Joined:
    Aug 13, 2007
    Messages:
    229
    Likes Received:
    0
    Hope this helps;

    Code:
    {Enter Variable definitions here}
    
    FlagSecurityArmed : boolean;
    
    Code:
    {Enter Initialisation code here}
    
    FlagSecurityArmed := FALSE;
    
    Code:
    {The code below ties the C-Bus Group Address CBusAlarmOn to the FlagSecurityArmed
     variable}
    
    once GetLightingState("CBusAlarmOn")= ON then
    begin
      FlagSecurityArmed := TRUE;
    end;
    
    once GetLightingState("CBusAlarmOn")= OFF then
    begin
      FlagSecurityArmed := FALSE;
    end;
    
    {From here you can use the FlagSecurityArmed to be the controlling condition
    for several things like -}
    
    once FlagSecurityArmmed = TRUE then
    begin
      EnableModule("Security Lights");
      {Do something else;}
      {Do something else again;}
    end;
    
    once FlagSecurityArmmed = FALSE then
    begin
      DisableModule("Security Lights");
      {Do something else;}
      {Do something else again;}
    end;
    
    {The benefit of using the FlagSecurityArmed variable is you can write code
    elsewhere that also controls it below you can see how the same sort of
    code is linked directly to the controlling C-Bus Group Address -
    this is more straight forward but a little less flexible down the track.}
    
    once GetLightingState("CBusAlarmOn")= ON then
    begin
       EnableModule("Security Lights");
      {Do something else;}
      {Do something else again;}
    end;
    
    once GetLightingState("CBusAlarmOn")= OFF then
    begin
      DisableModule("Security Lights");
      {Do something else;}
      {Do something else again;}
    end;
    
    Did three code windows to represent the code sections in PICED - Considerate I thought...
     
    Last edited by a moderator: Jan 6, 2009
    Lucky555, Jan 6, 2009
    #24
  5. ADL

    ICS-GS

    Joined:
    Nov 1, 2004
    Messages:
    347
    Likes Received:
    0
    Location:
    SE Melbourne
    Very...:p

    only (for the newbies) you did not define the seperate sections, but most of us know what you are on about!
     
    ICS-GS, Jan 7, 2009
    #25
  6. ADL

    inpowers

    Joined:
    Jul 1, 2007
    Messages:
    44
    Likes Received:
    0
    Location:
    Sydney
    OK Thanks Lucky555 for the quick response.
    This is what I have come up with.
    Could you be so kind to give it a once over and tell me were I have stuffed up.
    Hopefully not to many mistakes.

    First part is the variables as you described in your earlier response.
    Code:
    {Advanced.var.}
    RandomTime1, RandomTime1a, RandomTime2, RandomTime2a : integer;
    FlagSecurityArmed : boolean;
    Second is the initialisation
    Code:
    {Advanced.Initialisation.}
    RandomTime1 := random ("0:30:00") + "0:10:00";
    RandomTime2 := random ("0:30:00") + "0:10:00";
    RandomTime1a := random ("0:30:00") + "0:10:00";
    RandomTime2a := random ("0:30:00") + "0:10:00";
    FlagSecurityArmed :=FALSE;
    And last of all the Module
    Code:
    once (Time = "20:30:00")then
    begin
      RandomTime1 := random ("0:30:00") + "0:10:00";
      RandomTime1a := random ("0:30:00") + "0:10:00";
      RandomTime2 := random ("0:30:00") + "0:10:00";
      RandomTime2a := random ("0:30:00") + "0:10:00";
    end;
    
    once (GetLightingState("Away Mode") = ON) and
         (Time = sunset + "0:15:00") and
         (Time < "10:50:00 PM") then
    begin
      FlagSecurityArmed := TRUE;
    end;
    
    once GetLightingState("Away Mode")= OFF then
    begin
      FlagSecurityArmed := FALSE;
    end;
    
    {From here you can use the FlagSecurityArmed to be the controlling condition
    for several things like -}
    
    
     once (Time = sunset + "0:15:00" + RandomTime1) and
          (Time < "10:50:00 PM") then
    begin
      if FlagSecurityArmed = TRUE then
      begin
        PulseCBusLevel("Doochs", "Lighting", "Study Lights 1", 100%, 0, RandomTime1a, 0%);
        PulseCBusLevel("Doochs", "Lighting", "Lounge Rm Lights", 90%, 600, RandomTime1a, 0%);
      end;
    end;
    
    once (Time = sunset + "0:15:00" + RandomTime2) and
         (Time < "10:50:00 PM") then
    begin
      if FlagSecurityArmed = TRUE then
      begin
        PulseCBusLevel("Doochs", "Lighting", "Deck Wall Lights", 100%, 1020, RandomTime2a, 0%);
        end;
    end;
    Regards
    Rob
     
    inpowers, Jan 8, 2009
    #26
  7. ADL

    Lucky555

    Joined:
    Aug 13, 2007
    Messages:
    229
    Likes Received:
    0
    inpowers, you have not stuffed up however writing simple concise code is the way to go. A clever man once said "best way to write good code is to start by writing no code" - have a really good think about the logical / functional flow of what you want to happen. Then think about it from several different directions. If you can break the flow from the logical / functional perspective then don't even try to code a solution.........

    So..... from a logical perspective -
    Code:
    once (GetLightingState("Away Mode") = ON) and
         (Time = sunset + "0:15:00") and
         (Time < "10:50:00 PM") then
    begin
      FlagSecurityArmed := TRUE;
    end;
    
    Strictly speaking the FlagSecurityArmed is true whenever "Away Mode" is on regardless of time being sunset + 15 minutes and time being greater that 10:50pm.

    run with -
    Code:
    once GetLightingState("Away Mode") = ON then
    begin
      FlagSecurityArmed := TRUE;
    end;
    
    Simple and clean plus it makes sense..

    Code:
    once (Time = sunset + "0:15:00" + RandomTime1) and
          (Time < "10:50:00 PM") then 
    AND logic is heavy on the processor - so for the above 10:50pm is always going to be greater than sunset + 15 minutes + a random time - so the code above is verbose and unnecessary.
    If you are working with a time obviously past sunset etc then just deal with that time plus a random value eg

    Code:
    once (Time = "20:30:00" + RandomTime1) then
    begin
      PulseCBusLevel("Local Network", "Lighting", "Dining", 100%, "0s",RandomTime1a, 0%);
    end; 
    One other thing when you consider the following -

    PulseCBusLevel(Network, Application, GroupAddress, NewLevel, RampRate, Duration, FinalLevel);

    Code:
    PulseCBusLevel("Doochs", "Lighting", "Deck Wall Lights", 100%, 1020, RandomTime2a, 0%); 
    what is with the RampRate of 1020 ???

    If you keep things really simple it will be easy on the processor, it will work well and in 6 months when you come back to read what you have done it will still make sense.

    Hope this helps.

    PS. The summer holidays come to an end. Next week will be back at work and back on the dreaded tread mill - won't have to much time to be helping out in the C-Bus forums.

    All the best gang...
     
    Lucky555, Jan 9, 2009
    #27
  8. ADL

    inpowers

    Joined:
    Jul 1, 2007
    Messages:
    44
    Likes Received:
    0
    Location:
    Sydney
    Thanks Lucky555
    You have been a great help.
    Will do as you say and see how I go.
    As for the 1020 that is the ramp rate to turn the light on.:)

    Regards
    Rob
     
    inpowers, Jan 9, 2009
    #28
  9. ADL

    Lucky555

    Joined:
    Aug 13, 2007
    Messages:
    229
    Likes Received:
    0
    A ramp rate of 1020 is no good. I can't understand why you would want to ramp the lights on over 17 minutes. Stick with a ramp rate of "0" or "4s" (seconds)

    You can use your FlagSecurityArmed to enable / disable a "Security Lights" module - just be careful when enabling modules that you don't introduce a big load to the processor if you already have a big program running. The benefit is your processor does not need to process extra lines whilst the security system is not armed.

    Otherwise you can write some code in a permanent module that checks time first then checks the FlagSecurityArmed etc.

    Code:
    once (Time = "21:15:00" + RandomTime1) then
    begin
       if SecurityArmedFlag = TRUE then
       PulseCBusLevel("Local Network", "Lighting", "Hall", 100%, "4s", RandomTime1a, 0%);
    end; 
    Enjoy ;)

    PS. Remember full random lighting in a home whilst away sounds like a good idea but in reality isn't that good. Goes back to the functional flow concept that it all starts with. During an evening you typically spend time around the kitchen, dining, lounge areas in the early part of the evening (cooking, eating, watching tele etc,) later in hallways, bathrooms and bedrooms etc as you get closer to retiring - so make your lighting roughly follow this pattern with some random times thrown in. This sort of makes it semi or sensible random ;)
     
    Last edited by a moderator: Jan 9, 2009
    Lucky555, Jan 9, 2009
    #29
  10. ADL

    muppets

    Joined:
    Oct 26, 2007
    Messages:
    98
    Likes Received:
    0
    Nice work lucky simple and effective code - mine is normally neither :eek:

    What happens if a scene is pulsed? I am sure I have tried it before but can a scene be pulsed by logic or is it only through the scene manager?
     
    muppets, Apr 24, 2009
    #30
  11. ADL

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    It isn't supported in logic directly. It is easy enough to set the scene to one level, delay for a while then set the scene to another level.
     
    Darren, Apr 25, 2009
    #31
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.