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


HC3 QuickApps coding - tips and tricks


jgab

Recommended Posts

Hi JGAB,

I have finished to modify your QA SVGTest2.fqa with my 4 floors, Temperatures displayed in each room with update every 1.5mn, each lights status On (enlarge red indicator) or Off (small green indicator) for each room with update every 1s.

I want to have the first row of buttons beeing hidden or visible by changing a quickAppVar "Grid"=false or true.

The question is there an attribute in the line

--%%u={{button='raster',text='Grille',onReleased='raster'},{button="sensors", text="Couleurs", onReleased="indicLamp"}}

which can make the buttons visible or hidden (I think the QA needs to restart)?

Do I have to change it with a QA property change?

if it is the case, will code be the same in vscode and HC3 QA?

The reason is that the raster is not needed in a normal running QA but for any change in the number of devices, raster is mandatory to place then on the picture (I spend a full day for doing it with 9+15+16+9 lights and 6+9+12+4 temp sensors) 

Again these changes will have not been possible without fibemu ( Thanks🤩)

Link to comment
Share on other sites

 

23 hours ago, Christb said:

I  want to have the first row of buttons beeing hidden or visible by changing a quickAppVar "Grid"=false or true.

The question is there an attribute in the line

--%%u={{button='raster',text='Grille',onReleased='raster'},{button="sensors", text="Couleurs", onReleased="indicLamp"}}

which can make the buttons visible or hidden (I think the QA needs to restar)

I have found a way to display or not the raster at startup and for each floor change by adding a QuickVar "NoGrid" with value "true" or "false" and launch the "raster" function conditionnaly of "NoGrid" value. Not fair code but it works👍 - for that I have also changed the "self.raster" value to "false" in SVG.lua file.

If you have a better way to do the above I will be happy to learn.

 

Also putting the "--%%u=..."  buttons and slider lines between --[[ ]]-- suppress the buttons and slider lines in the vscode web UI.

 

For the HC3 QA which is now working correctly as well:

I have use the attribute called "visible" but then QA displays blank lines where they were located so I have moved them below the image and suppress "select" line as it is not possible for the slider to hide it.

What is strange is that I have a line in the QuickApp debug window which I think is linked to "self.temps={}":

[06.03.2024] [13:40:01] [TRACE] [QUICKAPP525]: UIEvent: {"values":[2],"deviceId":525,"elementName":"sltc7","eventType":"onToggled"}
[06.03.2024] [13:40:01] [DEBUG] [QUICKAPP525]: Selected floor: 2
[06.03.2024] [13:40:01] [DEBUG] [QUICKAPP525]: createMap indx: 2
[06.03.2024] [13:40:01] [DEBUG] [QUICKAPP525]: createMap indx: 2, curr: 9
[06.03.2024] [13:40:01] [DEBUG] [QUICKAPP525]: custom [luabind::detail::null_type] object: (nil)
[06.03.2024] [13:40:01] [DEBUG] [QUICKAPP525]: No grid

What does mean that line?

Nothing similar in fibemu.

Attached the QA file

 

 

 

 

Please login or register to see this attachment.

Edited by Christb
Change the fqa files due to wrong size of temp values in Yubii applications - now OK
Link to comment
Share on other sites

I have another non expected issue: in the QuickApp variable table I cannot modify the variables the "pen" for opening modification is not displayed

What I need to declare in the code to prevent this? 

 

 

Link to comment
Share on other sites

14 minutes ago, Christb said:

I have another non expected issue: in the QuickApp variable table I cannot modify the variables the "pen" for opening modification is not displayed

What I need to declare in the code to prevent this? 

I have found that if I am creating the QuickVar from the onInit function, then it is impossible to modify it in the QA variable pannel

So I suppressed in the code the 2 lines for the 2 variables that are static and now I can modify them manualy. 😁

I have update the attached fqa file in my previous post

Link to comment
Share on other sites

As I started with your SVGtest.fqa which has been created as a binary switch the Fibaron ON/OFF buttons are there but of no use.

I tried to change its type using the Swagger but all new data are accepted except the type change.

Is this forbiden by Fibaro?

if it is the case then I will have to create a new QA with the type "com.fibaro.deviceController" and reinject all files main, SVG and images.

 

