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
  • 7 minutes ago, ChristianSogaard said:

    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?

     

    The tiles can be  "any"  size as they are scaled down to the width given (600)

    I wouldn't make them  large as it just takes space. If the width is 600 and you have 3 columns, don't make them more than 200-250 each.

    I believe that you have more space vertically (haven't tested) so it can make sense to have the floor plan rectangle standing.

    You can chop it up in any number of rectangles, just make sure that  the rows have equal height. They don't need to have equal width as long as they total width of all rows are the same (and have same number of columns in each rows)

    In Pixelmator pro I use the web slicing tool (export for web) that makes it easy to divide the picture into squares.

     

    Link to comment
    Share on other sites

    14 minutes ago, jgab said:

    The tiles can be  "any"  size as they are scaled down to the width given (600)

    I wouldn't make them  large as it just takes space. If the width is 600 and you have 3 columns, don't make them more than 200-250 each.

    I believe that you have more space vertically (haven't tested) so it can make sense to have the floor plan rectangle standing.

    You can chop it up in any number of rectangles, just make sure that  the rows have equal height. They don't need to have equal width as long as they total width of all rows are the same (and have same number of columns in each rows)

    In Pixelmator pro I use the web slicing tool (export for web) that makes it easy to divide the picture into squares.

     

    First i scaled down to X=3000

    Please login or register to see this attachment.

     

    The i created 10 tiles

     

    Please login or register to see this attachment.

    But not sure that you explained it this way.

    Each tile is close to 600x 

    Is there an easy way to type the slice size? instead of dragging the mouse trying to hit 600- 

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 10 hours ago, ChristianSogaard said:

    First i scaled down to X=3000

    Please login or register to see this attachment.

     

    The i created 10 tiles

     

    Please login or register to see this attachment.

    But not sure that you explained it this way.

    Each tile is close to 600x 

    Is there an easy way to type the slice size? instead of dragging the mouse trying to hit 600- 

     

     

    No, the total width of a row should be just over 600

    Make the image 1000 pixel wide.

    Slice it up in 4 columns. Each column can have different widths as long as the height is the same.

    The number of rows can be any.

    Because the width is  limited to ~600 in the web UI, I would tilt the floor plan so that you get a 

    standing rectangle of 4 rows and 2 columns.

     

    And then you create a layer onto where you do sensors  and make visible before exporting each layer.

    ...and give the layers some names like "base" and "1" etc...

     

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

    • 2 weeks later...

    Does anybody know how to get geolocation in QA?

    In scenes it's possible via api.get('/users') but it doesn't return geolocation in QA ...

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, petrkl12 said:

    Does anybody know how to get geolocation in QA?

    In scenes it's possible via api.get('/users') but it doesn't return geolocation in QA ...

    What do you mean? api.get('/users') returns the same value in scenes and QAs.

    Link to comment
    Share on other sites

    sorry, my mistake

    but still I don't have correct GPS - it shows some place in Poland where is Fibaro :)

    image.png.745bece6c4f658ab3b76d3507cf678ce.png

     

    I have 2 devices connected to admin account (user id 2) and location is possible to get only for user but not for seperate device - I don't understand Fibaro logic to have location for user but not for devices ...

    (geo location is allowed in both devices - Android phone and in iPad)

     

    QA code

    Please login or register to see this code.

     

    Edited by petrkl12
    Link to comment
    Share on other sites

  • Topic Author
  • Here is a small QA that can add a memory probe to installed QAs and report their memory usage. Max, min and total RAM as reported by  Lua's collectgarbage(...)

     

    "Install hook" ads a QA file to each QA with an extra QuickApp function to collect the values.

    It then polls the QAs every minute for the RAM usage.

    "Remove hook" removes the QA file from QAs.

    Note, QAs will restart when hooks are added/removed.

    Please login or register to see this code.

    Please login or register to see this attachment.

     

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

  • Topic Author
  • 1 hour ago, petrkl12 said:

    QA code

    Please login or register to see this code.

     

    Your tableDelFunc can be done with an option to json.encode (only in QAs)

    Please login or register to see this code.

     

    • Thanks 1
    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, jgab said:

    Here is a small QA that can add a memory probe to installed QAs and report their memory usage. Max, min and total RAM as reported by  Lua's collectgarbage(...)

     

    I guess one could also  estimate how much os.clock (cpu used) is a percent of os.time()  (time that have passed) to get a feeling for how much cpu each QA consumes.

    Link to comment
    Share on other sites

    3 hours ago, jgab said:

    Here is a small QA that can add a memory probe to installed QAs and report their memory usage. Max, min and total RAM as reported by  Lua's collectgarbage(...)

    Excellent idea! 

     

    Let's find out if this can detect some real world problems. I don't have any :D but I know a few power-users who will test your FQA

     

    I get this after a few minutes, and I don't think "Kitchen - zero kb"  makes sense so I'll have to dig into that... It is based on "refreshstates", which might already be a "red flag" as to why it is not working.

     

    Total 5243.05kb
    Max HomeAssistant:1873, 538.19kb
    Min Kitchen:1740, 0.00kb

     

    Thinking out loud... Maybe exclude the "0.00kb" from the min/max calculation and report them separately?

    • Like 1
    Link to comment
    Share on other sites

    28 minutes ago, jgab said:

     

    I guess one could also  estimate how much os.clock (cpu used) is a percent of os.time()  (time that have passed) to get a feeling for how much cpu each QA consumes.

    That's what I do in all my QuickApps, so I can easily monitor if a QA is consuming too much CPU or RAM.

     

    Information is displayed every 5 minutes in the logs :

     

    Please login or register to see this attachment.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 11 minutes ago, lazer said:

    That's what I do in all my QuickApps, so I can easily monitor if a QA is consuming too much CPU or RAM.

     

    Information is displayed every 5 minutes in the logs :

     

    Please login or register to see this attachment.

     

    The cpu %, is that over total running time or some interval?

    Edit: sorry, 5min  update interval?

    29 minutes ago, petergebruers said:

    Excellent idea! 

     

    Let's find out if this can detect some real world problems. I don't have any :D but I know a few power-users who will test your FQA

     

    I get this after a few minutes, and I don't think "Kitchen - zero kb"  makes sense so I'll have to dig into that... It is based on "refreshstates", which might already be a "red flag" as to why it is not working.

     

    Total 5243.05kb
    Max HomeAssistant:1873, 538.19kb
    Min Kitchen:1740, 0.00kb

     

    Thinking out loud... Maybe exclude the "0.00kb" from the min/max calculation and report them separately?

    Yes,  0.00kb is strange - unless you intercept onAction when the QAs try to call each other ? If you block the fibaro.call(id,"MEMORYWATCH",..) it  will never get any value reported back and thus report the initialisation value that is 0... 

    So, they should be initialised to -1 and filtered out if no response from them...

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

    @jgab

    Yes, 5 minutes update interval by default, although it is customizable.

     

    Function in my tools library (dedicated QA file) :

    Please login or register to see this code.

     

    Somewhere in QA's main loop, just call :

    Please login or register to see this code.

     

     

    Main goal is obviously to monitor system resources usage for every QuickApps.

     

    Second goal is to check if QA is still alive, and not crashed (old habit from HC2, where Virtual devices could crash without being automatically restarted)

    For example a QA which has nothing to display during hours in the logs, this messages appears every 5 minutes, so my own watchdog can detect if a particular QA has stopped displaying messages for more than 5 minutes (and then send notification message and force restart it)

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

  • Topic Author
  • Please login or register to see this image.

    /monthly_2022_02/1679920162_Screenshot2022-02-21at12_38_03.png.0711d98fa2f3a895dd48b7217d54f1e9.png" />

    Ok, this version monitors CPU usage too - thus the new name "Memory and CPU watcher"

    Sampling interval is selectable - 60s, 5min, 30min, 1hour, 24hours

    The cpu usage is in percent and is the os.clock() of the os.time() for the sample interval.

    os.clock measure the cpu used by the process and will not count time waiting for setTimeouts or hanging in net.HTTPClient():request(...) etc. ... so I believe it's a fair estimate.

    If your QA does a loop like

    Please login or register to see this code.

    it will report close to ~95%. We can't do a tight "while true do end" loop as it will  give no time for the QA to respond to the probe request.

     

    Please login or register to see this attachment.

     

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

    32 minutes ago, jgab said:

    Ok, this version monitors CPU usage too - thus the new name "Memory and CPU watcher"

    Excellent! Your FQA confirms that my system is "happily idling along":

     

    Total 5249.95kb
    Max mem 'HomeAssistant':1873, 538.66kb
    Min mem 'Hal-fqa-test':1752, 303.93kb
    Max cpu 'Uplighter':1781, 0.198%
    Min cpu 'mqtt':1762, 0.011%

     

    Mmmmmmmmmmm I should use more MQTT :)

    Link to comment
    Share on other sites

  • Topic Author
  • My big cpu hogger is childrenofhue that polls a Hue hub every second for info - around 5% cpu. I believe the new V2 API will be much better as it uses a model something similar as /refreshState... (will do some benchmarks this evening)

    My memory hog is EventRunner - that builds a lot of internal memory structures for the rules to execute efficiently ~1Mb. Working on a new ER engine I believe will cut down on the memory there too.

    Edited by jgab
    Link to comment
    Share on other sites

    Aha! i knew it. I need to reboot my doorbell ?

     

    1826.86kb - 'DOORBELL BUTTON':390 (cpu:0.199%)

    Link to comment
    Share on other sites

  • Topic Author
  • 1 minute ago, ppeterr said:

    Aha! i knew it. I need to reboot my doorbell ?

     

    1826.86kb - 'DOORBELL BUTTON':390 (cpu:0.199%)

    Yes, it seem like a lot of memory for a doorbell... ;-)

     

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

    1 hour ago, jgab said:

    My memory hog is EventRunner - that builds a lot of internal memory structures for the rules to execute efficiently ~1Mb. Working on a new ER engine I believe will cut down on the memory there too.

    I had a QuickApp used to monitor events that did polling of /api/events/history every minute, then display last events into labels.

    So huge LUA tables, the QA consumed up to 180 MB (yes megabytes) of memory, and quite a lot of CPU (for than 10%)

    The HC3 was out of free memory, it appeared that the QA was killed and not restarted. So the HC3 is quite resilient, kudos to Fibaro :)

     

    I then decided to rewrite the QA, and use /api/refreshStates instead.

    Now, the QA refresh instantly, consumed almost no CPU and RAM (around 1 MB as other traditional quickapps)

     

    • Like 2
    Link to comment
    Share on other sites

    Could it  be, that after removing the quickapp. There remain some parts

    of code in other quickapp on my system ?

     

    [26.02.2022] [17:47:00] [ERROR] [QUICKAPP225]: QuickApp crashed[26.02.2022] [17:47:00] [ERROR] [QUICKAPP225]: ./quickApp.lua:239: module 'include.MEMORYWATCH' not found:

     

     

    Maybe i forgot to remove the probes. Not sure. 

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