Trackgroup Across 2 applications

Discussion in 'C-Bus Automation Controllers' started by Weedo, Feb 28, 2020.

  1. Weedo

    Weedo

    Joined:
    Mar 21, 2011
    Messages:
    20
    Likes Received:
    0
    Location:
    Toowoomba
    Hi All,

    As suggested in the title, is it possible to use the trackgroup(one-way) function when tracking a group on a different application. i.e Lighting and Security. This is possible with the trackgroup2 function but the same convention does not worth with trackgroup?

    Thanks
    Brent
     
    Weedo, Feb 28, 2020
    #1
    1. Advertisements

  2. Weedo

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,021
    Likes Received:
    80
    Location:
    Adelaide, Australia
    Actually trackgroup2 won't track between lighting and security. You can only track between lighting compatible applications.

    To track one way across apps just do it yourself.

    i.e.

    Code:
    // Globals
    varX: integer;
    
    //Module
    VarX := GetCBusLevel("Net X", "Application X", "Group X");
    if HasChanged(VarX) then SetCBusLevel("Net Y", "Application Y", VarX, 0%, "0s");
    
     
    Ashley, Feb 28, 2020
    #2
    1. Advertisements

  3. Weedo

    Weedo

    Joined:
    Mar 21, 2011
    Messages:
    20
    Likes Received:
    0
    Location:
    Toowoomba

    Thanks for the rely Ashley,
    It appears that module is utilizing PASCAL?
    This instance is using the LUA language as the project is with a shac.
    In the Shac the trackgroup is capable of cross-application tracking but is limited to the Trackgroup2 function. or so it appears?
    I can write the function in a similar form to your example, I simply like the trackgroup for it's clean syntax

    Thanks again
     
    Weedo, Feb 28, 2020
    #3
  4. Weedo

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,021
    Likes Received:
    80
    Location:
    Adelaide, Australia
    It's useful to mention what device you are running on these days as there is now a choice :)
    As far as I am aware the trackGroup functions work the same on the SHAC and have the same limitations.

    To do it manually just set up an event based script on the source group than get the script to set the destination group.
     
    Ashley, Feb 28, 2020
    #4
  5. Weedo

    Spooky

    Joined:
    Aug 28, 2006
    Messages:
    14
    Likes Received:
    1
    the lua script below is designed to be used as an event based script.

    it grabs the app, group, target level and ramp rate of the object that triggered the script and then resends it on the desired target application. its effectively what I believe is behind the track group function just done yourself.

    ive only tested on lighting type and trigger control application because i couldn't remember the security app off of the top of my head.

    at the moment you can use a keyword and it will map the group to the second application with the same group number as it was on the original application. if you want to change the group number as well trigger the event on a specific object and specify the desired group in the setcbuslevel command rather than using the group variable.

    <code>

    local source = event.dst
    local pos1 = string.find(source,'/',1)
    local pos2 = string.find(source,'/',(pos1 + 1))
    local target = event.datahex
    local application = tonumber(string.sub(source,(pos1 + 1),(pos2 -1)))
    local group = tonumber(string.sub(source, (pos2 + 1)))
    local targetlevel = tonumber(string.sub(target,3,4),16)
    local currentlevel = tonumber(string.sub(target,1,2),16)
    local ramprate = 0
    if ((application >= 48) and (application <= 95)) then
    ramprate = tonumber(string.sub(target,5,8),16)
    end
    targetapplication = 59


    SetCBusLevel(0, targetapplication, group, targetlevel, ramprate)

    </code>
     
    Last edited: Feb 28, 2020
    Spooky, Feb 28, 2020
    #5
    Pie Boy likes this.
  6. Weedo

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    51
    Likes Received:
    7
    Location:
    New Zealand
    I altered and added in a check to see if ga exists on other app first, add into common functions below then
    call function from event script
    track_group(event.dst, 58, event.getvalue(), event.datahex)

    Code:
     put in common functions
    
    function grp_to_number(obj)
       s = string.split(obj, '/')                 
      t = {net = tonumber(s[1]),
      app = tonumber(s[2]),
      group = tonumber(s[3])}
      return t
    end
    
    function track_group(from_obj, to_app, t_level, to_rate)
      grp_to_number(from_obj)
     local to_r = tonumber(string.sub(to_rate,7,8),16)
    
      -- check ga exists on other application first
     local ga_chk = CBusLookupAddresses(t.net, to_app, t.group)
     
      if ga_chk then
      SetCBusLevel(t.net, to_app, t.group, t_level, to_r)
      else
        log('Group '.. t.group.. ' dose not exist on application '.. to_app)
      end
     
    end
     
    Pie Boy, Feb 28, 2020
    #6
    Spooky likes this.
  7. Weedo

    Spooky

    Joined:
    Aug 28, 2006
    Messages:
    14
    Likes Received:
    1
    looks good, I have only just started playing with the lua string functions. string.split is much more elegant than my way.

    just need to remember that if you are tracking from a non lighting type application then :

    local to_r = tonumber(string.sub(to_rate,7,8),16) will return a null value as event.datahex changes length depending on application type. setcbuslevel() throws an error if it receives a null. also only grabbing 7-8 will result in an incorrect ramp rate for anything longer than 255 seconds. it needs the full 5-8 of the string.

    im also not sure i like how the nac handles ramping objects. i think this script will execute throughout the ramp each time the nac considers the level to have changed. I haven't tested fully but if you don't have execute during ramp ticked it doesn't do anything until the end of the ramp.
     
    Spooky, Feb 29, 2020
    #7
  8. Weedo

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    51
    Likes Received:
    7
    Location:
    New Zealand
    Yeah it executes through the ramp and cancels the last ramp call well as far as i can tell..

    Oh I see that is why you had the
    if ((application >= 48) and (application <= 95)) then
    ramprate = tonumber(string.sub(target,5,8),16)
    end

    The below should sort it, as you say it looks like event.datahex is usally 4 hex bytes long (for a app 56 group) it seems the first two bytes are always the same value twice?, and the last two bytes are the ramp rate, although most of the user parameters (app 250 ) range anywhere from 1 byte to many depending on the data type. so i guess this wouldn't work tracking to app 250?

    function call track_group(event.dst, 58, event.getvalue())

    Code:
    function grp_to_number(obj)
       s = string.split(obj, '/')                 
      t = {net = tonumber(s[1]),
      app = tonumber(s[2]),
      group = tonumber(s[3])}
     
      return t
    end
    
    function track_group(from_obj, to_app, t_level)
     
      grp_to_number(from_obj)
      local to_r = GetCBusRampRate(t.net, t.app, t.group)
     
      -- check ga exists on other application first
     local ga_chk = CBusLookupAddresses(t.net, to_app, t.group)
     
      if ga_chk then
      SetCBusLevel(t.net, to_app, t.group, t_level, to_r)
      else
        log('Group '.. t.group.. ' dose not exist on application '.. to_app)
      end
     
    end
     
    Pie Boy, Feb 29, 2020
    #8
  9. Weedo

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,021
    Likes Received:
    80
    Location:
    Adelaide, Australia
    While an interesting exercise, I am failing to see the point of any of this. Group numbers are randomly assigned and have no real significance, Certainly across applications anyway. And tracking groups across non lighting applications is fraught with danger. It seems to me if you require this then your basic design is flawed.

    Apart from that, in the SHAC why go to all that trouble? Just create a table with the source object name as the key and the destination as the value. Then in the event you just have to look up the key to get the destination.
    Easy to maintain and has no requirement to the same group number in each application.
     
    Ashley, Mar 1, 2020
    #9
  10. Weedo

    Spooky

    Joined:
    Aug 28, 2006
    Messages:
    14
    Likes Received:
    1
    Hi Ashley,

    Totally agree that tracking across the non lighting can cause very unexpected results. Not actually sure what is trying to be achieved in the original question. Only one that is sometimes necessary is lighting to trigger control for scenes. The NAC can only have trigger control addresses for scene triggers but some jobs may still have field units that don't have secondary application capability.

    I like the idea of a table and will probably implement that in a module I wrote to track groups between NACs over the ethernet. At the moment I have just stuck the groups I need linked between networks up in a range I haven't used for local control and made them match.

    Pie Boy,

    I haven't looked at what is in the object table for app 250 but it could definitely be a lot more complicated. For the lighting type it seems like the first byte is current level and the second is target or something like that. As you said they are both the same for instantaneous messages, if you do a 10min ramp though you will see the first byte progressively change throughout the ramp while the second byte stays the same.
     
    Spooky, Mar 1, 2020
    #10
  11. Weedo

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    51
    Likes Received:
    7
    Location:
    New Zealand
    @Ashley, Yeah I agree I don’t have a use for this code, but hey, interesting exercise is the only kind of exercise I do ...
    @Spooky you probably know this already, but if you tick the log box for an individual object, then go to object logs tab in the ui, it tells you the datahex value and the decoded value. FYI I only realised this yesterday.... after setting an event script with log (event.datahex) to different values numerous times. Also if you log(event) you will see what other parameters are available in the event table...
     
    Pie Boy, Mar 2, 2020
    #11
  12. Weedo

    Spooky

    Joined:
    Aug 28, 2006
    Messages:
    14
    Likes Received:
    1
    @Pie Boy thanks I hadn't noticed the decoded value, I have also just been logging everything I want to interrogate.

    I hope @Weedo has a functional solution as I feel like we took over the thread, both just doing it for the interesting exercise ;-)
     
    Spooky, Mar 2, 2020
    #12
    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.