Edited by Christb
Link to comment
Share on other sites

  • Topic Author
  • Posted (edited)
    12 hours ago, Christb said:

    As I started with your SVGtest.fqa which has been created as a binary switch the Fibaron ON/OFF buttons are there but of no use.

    I tried to change its type using the Swagger but all new data are accepted except the type change.

    Is this forbiden by Fibaro?

    if it is the case then I will have to create a new QA with the type "com.fibaro.deviceController" and reinject all files main, SVG and images.

     

    No, you can't change the type of an existing QA. You need to create a new (in fibemu?) with your choice of type...

    Edited by jgab
    • Thanks 1
    Link to comment
    Share on other sites

  • Topic Author
  • 12 hours ago, Christb said:

    I have found that if I am creating the QuickVar from the onInit function, then it is impossible to modify it in the QA variable pannel

    So I suppressed in the code the 2 lines for the 2 variables that are static and now I can modify them manualy. 😁

    I have update the attached fqa file in my previous post

    The short answer is that if you store a value that is not a string you can't edit it.

    • Thanks 2
    Link to comment
    Share on other sites

    4 hours ago, jgab said:

    The short answer is that if you store a value that is not a string you can't edit it.

    It is not the first time I am asking: "Where I can find such specification?"

    Link to comment
    Share on other sites

    • 4 weeks later...
  • Topic Author
  • Posted (edited)

    So QuickApps have their own storage that is not quickAppVariables.

    It's a good place to store values that should survive restarts but we don't want them visible in the quickVar list.

    Please login or register to see this code.

    The values survive restarts of the QA but will not be saved when the QA is downloaded (only quickVars are saved with the .fqa)

     

    To make it easy to use we can wrap it up in a metatable

    Please login or register to see this code.

     

    Edited by jgab
    • Like 4
    Link to comment
    Share on other sites

    15 minutes ago, jgab said:

    So QuickApps have their own storage that is not quickAppVariables.

    It's a good place to store values that should survive restarts but we don't want them visible in the quickVar list.

    Please login or register to see this code.

    The values survive restarts of the QA but will not be saved when the QA is downloaded (only quickVars are saved with the .fqa)

     

    To make it easy to use we can wrap it up in a metastable

    Please login or register to see this code.

     

    Love this @jgab, I have used over 40 Qvars to store everything 😅

    • Thanks 1
    Link to comment
    Share on other sites

    Hi again @jgab

    May I ask for your help again. Since the last post about the storage with metatables I have cleaned up my QA I am trying to make now :D 
    And only have the needed Qvars for user to set. But I am still on alot off Qvars for Lights, relays and colourswitches 😅

     

    I have tried to figure it out by looking on other QA posted in the forum like your Devicesensor from 2020.

    where the Devices ID's can all go in 1 Qvar. But I dont understand tables and arrays and how to manipulate them well enuf yet. 

    My work around is this with 10Qvars and then store them inn a table (LightID): 

      local  LightID1 = tonumber(self:getVariable("LightID1")) or 0
      local  LightID2 = tonumber(self:getVariable("LightID2")) or 0
      local  LightID3 = tonumber(self:getVariable("LightID3")) or 0
      local  LightID4 = tonumber(self:getVariable("LightID4")) or 0
      local  LightID5 = tonumber(self:getVariable("LightID5")) or 0
      local  LightID6 = tonumber(self:getVariable("LightID6")) or 0
      local  LightID7 = tonumber(self:getVariable("LightID7")) or 0
      local  LightID8 = tonumber(self:getVariable("LightID8")) or 0
      local  LightID9 = tonumber(self:getVariable("LightID9")) or 0
      local  LightID10 = tonumber(self:getVariable("LightID10")) or 0
      local  LightID = {LightID1, LightID2, LightID3, LightID4, LightID5,LightID6,LightID7,LightID8,LightID9,LightID10}
     
     

    So I dont have  to make a hub.call for each LightID1-10

     



    I know I have seen somewhere on the forum you can do a fromat thing to set a  "," between each number inn a string and store it in the table. But cant find back too it 😅

    --[[
      local LightID = {}
      local LightID = self:getVariable("LightID1")
    ]]
    --LightID here is exampel: 2131 2049 (ID of multilevelswitches)
     
     

     

     

     

    Link to comment
    Share on other sites

    Do you mean

    lightId={}

    table.insert(lightId,LightD1)

    table.insert(lightId,LightD2) etc....

    Or

    for k,v in pairs(LightID)do table.insert(lightId,v)end

    Link to comment
    Share on other sites

     

     

    32 minutes ago, Kage said:

    Do you mean

    lightId={}

    table.insert(lightId,LightD1)

    table.insert(lightId,LightD2) etc....

    Or

    for k,v in pairs(LightID)do table.insert(lightId,v)end

     

    Hmm This is kinda the same as this? 🤔
    LightID = {LightID1, LightID2, LightID3, LightID4, LightID5,LightID6,LightID7,LightID8,LightID9,LightID10

     

     


    My goal is to only have 1 Qvar where I can type in all my multilevel switches IDS like the: "2131 2049"  and store thoose values in a table like this: 😅

    LightID = {2131,2049, "more ID'S" 

     

     

    If you know what I mean by this? 😅 
    Sorry for my bad explanation :D 
     

     

     

    Link to comment
    Share on other sites

    lightID1=155
    lightID2=314
    lightID3=329
    lightID4=270
    function QuickApp:data()
        LightId=self:getVariable('LightId')
        tb=json.decode((self:getVariable('LightId')))
        for k,v in pairs({lightID1,lightID2,lightID3,lightID4})do
            tb[v]=fibaro.getValue(v,'value')
            self:setVariable('lightId',json.encode(tb))
        end
    end
    function QuickApp:onInit()self:data()end
     
    gives
    • lightId   String variable   {"270":true,"329":25,"314":0,"155":25}
    Link to comment
    Share on other sites

    19 hours ago, Kage said:
    lightID1=155
    lightID2=314
    lightID3=329
    lightID4=270
    function QuickApp:data()
        LightId=self:getVariable('LightId')
        tb=json.decode((self:getVariable('LightId')))
        for k,v in pairs({lightID1,lightID2,lightID3,lightID4})do
            tb[v]=fibaro.getValue(v,'value')
            self:setVariable('lightId',json.encode(tb))
        end
    end
    function QuickApp:onInit()self:data()end
     
    gives
    • lightId   String variable   {"270":true,"329":25,"314":0,"155":25}


    It is somthing like this I am looking for, but this store the Lightid1-4 with their current value, am I right? 

    The thing I want to do is too take my Qvar "LightID"  with the string "26 87 116 222"             <-- ID of 4 multilevelswitches 

     

    Please login or register to see this image.

    /monthly_2024_04/image.png.b1a9c0305c1849ade84b77a49e7888ef.png" />


    And make them into a table like this:

    image.png.576764794f76ee0dc85c40cac9615667.png

     

    I dont know how to convert it from the self:getvariable to the LightID with the table

     

    It is most likly very basic, but Fibaro is my only experience with any coding at all 😅

     

    And I know I have seen someone done it somewhere on the forum before, but cant find it... :( 

     

     

     

     

     

     

     

     

     

    Link to comment
    Share on other sites

    1 hour ago, Brors94 said:


    It is somthing like this I am looking for, but this store the Lightid1-4 with their current value, am I right? 

    The thing I want to do is too take my Qvar "LightID"  with the string "26 87 116 222"             <-- ID of 4 multilevelswitches 

     

    Please login or register to see this link.


    And make them into a table like this:

    Please login or register to see this link.

     

    I dont know how to convert it from the self:getvariable to the LightID with the table

     

    It is most likly very basic, but Fibaro is my only experience with any coding at all 😅

     

    And I know I have seen someone done it somewhere on the forum before, but cant find it... :( 

     

     

     

     

     

     

     

     

     

    I am not really sure what you want to acheieve

    But if i am right you have a string variable 26,87,116,222 and you want to add them by keys into a table ?

    If so

     

    Please login or register to see this code.

     

    Edited by Neo Andersson
    • Thanks 1
    Link to comment
    Share on other sites

    2 hours ago, Neo Andersson said:

    I am not really sure what you want to acheieve

    But if i am right you have a string variable 26,87,116,222 and you want to add them by keys into a table ?

    If so

     

    Please login or register to see this code.

     

     

    Thanks for helping @Neo Andersson :D 

     

    Had some error when calling the LightID first and said it was a string :D 

    But adjusted too this and it works! Thanks alot! 

     

    local qaVar = self:getVariable("LightID")
     
     split = function(s, delimiter)
            local result = {};
            for match in (s .. delimiter😞gmatch("(.-)" .. delimiter) do
                table.insert(result, match);
            end
            return result;
        end
     
    -- Now split the string using the function
    local elements = split(qaVar, ",")
     
    -- Create the indexed LightID table
    local LightID = {}
    for i, element in ipairs(elements) do
        LightID[i] = tonumber(element)
    end

     

     


     

     

     

    Please login or register to see this attachment.

    Edited by Brors94
    Link to comment
    Share on other sites

     

    Just want to share what you guys have helped me with :D 

    and wonder if any body got some tips for additional futures for the outdoor light controller :D


    Would also appriciate comments on how to do the code better 😅 Because ill guess you guys might get a laugh 😆
     

    Please login or register to see this attachment.

     

    And if you like it you are free to use it and change it for your needs :)

    And thanks too @jgab for the Eventlib 😄

     

     

     

    Link to comment
    Share on other sites

    • 3 weeks later...
  • Topic Author
  • Running this code in an HC3 QA vs HC3 Scene

    Please login or register to see this code.

    Runs on ~10s in a QA and ~30s in a Scene.

    Both QAs and Scenes seem to run Lua 5.3 these days.

     

    So, QAs are 3x faster? Go figure...

    • Like 1
    Link to comment
    Share on other sites

    On 4/26/2024 at 10:09 AM, jgab said:

    Running this code in an HC3 QA vs HC3 Scene

    Please login or register to see this code.

    Runs on ~10s in a QA and ~30s in a Scene.

    Both QAs and Scenes seem to run Lua 5.3 these days.

     

    So, QAs are 3x faster? Go figure...

     

    So it is smart to setup most of the automasion in quickapps then? 🤔 If I understand you right :D 

    I tested on my HC3, it gave me 47s on scene and 11 on QA :) 

     

     

    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
    Reply to this topic...

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