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
  • 1 hour ago, cag014 said:

    I'm curious how do you use refreshState?

    Is  it always

    Please login or register to see this code.

    You know that you need to get next correct last number?

    Yes, I know... but we can't get that. Because I can't know I saw that  it didn't seem to store the events that long.... However, I pressed the same key quickly which did produce the same event - which I mistook for the code to work - which was a fault of mine. On the other hand, if you press the keys really slow this will produce the keys ;-) One can also pick the last CentralSceneEvent, and the reaction times are a bit quicker... Anyway, lets wait for the real sourcetrigger.

     

    Link to comment
    Share on other sites

    28 minutes ago, jgab said:

    Anyway, lets wait for the real sourcetrigger.

    Agree

    Link to comment
    Share on other sites

    7 hours ago, jgab said:

    sourceTrigger seems to be a variable in the next release - it's documented in the Lua scene docs for the HC3.

     

    that's right, and yes it will be there and it does works, e.g. here with Wallmote Quad

     

    Please login or register to see this spoiler.

     

     

    • Like 1
    Link to comment
    Share on other sites

    Guys,

    Any idea how to arm disarm specific sensor... I don't see any option in device settings.

    Even when defined the sensor in alarm zone and arm it. No indication.

    By breaching alarm also no indication at any place? You don't have any idea that alarm activated!

    Am I miss something?

    Edited by cag014
    Link to comment
    Share on other sites

  • Topic Author
  • Now there is rudimentary support for coding and developing scenes offline with fibaroapiHC3.lua. (and you got sourceTrigger before Fibaro releases sourceTrigger :-) )

     

     

     

    The conditions expression is declared in a Lua table named 'hc3_emulator.conditions'

    The actions should be inside a function called 'hc3_emulator.actions'

    Please login or register to see this code.

    The above scene triggers on device 32 having a value property that is true (e.g a sensor)

     

    A more complex example

    Please login or register to see this code.

    This scene triggers on a key fob with id 53, or a sensor with id 55, or every hour from 3hours after sunrise to sunset.

    To run and debug date/cron expressions can be very boring as it takes a long time.

    Therefore a 'speed' argument to hc3_emulator.start{speed=<hours to speed>}

    will speed through the time the number of hours given (or 48 hours if argument is 'true')

     

    Running

    Please login or register to see this code.

    Is a way to quickly speed through 20hours and check if you got that condition right to trigger on the hours you expected.

     

    I still don't support {type='date', property='cron', operator='match>'} e.g. a cron with any operator beyond 'match'

    Writing an "compiler" for conditions is really tricky when any interpretation of the semantics for cron comparisons are really strange...

    What does a "match>" for {"*", "4,10" ,"*", "*", "2,9", "*"} mean???

     

    The types of events above is what is currently supported, no matchInterval, no other types... will add as I start to use them myself.

    Edited by jgab
    Link to comment
    Share on other sites

    @jgab How to change value of slider from another QA?

    I have tried:  fibaro.call(idQA, "MySlider", "value", "90")

    but it doesn't work ...

    Link to comment
    Share on other sites

  • Topic Author
  • 15 minutes ago, petrkl12 said:

    @jgab How to change value of slider from another QA?

    I have tried:  fibaro.call(idQA, "MySlider", "value", "90")

    but it doesn't work ...

    First, the update of UI values are a bit buggy in this release.

    I have been unable to do

    Please login or register to see this code.

    I don't know if that is a bug or that :updateView is not accessible from other QDs.

     

    I use this. In the QD with the slider:

    Please login or register to see this code.

    and then from the QD that wants to change the value

    Please login or register to see this code.

    This is for code where the slider value reflects the value property of the QD.

    You could simple define

    Please login or register to see this code.

    and call it like

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    On 2/16/2020 at 1:40 PM, jgab said:

     

    Please login or register to see this code.

     

    this doesn't work ...

    Link to comment
    Share on other sites

  • Topic Author
  • 4 minutes ago, petrkl12 said:

    this doesn't work ...

    plugins  -> plugin 

    Link to comment
    Share on other sites

    Please login or register to see this code.

    interesting - 

    self:myUpdateView("sldBrightness", "value", "80") this works

    fibaro.call(plugin.mainDeviceId, "myUpdateView", "sldBrightness", "value", "10") -- this doesn't work, any change in slider

     

    in debug:

    [DEBUG] 21.02.2020 20:49:59: onInit

    [DEBUG] 21.02.2020 20:49:59: deviceID: 24

    [DEBUG] 21.02.2020 20:49:59: Setting value to sldBrightness value 80

    [DEBUG] 21.02.2020 20:50:04: Setting value to sldBrightness value 10

     

    Link to comment
    Share on other sites

  • Topic Author
  • 11 minutes ago, petrkl12 said:

    interesting - 

    self:myUpdateView("sldBrightness", "value", "80") this works

    fibaro.call(plugin.mainDeviceId, "myUpdateView", "sldBrightness", "value", "10") -- this doesn't work, any change in slider

     

    in debug:

    [DEBUG] 21.02.2020 20:49:59: onInit

    [DEBUG] 21.02.2020 20:49:59: deviceID: 24

    [DEBUG] 21.02.2020 20:49:59: Setting value to sldBrightness value 80

    [DEBUG] 21.02.2020 20:50:04: Setting value to sldBrightness value 10

    Yes, I get the same result. However, I believe that this may be fixed with the new fw

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, petrkl12 said:

    I hope so because it's a difficult to create something useful ...

    Ha, there is a bug with calling QuickApp methods and how they marshal arguments - Iv'e seen it before but I never investigated it deeply enough...

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Super!  We have workaround.

    I think that is also reason why fibaro.call doesn’t work for setting properties from another QA.

    @petergebruers could you please check if it was corrected in your beta version? Thanks

     

    btw Is there any option how to become betatester with my own HC3? 

    Link to comment
    Share on other sites

  • Topic Author
  • Here is an iCalendar QD. v0.11

    Please login or register to see this attachment.

      (new doc here 

    It's not strictly a tips & trick's but I'm awaiting a HC3 section for download - the next fw - and to find any bugs - before submitting to the general audience.

     

    I'm also not completely satisfied with the functionality yet...

     

    You configure it with a secret but public url to an icalendar (I tried with Google and iCloud and it works for me)

    Variables in code:

    CALURL=<url>
    CALNAME=<name>  -- ex. "Joe"

    Ex.
    Google  

    Please login or register to see this link.


     

    I had hoped to use the quickvaraibles panels to allow users to define the url without having to go into the code - of course they don't allow you to enter longer strings as values. (however, we can set longer strings with self:setVariable...)

     

    If successful the QD starts to read the calendar every 30min (can be changed) and schedules customEvents at the time of the event.

    The name of the customEvent depends on another variable 'CUSTOMEVENT'

    If CUSTOMEVENT=='title' then the customevent's name is just the title (spaces replaced with '_')

    if CUSTOMEVENT=='name' then the customevent's name is "iCalendar_"..CALNAME, ex. 'iCalendar_Joe'

    The userDescription of the event is always the full json encoded icalender entry.

    This is posted for all events in the calendar.

     

    Another trick. If the text of the event (description) contains lines with 

    Please login or register to see this code.

    and/or

    Please login or register to see this code.

    a customevent at start resp. end of the event will be posted with the name <eventA> resp. <eventB>

    Ex.

    A calendar entry with the text

    Please login or register to see this code.

    and if set to start at 20:00 and end at 05:00 will post customevent 'turnOnGarageLamp' at 20:00 and customevent 'turnOffGarageLamp' at 05:00

    You can use a block scene to trigger on these events and do the appropriate stuff - like turning on/off that lamp.

    Per default the QD will delete the events after 6s (to not littering the customevents panel list)

    There is a variable REMOVEDELAY that if set to nil will not remove the events after they have been emitted.

     

    The problem with blockscenes is that you can only use events that are defined, so you can pre-defined them and set REMOVEDELAY to false and it will not delete the events.

     

    If you update the calendar and want the QD to re-read the events immediately there is an UI button "Refresh calendar"

     

    Any bugs?

     

    P.S this was completely developed offline with the fibaroapiHC3.lua and ZeroBrane - and it worked almost directly when copy&pasted into the HC3. It's a real productivity boost to debug the code with a real debugger, set breakpoints and inspect variables etc..

    The only issue was that pesky setTimeout that can't schedule times too far away in the future.... need to replicate that limitation in the fibaroapiHC3.lua code :-) 

     

     

     

    Edited by jgab
    Of course I forgot debugging code that disabled refresh...
    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • So this is not for everyone... only for coders that think they would need loadstring...

     

    Here is a QD that "compiles" Lua. In practice it only parses Lua to a "parse tree"

    local parseTree = fibaro.call(<QD ID>,"parse",[[local s = 0 for k,v in pairs({a=4,b=3,c=2}) do s=s+v end return s]],<return var>)

    will parse the given Lua code and return a parse tree.

    Then we have a "compiler" that compiles that expression into a Lua function (more efficient than interpreting a parse tree). That compiler we need to have in the QD/scene calling our expression as we can't return functions from a fibaro.call...

     

    Anyway. Assume we install the "Lua compiler" QD with a ID of 27.

    Then we can do

    Please login or register to see this code.

     

    We do "loadstring" to load in the code that defines the function 'prettyJson' and then we can call it.

    Here we could ofcourse load the code string from a global variable or from some other place....

    Functions loaded this way have a penalty in efficiency. The prettyJson function above is ~10-15 times slower when loaded with loadstring...

    However, a call to prettyJson with a medium large table only takes milliseconds (loadstring version)

     

    The trick is the implementation of loadstring (that we put after QuickApp:onInit() )

    Please login or register to see this code.

    ...and after this we put the 'makeCompiler' functions.

     

    All is in the "loadstring client" QD included.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

     

    • Like 2
    Link to comment
    Share on other sites

  • Topic Author
  • Sharing devices between the HC2 and the HC3 (Updated Sept.4, 2020)

    Yet another hack.

     

    Here is a HC2 scene - You need to call it "HC3Proxy" and set the variables for IP, username, and pwd for you HC3 in the code.

    Also set "Max running instances" to 10.

     

    Please login or register to see this spoiler.

     

    Every time the scene triggers it will send the values to the corresponding QD proxy on the HC3...

    On the HC3 you install the HC2 Proxy QD 

    Please login or register to see this attachment.

    Inside the QD you set the credentials for the HC2

    You also need to edit the table

    Please login or register to see this code.

    The ID is an ID of a device on the HC2. 

    The name is the name of the HC3 Proxy QD that is going to be created. It will be called name.." (Hc2)"

    The proxyType is the type of device. Only 2 available at the moment. 'binarySwitch' and 'binarySensor'. They have a property of true/false

    The type is the QD type that is gong to be installed - should be a device type with a value property of true/false. 

     

    In my example, I have a switch (fibaro wall plug) and a motion sensor (fibaro eye) on the HC2 with IDs 17 and 44 resp.

     

    Then on the HC2 Proxy QD there is two buttons; Install and Remove.

    Install will install the proxies listed in the table.

    Remove will remove all proxies installed

     

    The 'binarySwitch'  will react to motions of the HC2 device and can be included in block scenes

    The HC2 Light will react to on/off and also have 2 buttons to turn on/off the light.

     

    It should be fairly straightforward to extend it with more device types. multiLevel switch and sensor is next...

     

    This is a way to have the devices shared between the HC3 and the HC2 

     

    Updated Sept.4, 2020

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

    @jgab

     

    this doesn't work in fibaroapiHC3.lua (directly in QA it's OK)

     
    fibaro.call(plugin.mainDeviceId, "myUpdateView", "label", "text", os.date("%d.%m.%Y %H:%M:%S"))
     
    Link to comment
    Share on other sites

  • Topic Author
  • 18 minutes ago, petrkl12 said:

    @jgab

    this doesn't work in fibaroapiHC3.lua (directly in QA it's OK)

    fibaro.call(plugin.mainDeviceId, "myUpdateView", "label", "text", os.date("%d.%m.%Y %H:%M:%S"))

    It's not fibaroapiHC3 , it's the HC3 marshalling of arguments.

    Turns out it doesn't like spaces in the string either-

    This works

    Please login or register to see this code.

    and 

    Please login or register to see this code.

     

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