Pass group which triggered Event Script

Discussion in 'C-Bus Automation Controllers' started by Ks04, Oct 2, 2023.

  1. Ks04

    Ks04

    Joined:
    Dec 28, 2019
    Messages:
    110
    Likes Received:
    9
    Hi All,

    I'm trying to write a script which will syncronise my Trigger Groups with a Custom Application (49) so that I can get groups working in a nice way on my eDLTs (whoever thought this function through seems to have only half thought it through!).

    I've labelled each of my trigger groups with a keyword 'scenes' which I can use to trigger off an event, is there a way that I can then pass to the script which group triggered the event to start so I can use that group number to get the level and synchronise it?

    I want to avoid creating xx number of event scripts to synchronise each trigger if possible.
     
    Ks04, Oct 2, 2023
    #1
  2. Ks04

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    Something like

    from_level = event.getvalue()
    from_ga = string.split(event.dst, '/')

    to_app = 56
    to_level = 255
    to_rate = 0

    log(from_ga)

    if from_ga[2] == '202' then -- is from trigger control

    SetCBusLevel(tonumber(from_ga[1])), to_app, tonumber(from_ga[3]), to_level, to_rate)

    end
     
    Pie Boy, Oct 2, 2023
    #2
  3. Ks04

    Ks04

    Joined:
    Dec 28, 2019
    Messages:
    110
    Likes Received:
    9
    Thanks - that's super helpful. Are the event.xxx attributes documented anywhere? I haven't seen them and really helpful!
     
    Ks04, Oct 3, 2023
    #3
  4. Ks04

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    Pie Boy, Oct 3, 2023
    #4
  5. Ks04

    Ks04

    Joined:
    Dec 28, 2019
    Messages:
    110
    Likes Received:
    9
    Also, to give back to the community, final script I ended up using:

    Code:
    --Syncronise the scene groups and triggers
    -- Note: Assumes that there is a 1:1 mapping between the trigger groups and the lighting groups on your target application.
    from_level = event.getvalue()
    from_ga = string.split(event.dst, '/')
    
    to_app = 49 --application with mirror groups
    to_rate = 0
    
    if from_ga[2] == '49' then -- is from eDLT/lighting Group which mirrors the trigger groups
        to_level = GetTriggerLevel(from_ga[3], from_level)
        if from_level ~= to_level then
        log("Change in Mirror Group " .. tostring(from_ga[3]).. " detected, updating Trigger group to match level " .. tostring(from_level))
          SetTriggerLevel(tonumber(from_ga[3]), from_level)
      end
    end
    
    if from_ga[2] == '202' then -- is from trigger control
        to_level = GetCBusLevel(tonumber(from_ga[1]), to_app, tonumber(from_ga[3]))
      if from_level ~= to_level then
          log("Change in Trigger Group " .. tostring(from_ga[3]).. " detected, updating Lighting group to match level " .. tostring(from_level))
        SetCBusLevel(tonumber(from_ga[1]), to_app, tonumber(from_ga[3]), from_level, to_rate)
      end
    end
     
    Ks04, Oct 3, 2023
    #5
  6. Ks04

    Ks04

    Joined:
    Dec 28, 2019
    Messages:
    110
    Likes Received:
    9
    Thanks - this is quite useful in general. Makes me wonder what else I can do which isn't documented
     
    Ks04, Oct 3, 2023
    #6
  7. Ks04

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,534
    Likes Received:
    175
    Location:
    Adelaide, Australia
    It's documented under scripting/common functions/scripting basics/general information
     
    Ashley, Oct 3, 2023
    #7
  8. Ks04

    Ks04

    Joined:
    Dec 28, 2019
    Messages:
    110
    Likes Received:
    9
    In which document sorry? I just checked the SHAC User Manual and the Scripting UI but couldn't see this (But likely looking in the wrong place)
     
    Ks04, Oct 3, 2023
    #8
  9. Ks04

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,534
    Likes Received:
    175
    Location:
    Adelaide, Australia
    Open the SHAC configurator and go to scripting.
    Select either Common Functions or edit any script.
    On the right pane you see all the help.
    Select Scripting Basics, then General Information
    Voila
     
    Ashley, Oct 4, 2023
    #9
  10. Ks04

    Ks04

    Joined:
    Dec 28, 2019
    Messages:
    110
    Likes Received:
    9
    Found it now! Thanks
     
    Ks04, Oct 4, 2023
    #10
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.