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
  • Ooooh, we almost have metatables in QuickApps....?

    Please login or register to see this code.

    Please login or register to see this code.

    ....hmmmm, now just to figure out what to use it for....

     

    Maybe something like this?

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

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

    A wrapper for fibaro globals with marshalling, i.e. that makes automatic json encoding/decoding and also converts number and booleans.

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • On 7/12/2020 at 2:47 PM, petrkl12 said:

    Does anybody know how to add icon to centralSceneEvent to show icon in History panel (currently there is only "undefined")

     

    Please login or register to see this code.

     

    I thought the icon was fetched from the icon of the source, QAID in your case. What type is it?

    Link to comment
    Share on other sites

    type of QA is "com.fibaro.remoteController" and icon is setup via self:updateProperty("deviceIcon", iconID). Icon is correctly visible in device but not in history panel ...

     

    Please login or register to see this attachment.

     

    Please login or register to see this image.

    /monthly_2020_07/image.png.7eb249e83753f478dd189c67e5930b76.png" />

    Edited by petrkl12
    Link to comment
    Share on other sites

    7 hours ago, petrkl12 said:

    type of QA is "com.fibaro.remoteController" and icon is setup via self:updateProperty("deviceIcon", iconID). Icon is correctly visible in device but not in history panel ...

     

    Please login or register to see this attachment.

     

    Please login or register to see this link.

     

    Is it child devices?

    If yes, is it possible setup the scene via advanced tab?

    or how can you activate scene or do something when button pressed?

    Link to comment
    Share on other sites

    7 hours ago, rangee said:

     

    Is it child devices?

    If yes, is it possible setup the scene via advanced tab?

    or how can you activate scene or do something when button pressed?

    Is it child devices? No

    or how can you activate scene or do something when button pressed?

    there is more ways how to do it - for example here:

    Please login or register to see this image.

    /monthly_2020_07/image.png.d3371f42407cdb94a7893526f25a8b8f.png" />

    Edited by petrkl12
    Link to comment
    Share on other sites

    Hi, i used some code from this topic to make the SolarEdge code some smarter.

    There is just 1 problem that the Childs won't fire up, maybe one of you can find the problem ?

     

    Thanks in advance !

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 57 minutes ago, Hearts said:

    Hi, i used some code from this topic to make the SolarEdge code some smarter.

    There is just 1 problem that the Childs won't fire up, maybe one of you can find the problem ?

    Thanks in advance !

    Because you have 2 QuickApp:onInit() i your code and the last overwrite the first.

     

    Btw. you can remove the 'value' and 'unit' here as they are ignored by createChildDevice, add them to property instead.

    You can also add interfaces here - like 'energy' etc.

    Please login or register to see this code.

    Edited by jgab
    Link to comment
    Share on other sites

    A lot of thanks for you reply so fast! 

    LUA is al new for me, very difficult to understand at this moment. something with learning curve XD

     

     

    If I remove the last part 

    Please login or register to see this code.

    I will get the following and I can't find an solution :S

     

    Please login or register to see this code.

     

    Edited by Hearts
    Extra info
    Link to comment
    Share on other sites

  • Topic Author
  • With a new firmware comes new possibilities. 

    QuickApps can now consist of multiple files.

    We can easily copy one file from one QA to another. A file could be a "Library file" with nice to have code. Here is a function that copies a file from another QA.

    It can be called at startup to add the latest version of a library file. If the files are identical no copy is done - as I expect the QA will restart ad infinitum otherwise...

    Please login or register to see this code.

    You can't delete the "main" file and have to be a bit careful about colliding file names...

    • Like 3
    Link to comment
    Share on other sites

    I tried it :

     

    I copied your function in the QA in which I would like to use some function.

    I call the function in the onInit(),

     

    and I have "File doesn't exists"...

     

    I can set what I want for the "name" of the file ?

     

     

    Edited by jjacques68
    Link to comment
    Share on other sites

    oh sorry !

    it's ok !

     

    I just understand how it works...

     

    We must creat a file in the QA 'Library" for exemple.

    Create some functions...

    And call this QA with the filename created previously.

     

    now that's fine !

     

    Thank you very much !

    Link to comment
    Share on other sites

  • Topic Author
  • The latest firmware release, 5.040.37 is a boost. Now it's becoming quite nice to develop QuickApps :-)

     

    First I develop with Zerobrane studio and my HC3 emulator (fibaroapiHC3.lua).

     

    With that I can run (almost) any QA offline and debug. It has a web simulated QA GUI, or it can use an automatically deployed QA proxy on the HC3 to funnel QA button/slider presses back to the emulator. When I'm finished I can automatically deploy the finished QA to the HC3. There is a ZBS plugin that gives HC3 command completions and adds menu commands for ex. deploying to HC3.

     

    All my nice to have code I build as a Library: 'QA_Toolbox'. It is developed with the emulator.

     

    Two ways of using the Library:

    1. Include Library modules in QAs I'm building in ZBS. There is a emulator command "hc3_emulator.FILE("MyModule.lua","ModuleName") that just does a dofile when debugging but adds the file as a QA file when deploying
    2. Build a stand-alone "QA_Toolbox.fqa" and deploy to the HC3. It leverages the multi-file feature of the new QA structure to store each module of the Library. Then other QAs that need the Library check and copy them from the QA_Toolbox QA when they start/restart.

    Please login or register to see this code.

    The advantage with the latter is that existing QAs can be automatically restarted to load the latest version of the Library files. If I build my QAs with the Library files included it is easy to forget to update the Library files.

     

    My "Big project" EventRunner4 is now using this structure and it would be very difficult to manage without.

    Link to comment
    Share on other sites

    Guest kallecux

    Hi @jgab,

    can you give a hint how to arrange the files from github to use the new filestructure in QA?

    - EventRunner4.lua

    - EventRunner4Engine.lua

     

    Greetings.

    Link to comment
    Share on other sites

  • Topic Author
  • 9 minutes ago, kallecux said:

    Hi @jgab,

    can you give a hint how to arrange the files from github to use the new filestructure in QA?

    - EventRunner4.lua

    - EventRunner4Engine.lua

     

    Greetings.

     

    If you want to build EventRunner4 and debug yourself (You can also download the .fqa)

    You need:

    Working directory:

        fibaroapiHC3.lua

        EventRunner4.lua

        EventRunner4Engine.lua

    Subdirectory Toolbox:

        Toolbox_basic.lua

        Toolbox_events.lua

        Toolbox_triggers.lua

        Toolbox_rpc.lua

        Toolbox_files.lua

     

    ...and you run EventRunner4.lua. You will see in the source of EventRunner4.lua that it loads the modules.

    Beware that the flag deploy is set, unset it to run and debug.

     

    Edited by jgab
    Link to comment
    Share on other sites

    just to have it here, event logs / saveLogs for child devices

     

     

    • Thanks 1
    Link to comment
    Share on other sites

    On 5/1/2020 at 7:57 AM, jgab said:

    You could try this version

    Please login or register to see this attachment.

    - maybe it works better (at least it doesn't turn off the light icon when brightness is turned down to 0) - made some other small adjustments to 'Color light' too.

    I noticed that if I make a change in the Hue app it can take ~4s before the QA's state updates.

     

    No need to reinstall the lights - just copy paste code into the existing Hue QA.

    You are running the latest fw version for HC3 I assume?

     

     

    hello @jgab and thanks again for your contributions... keep learning thanks to you.

    i'm trying to use you QD but actually it doesn't work properly:

    * Lights are not updated of their real status (reachable, or not; color, birghtness...)

    * Off button doesn't work

     have you done any updates on this?

    Not having the real status of lights is of course the biggest issue.

     

    another quick question, is there an existing recommendation when having 2 hue bridges to optimize usage?

    thanks 

    br

    mde

     

     

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 5 hours ago, Mateo said:

    hello @jgab and thanks again for your contributions... keep learning thanks to you.

    i'm trying to use you QD but actually it doesn't work properly:

    * Lights are not updated of their real status (reachable, or not; color, birghtness...)

    * Off button doesn't work

     have you done any updates on this?

    Not having the real status of lights is of course the biggest issue.

    another quick question, is there an existing recommendation when having 2 hue bridges to optimize usage?

    thanks 

    br

    mde

     

    Hi, what kind of lights do you have? (If you click on the 'List' button in the main QA)

    I only have "Extended color light" and "Dimmable light" (Phillips) and they work for me.

    Can you try this version? 

    Please login or register to see this attachment.

     

    If you have 2 bridges you need to run two QAs. I could probably make a single QA support multiple bridges but I don't think there would be a lot of difference in resource usage. in fact, I think that dividing it up in one per bridge probably makes the QAs a bit more responsive as QAs execute in parallell.

    Link to comment
    Share on other sites

    Good morning @jgab,

    How to create a HomeTable in ER3?

    Or is it only HT at the beginning of each QA?

    Thanks in advance,

    //Sjakie

    Link to comment
    Share on other sites

  • Topic Author
  • 24 minutes ago, Sjakie said:

    Good morning @jgab,

    How to create a HomeTable in ER3?

    Or is it only HT at the beginning of each QA?

    Thanks in advance,

    //Sjakie

    You can do a scene that creates the table and store it in a fibaro global variable.

    Then you can retrieve that variable from other scenes and QAs

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