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


  • 0

check if qa variable exists and if not create it


Jay Ess

Question

12 answers to this question

Recommended Posts

  • 0

api.post("/globalVariables",{name="myVar", value="ok",isEnum=false, readOnly=false})

4 minutes ago, jgab said:

api.post("/globalVariables",{name="myVar", value="ok",isEnum=false, readOnly=false})

Ah, you asked for a QA variable....

You don't need to create them - just self:setVariable("Test",55) will create test if it doesn't exist.

Edited by jgab
Link to comment
Share on other sites

  • 0

and unfortunately, with Fibaro's wisdom they let self:getVariable("test") return "" if the variable doesn't exists (but you get a warning in the console)

 

Link to comment
Share on other sites

  • 0

After:

 

var = self:getVariable("var")

 

I do:

 

if var == "" or var == nil then

  var = “1234”

  self:setVariable("var",var)

end

 

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • when i run this in a qa i get this error: setup.lua:10: attempt to index a nil value (global 'self')

    this is my function which i am trying to setup:

    function setQAVariables()

        local CornerVariableName = "shabbosLightCorner"

        local DovidVariableName = "shabbosLightDovid"

        local RifkaVariableName = "shabbosLightRifka"

        local ShanaVariableName = "shabbosLightShana"

        local tb={CornerVariableName,DovidVariableName,RifkaVariableName,ShanaVariableName}

        for k,v in pairs(tb)do

            print(v)

            var = self:getVariable(v)

            if var == "" or var == nil then

                self:setVariable(v, "true")

            end

        end

    end

    what am i doing wrong?

    Link to comment
    Share on other sites

    • 0

    You can only use self inside a 

    function QuickApp:<name>(….) 

     ….

    end

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • if i have a function fn(a,p)

    return a*p

    end

     

    i now want to set a qa variable how do i do that please?

    i cant use self:setVariable as the function is not a QUickApp:function?

    Link to comment
    Share on other sites

    • 0
    16 hours ago, Jay Ess said:

    if i have a function fn(a,p)

    return a*p

    end

     

    i now want to set a qa variable how do i do that please?

    i cant use self:setVariable as the function is not a QUickApp:function?

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • sorry thought i had understood what you had written but i try it, i cant get it to work and throws me errors.

    i am trying to get a qa variable.

    Edited by Jay Ess
    Link to comment
    Share on other sites

    • 0
    17 minutes ago, Jay Ess said:

    is there a way of getting the last update of the qa variable?

    You mean when it was updated? Not really for an individual quickAppVariable.

    You can get the last time any quickAppVariable was updated

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • local sLastUpdateTime = select(2,fibaro.get(self.id,'quickAppVariables')) this does the same with out having to define the _variable correct?

    Link to comment
    Share on other sites

    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...