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

    @jgab

    I want to setup set credentials in fibaroapiHC3 but it doesn't work. Could you try it? or paste working example how to add credentials to fibaroapiHC3 ?

    Thanks

    You need v 0.62

     

    The way I would do it is to create a file, credentials.lua and add

    Please login or register to see this code.

    and then at the top of the scene/QA do

    Please login or register to see this code.

    Alternatively, without a credentials file (but it's a really good place to store credentials to other systems too)

    Please login or register to see this code.

     

    at the bottom you need to start with

    Please login or register to see this code.

    Does that work for you?

    Link to comment
    Share on other sites

    @jgab

    in newest version there doesn't work getVariable - result is nil

    Please login or register to see this code.

    In previous versions it was OK

    Link to comment
    Share on other sites

  • Topic Author
  • 9 minutes ago, petrkl12 said:

    @jgab

    in newest version there doesn't work getVariable - result is nil

    Please login or register to see this code.

    In previous versions it was OK

    Eh, it works for me...(!)

    Are you are running against a proxy? I tried both with and without and get the expected result.

    How does your 'hc3_emulator.start{...}' look like?

    Edited by jgab
    Link to comment
    Share on other sites

    my start ...

     

    if dofile then
      hc3_emulator.start{
        id=32,
        poll = 1000}
    end

     

    Link to comment
    Share on other sites

  • Topic Author
  • You want it to fetch the value from the HC3?

    The new default is that it will only fetch the value from the HC3 if it has a "proxy" on the HC3. 

    E.g.

    Please login or register to see this code.

    but then you don't get to chose the id (because it is generated when the proxy is created).

    And in your case you already have a QA on the HC3 with id 32 that you would like to fetch the variable from?

    So, you have to trick the emulator to believe that there is a proxy even though it hasn't created one..

    Have the same start as you had before, so no proxy is created, but when you enter QuickApp:init() set plugin.isProxy=true

    that will fool the emulator thinking there is a proxy with id 32 on the HC3 and call it.

    Let me know if it works.

     

    Note. the code looks like

    Please login or register to see this code.

    so if plugin.isProxy is set to true it will fetch the value from the HC3 otherwise the local _quickVars table.

    Edited by jgab
    Link to comment
    Share on other sites

    4 minutes ago, jgab said:

    You want it to fetch the value from the HC3?

     

    Yes

    4 minutes ago, jgab said:

    And in your case you already have a QA on the HC3 with id 32 that you would like to fetch the variable from?

    Yes

    7 minutes ago, jgab said:

     

    Have the same start as you had before, so no proxy is created, but when you enter QuickApp:init() set plugin.isProxy=true

     

    It works. Thanks

    I think it could be perfect to add possibility to start it without adding line to Init().

     

    Link to comment
    Share on other sites

  • Topic Author
  • 11 minutes ago, petrkl12 said:

    Yes

    Yes

    It works. Thanks

    I think it could be perfect to add possibility to start it without adding line to Init().

     

    Ok, next version will have an option to start{...}

    Link to comment
    Share on other sites

    3 minutes ago, jgab said:

    Ok, next version will have an option to start{...}

    Thanks

    Link to comment
    Share on other sites

    On 3/2/2020 at 9:08 AM, AutoFrank said:

     

    From Krikroff

     

    Please login or register to see this code.

     

     

    I use this little trick also in the case of a device with a fixed value of type power, to temporarily replace the value:

     

    Please login or register to see this code.

     

    And play with: 

     

    Please login or register to see this code.

    ;)

    Edited by Krikroff
    • Like 3
    Link to comment
    Share on other sites

    Hi jgap

    Home center 3, 1 person waiting for your er4

    When can I use it?

    From your fans

    Link to comment
    Share on other sites

  • Topic Author
  • 6 minutes ago, minsad79 said:

    Hi jgap

    Home center 3, 1 person waiting for your er4

    When can I use it?

    From your fans

    Can you run the ER4 quick app linked i this post? If not what error messages do you get?

     

    Link to comment
    Share on other sites

    If you execute the er3 rule of Home Center 2

    The following error

    [DEBUG] 2020-03-08 04:12:31 pm: [ERROR] in 'Rule: 1 [459: breached => 494: on]': {"msg": "Error executing instruction: '["% prop ", 1," breached "] '", "ERR": true, "src": "Rule: 1 [459: breached => 494: on]", "err": "./ quickApp.lua: 1888: attempt to compare string with boolean "}

     

     
     rule(" 459:breached => 494:on ")
     
     rule(" trueFor(00:01,459:safe) => 494:off")

    If you apply the rules used in Home Center 2

    Error in er4 quick app

    Link to comment
    Share on other sites

  • Topic Author
  • 4 minutes ago, minsad79 said:

    If you execute the er3 rule of Home Center 2

    The following error

    [DEBUG] 2020-03-08 04:12:31 pm: [ERROR] in 'Rule: 1 [459: breached => 494: on]': {"msg": "Error executing instruction: '["% prop ", 1," breached "] '", "ERR": true, "src": "Rule: 1 [459: breached => 494: on]", "err": "./ quickApp.lua: 1888: attempt to compare string with boolean "}

     

     
     rule(" 459:breached => 494:on ")
     
     rule(" trueFor(00:01,459:safe) => 494:off")

    If you apply the rules used in Home Center 2

    Error in er4 quick app

    Thanks, will fix...

    Link to comment
    Share on other sites

  • Topic Author
  • 16 hours ago, petrkl12 said:

    Thanks

    New version v0.64. New start option 'quickApp'. Connects to existing quickApp on HC3 with given id.

    Please login or register to see this code.

    Link to comment
    Share on other sites

    Is anyone has knowledge how to press button inside QuickApp (beside using API, which takes 5 seconds)?

    Edited by cag014
    Link to comment
    Share on other sites

  • Topic Author
  • 5 minutes ago, cag014 said:

    Is anyone has knowledge how to press button inside QuickApp (beside using API, which takes 5 seconds)?

    Do you have code inside the button so you need to actually activate the button?

    If you have moved the the code into "function QuickApp:buttonClicked()" you can call it with self within the QuickApp and fibaro.call(id,'buttonClicked') from another QuickApp... 

    Did I understand you?

    Link to comment
    Share on other sites

    33 minutes ago, jgab said:

    Do you have code inside the button so you need to actually activate the button?

    If you have moved the the code into "function QuickApp:buttonClicked()" you can call it with self within the QuickApp and fibaro.call(id,'buttonClicked') from another QuickApp... 

    Did I understand you?

    Yes, I have global definitions for many tables that I don't wont to keep inside QuickApp. (too many lines to scroll)

     

    Edited by cag014
    Link to comment
    Share on other sites

  • Topic Author
  • 7 minutes ago, cag014 said:

    Yes, I have global definitions for many tables that I don't wont to keep in side QuickApp. In addition have found very interesting advantage by keeping definitions there. I can change global variables, press the button and "main" QuickApp starts to use it on the fly.

     

    Yes, I have though about storing functions in them too... (You can update the uiCallbacks table of the device).

    It's a bit inefficient though for large code blocks as they probably do a loadstring() each time the button is pressed.

    Do you need to hide the buttons or is the switching of tables part of the user interaction?

    Link to comment
    Share on other sites

    7 minutes ago, jgab said:

    Yes, I have though about storing functions in them too... (You can update the uiCallbacks table of the device).

    It's a bit inefficient though for large code blocks as they probably do a loadstring() each time the button is pressed.

    Do you need to hide the buttons or is the switching of tables part of the user interaction?

    Is it part of user interaction... the idea that when user needs to configure variables, he can open the button code and change it without going through entire QuickApp code.

    The API call works fine, but it takes 5 seconds per button..!! Interesting by using same API in scene, it works very fast.

    Edited by cag014
    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...