Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Question

Posted

Hi

 

Anyone that knows how to create and use a dynamic variable like this in Fibaro-LUA?

 

Please login or register to see this code.

 

It does not work in Fibaro sandbox as _G cannot be used. 

 

Anyone with an idea?

 

 

Tnx

 

/Peo

6 answers to this question

Recommended Posts

  • 0
Posted

Are you going to read the current month?
If so, I'll do this way.

Please login or register to see this code.

 

  • 0
Guest FredrikKarlsson
Posted

Well, yes - or 

 

Please login or register to see this code.

if you don't need to do translation.

Or

 

Please login or register to see this code.

if you want more compact code that (I think) will be easier to maintain. 

  • 0
Posted (edited)

According answering some gurus here 

_G not supported - Fibaro runtime always create own environment for scenes or VSs and working there. You can’t share vars in  LUA processes like scenes or VD

FAD

Edited by 10der
  • 0
  • Inquirer
  • Posted (edited)

    @RH_Dreambox The "month" was just an example and had NO meaning at all. The question was about creating new variables at runtime in code, and not about month of the year.

     

    @10der Intention was not to share vars between VDs and/or scenes. Intention was to create and use new vars dynamically as runtime in my VD.


    I can see _G is not supported. But I have found a way to do it now... If I read a table I can dynamically create vars to use.

     

    EXAMPLE:

    Please login or register to see this code.


    But my intention is to read global predef variables (instead of "testTable") through the API like  HOST:GET('/api/globalVariables/LTCFG_ROOMS'); that hold arrays of enumvalues values like this: <ROOM>:<LIGHT_ARRAY_IDS>:<TIMER>:<AUTO_OFF>

     

    In the loop reading these enumvalues and split them at ":" I create new variables on the fly i memory with these as their values to use later on in my VD service.

     

    But as said, I found a work around :) It seem this is the only way to do it as "_G" cannot be used.

     

     

    /Peo   

    Edited by pos
    • 0
    Posted

    sorry,  but still not clear to me.

    I was said about _G 

    Please login or register to see this link.

     I not said anything about dynamically create vars... 

    but Ok, got it!

    • 0
    Guest FredrikKarlsson
    Posted
    14 hours ago, pos said:

    @RH_Dreambox The "month" was just an example and had NO meaning at all. The question was about creating new variables at runtime in code, and not about month of the year.

     

    @10der Intention was not to share vars between VDs and/or scenes. Intention was to create and use new vars dynamically as runtime in my VD.


    I can see _G is not supported. But I have found a way to do it now... If I read a table I can dynamically create vars to use.

     

    EXAMPLE:

    Please login or register to see this code.


    But my intention is to read global predef variables (instead of "testTable") through the API like  HOST:GET('/api/globalVariables/LTCFG_ROOMS'); that hold arrays of enumvalues values like this: <ROOM>:<LIGHT_ARRAY_IDS>:<TIMER>:<AUTO_OFF>

     

    In the loop reading these enumvalues and split them at ":" I create new variables on the fly i memory with these as their values to use later on in my VD service.

     

    But as said, I found a work around :) It seem this is the only way to do it as "_G" cannot be used.

     

     

    /Peo   

     

    Yes. What you really want then is just a table of key-value pairs that you store in a global variable using fibaro:setGlobal once it has been encoded into a json string, and then retrieved using fibaro:getGlobal().

    Essentially the same as _G, but you have to do it yourself :-)

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...