grp.create

Discussion in 'C-Bus Automation Controllers' started by sjfp, Jul 22, 2022.

  1. sjfp

    sjfp

    Joined:
    Oct 31, 2004
    Messages:
    145
    Likes Received:
    1
    Location:
    UK
    Want to create a template that I can use to populate objects with a standard layout,
    Using on LM machines we use as an example
    address = grp.create({
    datatype = dt.float16,
    address = '0/56/200',
    name = 'My first object',
    comment = 'This is my new object',
    tags = { 'My tag A', 'My tag B' },
    })
    but in C-Bus the object name is not getting the name 'My first new object'

    Need to get this working a I want to automate the creation of multiple objects which follow as standard zone layout.
    Any help would be appreciated
     
    sjfp, Jul 22, 2022
    #1
  2. sjfp

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    232
    Likes Received:
    31
    Location:
    Melbourne
    I see exactly the same thing.

    Thinking this would work for you, I tried setting the object's name in the SHAC database, and this works, but is not reflected in the Objects tab. The name stays as 0/56/230 even after a device reboot. Executing a create again when the group exists after the DB change results in its name attribute being set back to 0/56/230 in the DB...

    Obviously take a backup before messing with the DB.

    Code:
    address = grp.create({
      datatype = dt.uint8,
      address = '0/56/230',
      name = 'A test object',
      comment = 'A comment',
      tags = {  },
    })
    log(address)
    
    -- Get the object ID
    object = db:getall('SELECT id, name FROM objects WHERE name = "0/56/230"')[1]
    log(object)
    
    -- Update the name in the database
    log(db:execute('UPDATE objects SET name = "Testing" WHERE id = '..object['id']))
    
    -- Show the object attributes
    log(grp.find('0/56/230'))
     
    ssaunders, Jul 23, 2022
    #2
  3. sjfp

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    Depends what “name” you want to use..

    In the database under “objects” (which is where grp.create stores data) has a field called “name” which to my knowledge isnt used

    in the database under cbus tags also has a field called “name” this is the cbus tag/ name

    they are 2 different things….

    I think you will also find that grp.create() will create an object but not an association to a cbus group adress.
     
    Pie Boy, Jul 23, 2022
    #3
  4. sjfp

    sjfp

    Joined:
    Oct 31, 2004
    Messages:
    145
    Likes Received:
    1
    Location:
    UK
    Gents thanks for the replies, which now looks like we cant use the grp.create without someway to create an association between objects and c-bus tags.
    So the next question would of course be, how can we achieve this mass object creation then.
     
    sjfp, Jul 24, 2022
    #4
  5. sjfp

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    232
    Likes Received:
    31
    Location:
    Melbourne
    Doing some detective work there would appear to be an undocumented function "grp.createcbustag()". The LUA statement log(grp) shows this.

    So one could guess this is how to create an association?

    Lord knows what its parameters are. If the debug library were included on the NAC/SHAC/AC2 then the below would likely reveal them... But yeah, nah.

    (And even then it probably takes an array of parameters, like grp.create() does.)

    Code:
    function getargs(func)
        local args = {}
        for i = 1, debug.getinfo(func).nparams, 1 do
            table.insert(args, debug.getlocal(func, i));
        end
        return args;
    end
    
    for k, v in pairs(getargs(grp.createcbustag)) do
      print(k, v)
    end
     
    Last edited: Jul 24, 2022
    ssaunders, Jul 24, 2022
    #5
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.