Handling Scene Triggers

Discussion in 'C-Bus Automation Controllers' started by Thomas, Sep 30, 2019.

  1. Thomas

    Thomas

    Joined:
    Nov 25, 2004
    Messages:
    252
    Likes Received:
    0
    I am trying to control when a scene gets set as a result of a scheduler event. I am trying it this way because I have not been able to control a scheduler from a script.
    The requirement is actually fairly simply: I want to set a scene only if a Flag (part of another scene) is not set.

    So I have done this in the SHAC, but it does not work:

    -- Get phantom scene trigger
    if GetTriggerLevel(0, 202, 31) and
    -- check if flag is OFF
    GetCBusLevel(0, 48, 6) ==0 then
    -- Set real trigger level
    SetTriggerLevel(0, 202, 34)
    -- wait for 1.5 seconds
    os.sleep(1.5)
    -- reset Trigger level for next event
    SetTriggerLevel(0, 202, 0)
    end

    The script is set up to listen to TriggerLevel 0,202,31. In my mind I shouldn't even have to test for that within the script, but whether or not I do this makes anyway no difference.
    Any help would be appreciated.

    Of course first price would be a way to control schedulers via a script.
     
    Thomas, Sep 30, 2019
    #1
    1. Advertisements

  2. Thomas

    Thomas

    Joined:
    Nov 25, 2004
    Messages:
    252
    Likes Received:
    0
    Hmm, no takers.

    Might it help if I said that this routine is running perfectly on a PAC, just with the right syntax?

    Surely the NAC or SHAC should be able to process this sort of thing, or am I too optimistic?
     
    Thomas, Oct 1, 2019
    #2
    1. Advertisements

  3. Thomas

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    961
    Likes Received:
    70
    Location:
    Adelaide, Australia
    There is no such statement as GetTriggerLevel(0, 202, 31).

    The correct statement is GetTriggerLevel(31)

    Lua is an appallingly designed language that lets you shoot yourself in the foot all the time.
    It allows you to add any number of arguments to a function without producing an error, so GetTriggerLevel(0, 202, 31) is interpreted as GetTriggerLevel(0).

    You have the same problem with SetTriggerLevel.

    Also, GetTriggerLevel returns an integer, so it is always True (in Lua only Nil or Undefined are False), so GetTriggerLevel will always return True. You need to compare it with an integer.

    An event is triggered whenever the group changes, so you need to test the value if you only want to execute when it is set to a particular level.
     
    Last edited: Oct 3, 2019
    Ashley, Oct 3, 2019
    #3
    Thomas likes this.
  4. Thomas

    Thomas

    Joined:
    Nov 25, 2004
    Messages:
    252
    Likes Received:
    0
    Thank you Ashley,

    Thank you for your reply. I share your sentiments of course. Trying to make do with this product, but it seems tedious.

    What I don't understand in what you are saying, is how Lua distinguishes between the various trigger groups.
    So if I want to get or set 202,0 to level 45, as opposed to, say 202,1 to level 45?

    Btw, it seems that in my post I mixed up the sequence in any case (should be first application 202, then the rest).
     
    Thomas, Oct 3, 2019
    #4
  5. Thomas

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    961
    Likes Received:
    70
    Location:
    Adelaide, Australia
    GetTriggerLevel take a single parameter which specifies the trigger group on the local network. You don't need to specify the application (202) as that is always the trigger application. It returns the current action selector for that trigger group. So to get trigger group 0 level would be GetTriggerLevel(0) and to get trigger group 1 level would be GetTriggerLevel(1)

    SetTriggerLevel take 2 parameters. The first is the trigger group and the second the action selector to set. So to set trigger group 0 to 45 would be SetTriggerLevel(0,45), and to set trigger group 1 to 45 would be SetTriggerLevel(1, 45).

    You don't need to specify the network or application as they are assumed.
     
    Ashley, Oct 3, 2019
    #5
    Mr Mark and Thomas like this.
  6. Thomas

    Thomas

    Joined:
    Nov 25, 2004
    Messages:
    252
    Likes Received:
    0
    Thank you very much for these explanations Ashley!
     
    Thomas, Oct 3, 2019
    #6
    1. Advertisements

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.