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


Question

Posted

how do i create a new qa (self) variable fromw ithin a qa please?

12 answers to this question

Recommended Posts

  • 0
Posted (edited)

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
  • 0
Posted

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)

 

  • 0
Posted

After:

 

var = self:getVariable("var")

 

I do:

 

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

  var = “1234”

  self:setVariable("var",var)

end

 

 

  • 0
  • Inquirer
  • Posted

    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?

    • 0
    Posted

    You can only use self inside a 

    function QuickApp:<name>(….) 

     ….

    end

     

    • 0
  • Inquirer
  • Posted

    thank you fixed

    • 0
  • Inquirer
  • Posted

    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?

    • 0
    Posted
    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.

     

    • 0
  • Inquirer
  • Posted (edited)

    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
    • 0
  • Inquirer
  • Posted

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

    • 0
    Posted (edited)
    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
    • 0
  • Inquirer
  • Posted

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

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