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

it looks that one can add extra interface to QuickApp device, however for some reason the QA behaves strange if i called self:addInterfaces({"power"}) in onInit without any check, but with small check seems to work. Now my binary switch have power property:

 

Please login or register to see this code.

Please login or register to see this image.

/monthly_2020_03/image.png.c5c762e67cd1eab282d06d1690b99cd0.png" />

 

image.png.d4060024abd9e83a6fbe36462b8b4ab2.png

 

 

 

@A.Socha anything against (from Fibaro/design point of view) calling self:addInterfaces({"power"}) in QA to add extra interface?

 

  • Like 4
  • Thanks 2
Link to comment
Share on other sites

  • Topic Author
  • 14 minutes ago, tinman said:

    it looks that one can add extra interface to QuickApp device, however for some reason the QA behaves strange if i called self:addInterfaces({"power"}) in onInit without any check, but with small check seems to work. Now my binary switch have power property:

    @A.Socha anything against (from Fibaro/design point of view) calling self:addInterfaces({"power"}) in QA to add extra interface?

     

     

    I have added "battery" and set the "batteryLevel" property on a Hue proxy QA - works fine :-) 

    Edited by jgab
    Link to comment
    Share on other sites

    @jgab I have read all your posts with great interest. For several reasons I have not been able to join the discussion. I think you deserve plenty of "likes" so I will now randomly tag some of your posts to show my appreciation.

    Link to comment
    Share on other sites

  • Topic Author
  • 7 minutes ago, petergebruers said:

    @jgab I have read all your posts with great interest. For several reasons I have not been able to join the discussion. I think you deserve plenty of "likes" so I will now randomly tag some of your posts to show my appreciation.

    I believe that we are a few in the forum that tries to do a little bit more "advanced stuff" and it's good if we share our knowledge as the documentation kind of stops at a basic level.

    I try not to complain so much in this thread (I have another thread for that ;-) ) Also trying to keep an index in the beginning of the thread pointing to the main insights/contributions. Now I'm adding a link to @tinman's 'add Interface' finding.

    I'm pleased to have managed to get @tinman into the thread - he has some good insights. :-) 

    • Like 2
    Link to comment
    Share on other sites

    I was told on the HC3 beta tracker it was possible to mix a button and a label on the one line in a Quick App

    Please login or register to see this image.

    /monthly_2020_03/image.png.e2ddbeb432a5f0e66f50066dd0341cc8.png" />

     

    Does anybody know how ?

    Link to comment
    Share on other sites

  • Topic Author
  • 8 minutes ago, AutoFrank said:

    I was told on the HC3 beta tracker it was possible to mix a button and a label on the one line in a Quick App

    Please login or register to see this link.

     

    Does anybody know how ?

    You can if you create or modify the layout with the REST API.

    I don't think there is a way to do it with the UI.

    You can also mix slider and label on the same line

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

    3 minutes ago, jgab said:

    ou can if you create or modify the layout with the REST API.

     

    Thanks @jgab, I didn't think of that approach and will take a look 

    BTW - This is a really great post and should help a lot of people from beginners to experienced users

    All credit deserved..

     

     

    Link to comment
    Share on other sites

    as already mentioned here

     

    one can create custom QA, based on already existing device type, e.g. Fibaro Keyfob.

     

    Atatched my keyfob QA, with 1x,2x,3x,Hold Emulation.

     

    Please login or register to see this image.

    /monthly_2020_03/image.png.bc57b278243322b6b00538d80701c00b.png" />

     

    One could add as well keysequence etc., but i haven't

     

     

    Please login or register to see this attachment.

    Edited by tinman
    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • Just restricting the thread by moving out this post from the first post (where I will try to keep an index of the main insights) - Would be nice with a Wiki...

     

    Logging in QuickApps (and Scenes) are a bit lackluster. No html tags, no line breaks in strings, you can't event indent the string with preceding spaces. When I've coded quick apps now I have created my own log function (and patched QuickApps' self:debug) to make log output a bit nicer. There may come better log formatting support in the future (Logger.* doesn't do anything in QDs what I can tell)

     

    (

    Please login or register to see this link.

    )

     

    The simplest way is to do is like below. Add the missing fibaro.debug(...) that exists in scenes, and also add a convenient fibaro.printf(fmt,...) that formats its arguments with string.format. We also store QuickApp's 'self' variable in Fibaro.QD so we can access it from regular Lua functions later without having to pass 'self' around - or litter the global namespace more than necessary. 

    Please login or register to see this code.

     

    A more elaborate debug add-on that I use in my own code looks like:

    (sorry for the formatting)

    Please login or register to see this code.

    If called from QuickApp:onInit() setUpUtilities(self); self.debug = function(self,...) Log(LOG.LOG,...) end end

    it will create a function 

    Log(<tag>, ...) that logs the output formatted  (self:debug(...)  is the same as Log(LOG.LOG,...) )

    Log is a global function in the QD so no need to carry around QuickApp's self to do debug...

     

    Ex.

    Please login or register to see this code.

    and it will print

    Please login or register to see this code.

    it formats the arguments according to string.format rules.

    The tags defined are LOG = { LOG="[L] ", ULOG=" ", SYS="[Sys] ", DEBUG="[D] ", ERROR='[ERROR] ', HEADER='HEADER'}, and are easy to extend with more.

     

    Please login or register to see this code.

    will print

    Please login or register to see this code.

     

    When I start up my "QD project" the log looks like

    Please login or register to see this code.

    There is also a Debug function

    Debug(<flag>,...) is like Log(LOG.DEBUG,...) but only prints if <flag> is true and prints with the prefix [D]

     

    It automatically does json.encode on table values before printing them.

    It breaks up the line if it contains "\n"

     

    The last thing the code does is that if a table has a __tostring field in it and it points to a function, that function is used to format the table. (It actually patches tostring)

    Ex.

    Please login or register to see this code.

    will print

    Please login or register to see this code.

    ...which is handy if you have your own defined data structures...

     

    Edited by jgab
    Link to comment
    Share on other sites

    I am looking to write to the space under the QuickApp name

    Please login or register to see this image.

    /monthly_2020_03/image.png.b5c6366a68a61834ea6f857f026fd915.png" />

     

    Dimmer 2  s an actual zwave device so the off, on and % are there by default

    Office Window is of type window sensor and shows the last breached

    Hall Lamp is a binary switch QuickApp (of a sonoff device) but I am looking to write to the space under the name like fibaro:log or ticking the Main/Fav box in a VD

     

    Anybody know if this can be done ...?

    Link to comment
    Share on other sites

  • Topic Author
  • On 3/1/2020 at 5:19 PM, petrkl12 said:

    @jgab

    Could you please add "addInterfaces" to fibaroapi ? Thanks

    As part of hc3_emulator.createQuickApp and hc3_emulator.createProxy ?

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • 8 minutes ago, petrkl12 said:

    for ZB to be able to call it

    Ok, v 0.42 has self:addInterfaces(list)

    Link to comment
    Share on other sites

  • Topic Author
  • 21 minutes ago, AutoFrank said:

    I am looking to write to the space under the QuickApp name

    Please login or register to see this link.

     

    Dimmer 2  s an actual zwave device so the off, on and % are there by default

    Office Window is of type window sensor and shows the last breached

    Hall Lamp is a binary switch QuickApp (of a sonoff device) but I am looking to write to the space under the name like fibaro:log or ticking the Main/Fav box in a VD

     

    Anybody know if this can be done ...?

    My experience so far:

    -It seems to depend on what type the QuickApp is, and then the UI fetches appropriate property and displays it.

    -I have QuickApps for Hue devices of type lux, motion, and temperature and the UI fetches the values from the property ('value' in this case)

    -There seems to be nothing in the device structure that hints what value should be displayed and how it should be interpreted.

    Link to comment
    Share on other sites

    Another observation:

    In plugins on this line name of device shown... by changing the name this line changes accordingly.

    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    There seems to be nothing in the device structure that hints what value should be displayed and how it should be interpreted

     

    Thanks @jgab

    I'll log an enhancement/query on the beta page 

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • On 3/1/2020 at 3:08 PM, AutoFrank said:

    I was told on the HC3 beta tracker it was possible to mix a button and a label on the one line in a Quick App

    Please login or register to see this link.

     

    Does anybody know how ?

     

    It seems you can't modify an already uploaded device

    (I have tried  /devices/<id> without any luck, always gets unknown device type)

    However, you can download the fqa, and modify the viewLayout by hand.

    I have some code in fibaroapiHC3.lua which allows me to dynamically create a QuickApp and where I can specify the UI elements.

    Please login or register to see this code.

    I have discovered that there is a single and multi-select popup possible. 

    And also to add an image... the latter needs some investigation how to scale it.

     

     

     

    Edited by jgab
    Link to comment
    Share on other sites

    Please login or register to see this code.

    hmm, it must be possible to modify properties.viewLayout

    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    However, you can download the fqa, and modify the viewLayout by hand

    Thanks @jgab

    I had also started to look at this and found I could modify labels and buttons sizes but could not see a logic to the layout code .

    I was going to back to it during the week but will use tour code to see if I can find a way..

    Thanks for sharing .... 

    Edited by AutoFrank
    Link to comment
    Share on other sites

    • jgab changed the title to SDK for remote and offline HC3 development.

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