PAC, Once, if

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by TheBear, Feb 3, 2006.

  1. TheBear

    TheBear

    Joined:
    Aug 21, 2005
    Messages:
    21
    Likes Received:
    0
    Location:
    Israel
    Hello all,
    I'm a new member in this forum and did a lot of reading here that help me a lot ?
    Since my native language isn't English (or Pascal?) I apologize in advance for my misspellings.
    Using the PAC to set a "Night" scene, I programmed a module that will turn off some GAs (about 26?) on long fade-outs and other GAs on instant Off.

    once (GetLightingState("Night_Time") = ON) then
    begin
    SetLightingState ("GAx", OFF, Xs);
    SetLightingState ("GAx", OFF, Xs);
    .
    .
    end;

    The "Night_Time" state is defined by different parameters, mostly used by a key long press.

    While using the "Once" condition the module performed just 9 actions of my code (first 9 GAs in the code list). Using an "If" condition solved all my problems.

    Is there any action number limit between "begin" and "end" using a "Once" condition? What am I missing here?
     
    TheBear, Feb 3, 2006
    #1
  2. TheBear

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    Scenes!

    Bear

    I am not sure if there is any limitation on the number of actions inside a "once" condition or "if" for that matter, however, don't worry about that, the way you described your actions is not the way to go :(

    When you wish to control several (many) C-Bus commands in a block of code put all those into a scene then simply trigger the scene. Not only is this easier to read and manage it is about 10 times more efficient in terms of processor use :)

    Also be careful when using "if" for your condition where C-Bus GA's are concerened. If the group address being checked for the condition stays on (even for a second or two) your actions (mutiple C-Bus commands) will be sent on the bus several times, (up to 5 code loops per second). If the condition stays on for more than a few seconds the logic engine will detect "C-Bus messages being sent on every loop" and stop the logic process similar to a runtime error...

    Hope this helps.
     
    Phil.H, Feb 3, 2006
    #2
  3. TheBear

    TheBear

    Joined:
    Aug 21, 2005
    Messages:
    21
    Likes Received:
    0
    Location:
    Israel
    How simple...

    Thanks for your help Phil.
    I'll master my "scene" skills...

    BTW, my last action on the action list was turning the "Night_Time" GA to OFF (just to stop the "if" from running...)

    Thanks again.
     
    TheBear, Feb 4, 2006
    #3
  4. TheBear

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    Bell Press and Loops.

    Clarification for others... Bear is on the Money !
    Using "if" with a GA then turning off the same GA in the actions is the way to go ;) This gives the equiv of a bell press action for the associated key input (button). In this case the C-Bus button is set up for on/off. If you actually set a key up in C-Bus as bell press, it is possible to have a C-Bus group address command go on and off inside the 200ms loop time of the logic engine, meaning things can get missed.
     
    Phil.H, Feb 4, 2006
    #4
  5. TheBear

    phcjpp

    Joined:
    Oct 19, 2004
    Messages:
    112
    Likes Received:
    0
    Location:
    London
    Hi,

    Quick question following on from this.

    If I want to do a 'loft off' and our loft has about 20+ groups I cannot trivially use a scene (10 limit) so I am using a pac module.

    I created a dummy group called 'LOFT OFF' and assigned it to a on/off button on a dlt.

    then did some logic along the lines of

    if (GETLIGHTINGSTATE("LOFT OFF") = "ON") THEN
    begin
    GETLIGHTINGSTATE("LOFT OFF") = "OFF"
    GETLIGHTINGSTATE("GA1") = "OFF"
    GETLIGHTINGSTATE("GA2") = "OFF"
    GETLIGHTINGSTATE("GA3") = "OFF"
    GETLIGHTINGSTATE("GA4") = "OFF"
    GETLIGHTINGSTATE("GA5") = "OFF"
    .....
    GETLIGHTINGSTATE("GA20") = "OFF"
    end

    Is that ok ? Should the LOFT OFF = OFF be the first thing that executes or the last once the logic has completed ? Any better way of doing it ?

    Thanks
    Chris
     
    phcjpp, Apr 18, 2006
    #5
  6. TheBear

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    PAC Software Properties:
    Maximum number of Scenes : 250
    Maximum number of Items per Scene : 100

    Code:
     once GetLightingState("LOFT OFF")= ON then  {It is important to(almost always) use 'once' where
    a C-Bus state is used in the condition section of a code block.}
    begin
      SetScene("Scene Loft Off"); {The scene contains all the C-Bus groups ramp times etc for the
    lights you wish to turn / ramp off following the key press mentioned.}
      SetLightingState("LOFT OFF", OFF); {The C-Bus button this group resides on should be an on/off
    type. The code turns this button back off once processed. This give the C-Bus key bell press
    behaviour and ensures the press is not missed within a code loop.}
    end;
    Take out the comments and you have three simple lines to achieve your function. :)

    PS.
    For easy reading this is what the code looks like on its own,

    once GetLightingState("LOFT OFF")= ON then
    begin
    SetScene("Scene Loft Off");
    SetLightingState("LOFT OFF", OFF);
    end;
     
    Last edited by a moderator: Apr 18, 2006
    Phil.H, Apr 18, 2006
    #6
  7. TheBear

    coppo

    Joined:
    Sep 7, 2004
    Messages:
    221
    Likes Received:
    10
    Location:
    Adelaide
    If or ONCE.. decisions, decisions


    That is the best code , as phil H says.

    Easy to read and simple to fault find.

    Another option I do ( I dont think it was mentioned yet) for auto-resetting
    of trigger buttons is using the C-Bus timer function. I program the wall plate
    switch as a 4 second timer, so the code has time to execute, then the
    button resets.
    ( this bypasses problems caused by the trigger button being reset prematurely
    or problems caused by using the logic "delay" component in your code.)


    The "IF" can be used in logic providing the following is met:
    • The Cbus Group address "condtion" is not true for > approx 15seconds.

    To prevent a continual flooding of the C-Bus network, the logic engine has a
    built-in counter set to 20 loops ( adjustable ). If it sees the same cbus
    commands sent to the network continually ( ie 1 time each loop for 20 loops)
    it will stop the logic engine and flag an error.


    If your C-Bus condition auto-resets within a typical 2-4 second time range,
    the IF can work nicely for you.


    =======================================
     
    coppo, Apr 19, 2006
    #7
  8. TheBear

    phcjpp

    Joined:
    Oct 19, 2004
    Messages:
    112
    Likes Received:
    0
    Location:
    London
    Sorry to sound dumb (pac newbie) but do you mean I define the scene in the PAC ?

    And continuing on from this - I am having a nightmare with area code addressing triggering my comfort alarm system cbus interface (works like wireless group passthrough - DLT triggers group, comfort picks it up and does action as a result - unfortunatley a house off area code is triggering it - no idea why).

    Can I do and all off in a scene in a pac by listing all 100 groups for the all off ?

    Thanks
    Chris
     
    phcjpp, Apr 19, 2006
    #8
  9. TheBear

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    I think you need to be careful with if in the condition where C-Bus is concerned.
    If the C-Bus GA in the condition is triggering a scene and that scene is large
    then leaving a GA on for 2-4 seconds (which is really unnecessary) then you could end up with many, possibly hundreds of unwanted messages on the bus by virtue of code looping 3-4 times per second + C-Bus GA left on for 4 seconds. You could be triggering your scene 16 or more times. If that scene has say 20 actions, then you have roughly 300 unnecessary C-Bus messages.

    Once is there for a very good reason. ;)
     
    Phil.H, Apr 19, 2006
    #9
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.