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

tips:

sample custom weather provider

notice: ONLY local data!

 

Please login or register to see this code.

 

 

Please login or register to see this image.

/monthly_2020_05/image.png.5f86b9ee36d940e9dd67c1aef1195463.png" />

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

2 godziny temu, jgab napisał:

Lua has a date function. os.date("*t").month is the number of the month so the below could work.

Please login or register to see this code.

Next version I will add a 'month' variable that can be used directly.

Thx a lot. Got only one problem...It seems that variable length is limited to 100 characters, any idea to work around this?

 

Edited by michal85pl
Link to comment
Share on other sites

  • Topic Author
  • 11 minutes ago, michal85pl said:

    Thx a lot. Got only one problem...It seems that variable length is limited to 100 characters, any idea to work around this?

     

    Right, I have also seen this issue with quickVars in another QA, didn’t realize it would be a problem here too. Let me think about it. Worst case the string has to be added to the code inside the QA.

    Link to comment
    Share on other sites

    3 minuty temu, jgab napisał:

    Right, I have also seen this issue with quickVars in another QA, didn’t realize it would be a problem here too. Let me think about it. Worst case the string has to be added to the code inside the QA.

    it wasn't a problem until now, until I decided to use the date condition, which takes 55 characters ... maybe the implementation of date support in QA code will shorten the need for the number of characters ...

    Link to comment
    Share on other sites

  • Topic Author
  • 49 minutes ago, 10der said:

     

    Please login or register to see this code.

     

     

    Just a style of coding. If I need to run a function every x minutes I have moved to using setInterval.

    Ex.

    Please login or register to see this code.

    It's short, keeps the function clean, and allows it to be called from other contexts. 

    If I need a timed loop that run on the second and never drifts then I have to use a compensating setTimeout loop.

    • Thanks 1
    Link to comment
    Share on other sites

    1 hour ago, 10der said:

    tips:

    sample custom weather provider

     

    Please login or register to see this code.

     

     

    the original weather conditions in QA are wrong, see my posting / fix here

     

     

     

    • Thanks 1
    Link to comment
    Share on other sites

  • Topic Author
  • 8 hours ago, michal85pl said:

    it wasn't a problem until now, until I decided to use the date condition, which takes 55 characters ... maybe the implementation of date support in QA code will shorten the need for the number of characters ...

     

    Ok, new version

    You can use 3 letter english shortnames for weekdays and months with .. test.

    Ex. wed..fri & may..jun

    Link to comment
    Share on other sites

    Guest Freddan67
    10 hours ago, jgab said:


    I loaned a hue white bulb from a friend and it  works flawless in my system. Really strange. Can you give me links to the exact product that misbehaves for you? Can’t sleep ?

    This one but I have tried other lamps also with the same result. Ikea, ledvance (OSRAM). I have reset HC3 to see if it was the one who made it but it became the same. Fibaro's built-in QA works fine otherwise :) but I do not get sensors there, etc.

    Please login or register to see this link.

    Link to comment
    Share on other sites

    3 godziny temu, jgab napisał:

     

    Ok, new version

    You can use 3 letter english shortnames for weekdays and months with .. test.

    Ex. wed..fri & may..jun

    Thank you very much, works without a problem :) as always :)

    Link to comment
    Share on other sites

    Guys!

    what is wrong?

     

    Please login or register to see this code.

     

    [06.05.2020] [21:21:01] [ERROR] [QUICKAPP1638]: QuickApp crashed
    [06.05.2020] [21:21:01] [ERROR] [QUICKAPP1638]: /usr/share/lua/5.3/json/util.lua:55: bad argument #1 to 'for iterator' (table expected, got number)

    Link to comment
    Share on other sites

  • Topic Author
  • Well,

    You were thinking right, fibaro.getGlobalVariable returns 2 arguments

    This works

    Please login or register to see this code.

    A single parenthesis around a multi-value return the first value

     

    Your attempt to using select is wrong, 'select', selects from the number value and the rest of the multi values select(1,3,4,5) == {3,4,5}

     

    If you want to complicate it you can do like below, create a table of the multi values and select the first index. However, the first alternative is the clean one.

    Please login or register to see this code.

     

    The other thing is of course why json.decode is so sensitive to extra arguments. Well second argument to json.decode is for parsing options...

    • Thanks 1
    Link to comment
    Share on other sites

    4 minutes ago, jgab said:

    jT = json.decode((fibaro.getGlobalVariable("HomeTable"))) -- YES! it does work

    Jan ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it doen;t work.

    proofs

    Please login or register to see this attachment.

     

    Link to comment
    Share on other sites

  • Topic Author
  • Well, that's an invisible character that got in (the <\194>) - happens sometimes when I cut and paste into the forum. Try to rewrite the first part.

    Link to comment
    Share on other sites

    btw. your SIM works properly

     

    Please login or register to see this attachment.

    1 minute ago, jgab said:

    Well, that's an invisible character that got in (the <\194>) - happens sometimes when I cut and paste into the forum. Try to rewrite the first part.

    OMG!

     

    Thanks!

     

    @afendikov

    Link to comment
    Share on other sites

    Gues!

    who playing with com.fibaro.hvacSystem

    please please please please

     

    yes a can crate child with hvacSystem but can't add properties for setPoint etc.

    also this device has 2 buttons bu default but idk what this buttons do

    Link to comment
    Share on other sites

  • Topic Author
  • 22 hours ago, 10der said:

    Gues!

    who playing with com.fibaro.hvacSystem

    please please please please

     

    yes a can crate child with hvacSystem but can't add properties for setPoint etc.

    also this device has 2 buttons bu default but idk what this buttons do

     

    Well, if you set it to 
    com.fibaro.setPointForwarder

    you get a little better UI...  The "Advanced" tab has settings for thermostat, time and zone.

    When the "Advanced" tab is selected 

    function MyHVAC:getManualTime() 

    function MyHVAC:getSetPointsList()

    function MyHVAC:getHeatingZonesList()

    is called to populate the pop-up selectors - however, I can't find a way to get them enabled. :-( 

    Link to comment
    Share on other sites

    Youhoeee hehe the first QA who is delivering some result!

    Thanks Jan!

    One remark should the rooms also being listed?

    All my lights are in one room.

    Remark in the HUE-app they are all spread all over the house.

    resp.

    living room

    kitchen

    living room

    Bath room

    Please login or register to see this attachment.

    Keep going with the good work!

    //Sjakie

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • There are previous post on how to call functions in other QAs and receive the result.

    To recap: fibaro.call allows us to call a function in another QA but it does not return a value so we need another method for that.

    There are 2 ways to do it.

    The first is to make the called QA return the value by calling back to the caller with a fibaro.call(callerID,"RPC_VALUE",<return value>)

    The problem with that is that it is quite slow due to the "cooperative" nature of the QA event loop... I can't make it quicker than a 5s roundtrip.

    Much quicker then is to return the result in a fibaro global. Now we are talking about millisecond.

     

    My new code looks like

    Please login or register to see this code.

    Because this remote call is synchronous we only need to create one global per QA (named "RPC_" + QA deviceID)

     

    The slight improvement over the older version is that we add a sequence number 'n' to the calls. The problem in the past was that
    if the call timed out , an old, unfinished call, could stuff something in the return variable when we do the next call. Now we check for that and ignore old unfinished calls.( If we are unlucky we get a timeout because the unfinished call overwrites our new value, but at least we won't get a wrong value...)

     

    The "raw" remote call looks like 

    Please login or register to see this code.

    We can add a timeout value that defaults to 3 second. Remote calls need the have timeouts as the called QA may crash and never return a value.

     

    It's easy to add sugar to the rpc call to define "regular" functions:

    Please login or register to see this code.

    If your QA only answers to remote function calls you only need to implement

    Please login or register to see this code.

    and the functions you "export" need to be global functions, like below because we find them in the global environment _G. You could define them in a table and change the call to get the function from that table instead of _G.

    Please login or register to see this code.

     

    Only making remote calls will unfortunately  requires some more code to be added:

    Please login or register to see this code.

     

    If Fibaro will change the fibaro.call to return values they need to do something similar under the surface. There need to be a place (associated to the QA) where the return value can be stored. And they need to decide if it's going to be synchronous value returns like in the above example or asynchronous - some kind of callback function that the caller provide.

    It is tempting to use a quickApp variable to return the value in but it's too slow to access from another QA - and quickApps are also implemented as a list we need to search through - not very efficient.

     

    Edited by jgab
    Link to comment
    Share on other sites

    make GlobalVariable great again!

    Jan. I do not think what GlobalVariable is good approach.  GlobalVariable is not reentrant (if you understading what I mean)

     

    UPD: 

    Please login or register to see this link.

    Edited by 10der
    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...