This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

grp.create()
#1
I'm trying to figure out how to generate a series of viritual adresses. example:

room_nr = {name=, datatype=, }
functions =
 
etc...

I want GA's to be named something like this: "room_nr""function"

i guess I need a for loop, based on room_nr, but how do I separate the different roomnumbers in the table? 
It's most likely easy, brain is in weekend mode Smile
Reply
#2
Use this as a starting point:
Code:
for i = 1, 10 do
  name = 'room ' .. i
  log(name)
end
Reply
#3
What is the best way, when using grp.create, to check if the GA is allready created? I'm thinking of making a dynamic script, so that when I add new GA's and tag them correctly the script will generate new virtual GA's.
Reply
#4
You can use grp.find().
Reply
#5
Regarding this, and the funcion string.gsub() my pattern is '_PV' but i also have some GA's named '_PV3'. is there any way to make this function to apply only with _PV and not _PV3?
Reply
#6
If your string ends with _PV then you can use _PV$ regular expression. See this for more info: https://www.lua.org/manual/5.1/manual.html#5.4.1
Reply
#7
(12.02.2024, 08:20)tomnord Wrote: What is the best way, when using grp.create, to check if the GA is allready created? I'm thinking of making a dynamic script, so that when I add new GA's and tag them correctly the script will generate new virtual GA's.

I use function block like this when automatically generating addresses in my programs...

Code:
--**********CREATE GROUP ADDRESSES******************
function createga(groupaddress,datatype,name)
  exist = grp.alias(groupaddress)
  if exist == nil then
    address = grp.create({
    datatype = datatype,
    address = groupaddress,
    name = name,
    comment = 'Automatically created object',
    units = '',
    tags = { },
    })
  end
end
On some systems I use user script where I put all needed group addresses (so they all are on the same file and it's quite easy to change them)..

User script (HEATING_config):
Code:
Main_GA = '33'

group_address_for_frontend_update = '/0/0'        --If any modifications on values or chart must be updated, this variable is used.
group_address_for_backend_update = '/0/1'        --If any modifications on values or data file must be updated, this variable is used.

Scheduled/Resident/Event script:
Code:
require('user.HEATING_config')
createga( Main_GA .. group_address_for_backend_update, dt.bool,'HEATING - Update backend')
createga( Main_GA .. group_address_for_frontend_update, dt.bool,'HEATING - Update frontend')

--DO SOMETHING


Hope this helps...
Reply
#8
Thanks guys. I'll do some testing
Reply
#9
Hi I have a function in a script for creating the necessarily groupadresses. But in this script it´s not creating the adresses, can I ask if someone can see what can be the issue? 

Code:
-- Skapa nödvändiga gruppadresser
local function skapaGruppadresser()
    local maxZoner = 25  -- Antagande att det finns max 25 zoner
    for i = 100, 121 do
        -- Adresser och namn för zonerna
        local varaktighetAddress = '40/2/' .. i
        local dagligVaraktighetAddress = '40/4/' .. i
        local varaktighetName = 'Varaktighet Zon ' .. i
        local dagligVaraktighetName = 'Daglig Varaktighet Zon ' .. i

        -- Skapa adress för varaktighet om den inte redan finns
        if not grp.find(varaktighetAddress) then
            grp.create({datatype = 'dt.text', address = varaktighetAddress, name = varaktighetName})
        end

        -- Skapa adress för daglig varaktighet om den inte redan finns
        if not grp.find(dagligVaraktighetAddress) then
            grp.create({datatype = 'dt.text', address = dagligVaraktighetAddress, name = dagligVaraktighetName})
        end
    end

    -- Skapa återställningsflagga om den inte redan finns
    local resetAddress = '40/3/0'
    if not grp.find(resetAddress) then
        grp.create({datatype = 'dt.bool', address = resetAddress, name = 'Återställningsflagga'})
    end
end

skapaGruppadresser()
Reply
#10
datatype field should be either dt.text (without quotes) or 'text'
Reply
#11
(13.04.2024, 08:44)admin Wrote: datatype field should be either dt.text (without quotes) or 'text'

Thanks! That solved it... Big Grin
Reply


Forum Jump: