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

  • Topic Author
  • 2 minutes ago, petrkl12 said:

    hmm, I expect something in ZBS menu :)

    it looks that sometimes QA will not work in HC3L or Yubii without visible reason :(

     

    Yes, lots of issues with 32bits integers. 

    @jompa68had this problem on his Nice box.

    Please login or register to see this code.

    returns -60.0 on the HC3 as expected, but 0.0 on the "nice" box. 

    We are adding a small decimal to a rather large integer, but the result is still unexpected....

    Took quite some time to hunt down that bug...

     

    Sometimes in ER the offset to os.time() happen to turn into a float (happens easily in some cases)...

     

    Link to comment
    Share on other sites

    • 2 weeks later...
  • Topic Author
  • More people are starting to code QuickApps using several "QuickApp files". It's convenient to have a library of functions or just structure a code into separate files.

    More specifically, we can share Lua global variables (and function) between QA files.

     

    However, there are some pitfalls.

     

    QA files are more or less loaded in random order.

     

    When all files have loaded, the QuickApp object is created and the :onInit() method called.

     

    This means that if you in one file set a global Lua variable. Ex.

     

    foo = 42

     

    and in another file set another global that depends on 'foo'

     

    bar = foo+55

     

    it will depend in what order the QA files are loaded.

     

    The order they load seems to depend on in what order they are created - not strictly in top-down order. It seems like they always load in the same order until you add or remove a file, then you can get another order.

    This means that bugs can appear months after the QA have been working flawless... just because something innocent was edited in a QA file.

     

    So, be careful with global Lua constants defined in separate files.

    Be careful with classes (QuickAppChildren etc) defined in separate files (they are global values).

     

    In general it's a good practice to not use (reference) any global values until you have entered the :onInit() function. Exeption is of course if there is only one QA file - then you just follow the Lua scope rules...

     

     

     

     

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

    6 hours ago, jgab said:

    More people are starting to code QuickApps using several "QuickApp files". It's convenient to have a library of functions or just structure a code into separate files.

    More specifically, we can share Lua global variables (and function) between QA files.

     

    However, there are some pitfalls.

     

    QA files are more or less loaded in random order.

     

    When all files have loaded, the QuickApp object is created and the :onInit() method called.

     

    This means that if you in one file set a global Lua variable. Ex.

     

    foo = 42

     

    and in another file set another global that depends on 'foo'

     

    bar = foo+55

     

    it will depend in what order the QA files are loaded.

     

    The order they load seems to depend on in what order they are created - not strictly in top-down order. It seems like they always load in the same order until you add or remove a file, then you can get another order.

    This means that bugs can appear months after the QA have been working flawless... just because something innocent was edited in a QA file.

     

    So, be careful with global Lua constants defined in separate files.

    Be careful with classes (QuickAppChildren etc) defined in separate files (they are global values).

     

    In general it's a good practice to not use (reference) any global values until you have entered the :onInit() function. Exeption is of course if there is only one QA file - then you just follow the Lua scope rules...

     

     

     

     

     

    It could be perfect to have possiblity to setup order in Main file ...

    Link to comment
    Share on other sites

    attached small toy QA to check internet, reconnect wifi, and enable/disable wifi (which actually is better when one use more than one wifi, so HC will chose itself the working wifi when radio is again enabled).

     

    Please login or register to see this image.

    /monthly_2022_01/image.png.b23e31759e3b99914bbaf441750f1f14.png" />

     

     

     

    Check internet need to be called from TriggerQA or scene or any other loop, i decided to not implement anything here to let open to user how to check.

     

    The QA value is true/false, depending on internet state.

    Get WiFi UUID need to be clicked once in order to be able to use reconnect WiFi

    Disable / Enable WiFi RF is more automatic, as described above.

     

    Please login or register to see this attachment.

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

  • Topic Author
  • Playing with the new com.fibaro.multiPositionSwitch type. Tip from @Krikroff.

    Can't emulate the UI updates yet, but can be deployed from the emulator to the HC3.

     

    Please login or register to see this code.

     

    Please login or register to see this image.

    /monthly_2022_01/image.png.13cbcc146c08b6c0e3ddd5911998f844.png" />

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

  • Topic Author
  • The multiPositionSwitch is like a global variable enum. It has a number of positions or states that it keeps in the property 'position'. It was difficult in the past to have a QA of this type as there was usually no suitable property for a string value.

    The current position button is also highlighted (blue).

    Scenes can also easily trigger on position changes.

    It is also a bit dynamic when it comes to displaying buttons for positions as they are updated when the availablePositions property is updated.

     

    Mapping to QuickApp function I would probably code like this

    Please login or register to see this code.

     

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

  • Topic Author
  • Here is an example  how to use  the multiPositionSwitch as a simple TimeOfDay state switch using the EventRunner QA.

    It's interesting as the StateQA used is just one line - the smallest useful QA I've written so far...?

     

    Link to comment
    Share on other sites

  • Topic Author
  • Hack-of-the-day...

     

    Please login or register to see this attachment.

    • Like 9
    • Thanks 1
    Link to comment
    Share on other sites

    11 minutes ago, jgab said:

    Hack-of-the-day

     

    frakking cool!

    Link to comment
    Share on other sites

  • Topic Author
  • 22 minutes ago, tinman said:

     

    frakking cool!

    It brings back the memories when doing 2-D game tiles... ;-)

     

    • Thanks 1
    Link to comment
    Share on other sites

    42 minutes ago, jgab said:

    Hack-of-the-day...

     

    How it can be edited? Meaning different Breach points and house layout.

    Link to comment
    Share on other sites

    56 minutes ago, jakub.jezek said:

    How it can be edited? Meaning different Breach points and house layout.

     

    take your house layout

    tile it to section (of interest)

    save sections as dotted and not dotted png files

    convert files to base64 code

    paste base64 code to QA

    • Like 1
    • Thanks 1
    Link to comment
    Share on other sites

    1 hour ago, tinman said:

    take your house layout

    tile it to section (of interest)

    save sections as dotted and not dotted png files

    convert files to base64 code

    paste base64 code to QA

    Great, thanks.

    Link to comment
    Share on other sites

  • Topic Author
  • So I have lua code  that takes a directory with tile .pngs and create a QuickApp file that can be included in the QA.

    HouseMap.lua

    Please login or register to see this spoiler.

     

    The files in the directory should be named 

    <name>_<index>_<tag>.png

    Ex. "myFile_1_base.png"

    'tag' is the layer. It can be "0","1","2","3"... or whatever. You need to have a layer that is called "base" or "0".

    'index' is the tile number, starting with 1 in the upper left and going right and down (one index serie per layer).

    Please login or register to see this attachment.

     

    You also set a row constant that is how many rows the map  is divided up in and the outputFile is the name of the generated QuickApp file.

    In the example above, in HouseMap.lua set

    Please login or register to see this code.

     

    I use a Mac program, PixelMator Pro' to divide up the picture into tiles. I can turn on and off various layers before exporting the tiles making it fairly simple.

     

    When the QA file is loaded in your QA you have a ImageMap class defined that helps you render the map.

    Please login or register to see this code.

     

    An example QA like I posted earlier then look like

    Please login or register to see this code.


     

     

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

    20 hours ago, jgab said:

    Hack-of-the-day...

     

    Please login or register to see this attachment.

     

    Yeah, combining HTML generation with HC FQA Lua stuff and imaging conversion, throw in some base64 coding...

     

    That's next level coding!

    • Like 1
    Link to comment
    Share on other sites

    21 hours ago, SmartHomeEddy said:

    I have images from the breach in the toilet room ?

    nudes only in PM. :D 

    • Like 1
    Link to comment
    Share on other sites

    On 2/3/2022 at 4:45 PM, jgab said:

    So I have lua code  that takes a directory with tile .pngs and create a QuickApp file that can be included in the QA

    Please login or register to see this spoiler.

    This is mindblowing cool ? tand combined with the Alarm - wauu

    I installed PixelMator Pro - i found a Hires PDF of my house . 

    so next step ...

    What should the resolution be for the PNG files?

    Also can I do 5x3 tiles? or is there a limit?

     

    Edited by ChristianSogaard
    P
    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...