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
  • Creating QuickAppChild's have always bothered me as both the process of creating and re-loading children was needed, and then the mess with mapping types to QuickAppChild classes.

     

    There seems to be 2 use cases. 

    1. A QA with a fixed, pre-defined number of QuickAppChildren that needs to be created once and then re-loaded when the QA restarts.
    2. A QA that creates QuickAppChild devices dynamically, ex mapping to external Hue devices found on a Hue bridge. That QA then re-loads a "dynamic" number of QuickAppChild objects, so we can't list them upfront like in case 1.

     

    So, my new approach is the class 'QuickerAppChild' (case 1)

    Please login or register to see this code.

     

    The class constructor creates a child device if it doesn't exists, and maps to an existing device if it exist. No need for both creating a child device and call self:initChildDevices with a map to re-load them. The example above works well for a QA with a fixed number of upfront pre-defined children. First time the device will be created, next restart only the QuickerAppChild object is created and mapped to the existing device. If quickAppVariables are provided they are only used the first time when the device is created to initialise the device. When reloaded it will get the eventually modified quickVars. The code is minimal, no need to check if devices have been created, create or call self:initChildDevices.

     

    The trick is that we give each child a 'uid', a unique identifier. This allows the class constructor to know if the object already exists or we need to create a new.

     

    Child objects will be available in self.childDevices{}, that maps deviceId to child object.

    Child devices will also be available in self.uidMap{} that maps 'uid' to child object.

     

    The uid can be whatever, but if child devices represent external devices, like ex. Hue devices, it can be clever if the uid is the external device id. Because if an external device is found to have changed state, the corresponding QuickerAppChild object can be quickly found with self.uidMap[uid], to allow the object to update it's state.

     

    In the case there are a varying number of child devices there is a self:loadChildDevices() that loads/creates objects for all child devices, no need to bother with what class they should map to. (case 2)

    Please login or register to see this code.

     

    The QuickerAppChild class looks like this.

    Please login or register to see this code.

     

    the getClassName() is a nice hack :-). Needed to know the class of the object being created from the super class...

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

    • 1 month later...
  • Topic Author
  • New functions for QuickApps in FW5.082.15  (they may have been there earlier)

     

    Please login or register to see this code.

    Returns "armed", "partially_armed" or "disarmed" 

     

    Please login or register to see this code.

    Returns true or false of partition with id is breached

     

    Please login or register to see this code.

    Returns true or false depending if home is breached

     

    Please login or register to see this code.

    Returns a list of ids of breached partitions 

     

    Please login or register to see this code.

    Return "armed" or "disarmed" if partition id is armed

     

    Please login or register to see this code.

    Returns all partitions.

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

    2 hours ago, jgab said:

    New functions for QuickApps in FW5.082.15  (they may have been there earlier)

     

    Please login or register to see this code.

    Returns "armed" or "disarmed"

     

    and 'partially_armed'

     

    • Like 3
    Link to comment
    Share on other sites

    • 3 weeks later...
  • Topic Author
  • 1 hour ago, matnowys said:

    Hi everyone!

    I'm learning QA's and now I need to make simple QA with slider of dimmable light. Can anyone tell me how to do it?

    How do you talk to the light? Http? What brand? Good chance that  someone already done a QA…

    Link to comment
    Share on other sites

    12 godzin temu, jgab napisał:

    How do you talk to the light? Http? What brand? Good chance that  someone already done a QA…

    Z-Wave device. Dimmer 2 and 2 channels of RGBW2 (mono white LEDs). I want to make them in separate sliders.

    Link to comment
    Share on other sites

    • 2 weeks later...

    how to change some device properties?

     

    I have tried:

          fibaro.call(111,"updateProperty","enabled",true)
          fibaro.call(111,"updateProperty",{"enabled",true})
          fibaro.call(111,"updateProperty","enabled","true")
          fibaro.call(111,"updateProperty","enabled",1)

    but nothing works :(

     

    EDIT:

    OK - this works :)

          api.put("/devices/111",{enabled=true})

     

    Edited by petrkl12
    Link to comment
    Share on other sites

    30 minutes ago, petrkl12 said:

    how to change some device properties?

     

    I have tried:

          fibaro.call(111,"updateProperty","enabled",true)
          fibaro.call(111,"updateProperty",{"enabled",true})
          fibaro.call(111,"updateProperty","enabled","true")
          fibaro.call(111,"updateProperty","enabled",1)

    but nothing works :(

     

    EDIT:

    OK - this works :)

          api.put("/devices/111",{enabled=true})

     

     

    Edited by Neo Andersson
    Link to comment
    Share on other sites

    13 minutes ago, Neo Andersson said:
    13 minutes ago, Neo Andersson said:

    This works for me: 

    fibaro.call(542"updateProperty","value""true")

     

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 9 hours ago, petrkl12 said:

    OK - this works :)

          api.put("/devices/111",{enabled=true})

     

    Yes, because 'enabled' is not a 'property'. e.g. it's not under the .property.* key.

    :updateProperty only works on .property.* keys, like 'value'

    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    Yes, because 'enabled' is not a 'property'. e.g. it's not under the .property.* key.

    :updateProperty only works on .property.* keys, like 'value'

    OK. Thanks

    Link to comment
    Share on other sites

    W dniu 19.11.2021 o 08:15, matnowys napisał:

    Z-Wave device. Dimmer 2 and 2 channels of RGBW2 (mono white LEDs). I want to make them in separate sliders.

    Anybody could help?...

    Link to comment
    Share on other sites

    • 3 weeks later...
    On 7/8/2020 at 7:26 PM, tinman said:

    For all who need MD5 and/or Digest Auth on HC3, i made sample QA which implements following things:

    • Digest Access Authentication
    • MD5
    • example of send with button click
    • example of loop send
    • HTTP and HTTPS  

    You can find it on our

    Please login or register to see this link.

     

    This Quick App is btw. part of upcoming Dahua Doorstation QA, which i hope will support as well DHIP protocol, to e.g. allow triggering on call

     

    EDIT: 

    Please login or register to see this attachment.

    Hi tinman, thank you for developing this QA, and providing it as free. 

    The Hikvision NVR QA is using Basic authentication - i have a wish to have it changed to use the digest authentication 

     

    i filled in the Variables as well

    I changed the uri - but not sure if its right or compatible ... 

    function QuickApp:clickButton1()
        -- change to your target URI
    --    local uri = '/cgi-bin/whatsoever.cgi?action=DoSomethingOnClick'
        local uri = '/doc/page/login.asp'

     

    or is this where the magic should be done?

    Please login or register to see this attachment.

     

    Please login or register to see this attachment.

     

    working QA, but with Basic authentication and some dublets. 

    Please login or register to see this attachment.

    Please login or register to see this attachment.

     

    Link to comment
    Share on other sites

    13 hours ago, ChristianSogaard said:

    The Hikvision NVR QA is using Basic authentication - i have a wish to have it changed to use the digest authentication 

     

    actually @cashe reported digest auth qa issue with hikvision as well, and he tracked down the problem to MD5 code, which i can't trace without hikvision hardware.

    I know that in some really rare cases that MD5 implementation might not work on HC3L/Yubii due to overflow, but that's normally not the case on HC3.


    You might try to use different MD5 implementation, from the sha2lib qa, but that one is working only on HC3

     

    and change the code like 

     

    Please login or register to see this code.

     

    Btw, digest auth is still working for me with 5.092.19 and the various hardware on which i tested the code originally, just in case you ask.

     

    Regarding your "logon.asp" question, i don't think you can use it like that, the id will be generated by the browser or http call from qa. The "do soemthing" part of qa is executed after you already logged in, so not the place for logon.asp. 

     

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

    Hello guys, i'm trying to change my HC2/HCL system to HC3/HCL. In my knowledge there is no way for a master/slave combination with HC3 and HCL. So i think i can generate QA to control devices on HCL via API-calls. I read a lot of postings - but no idea to make a useful start. Have anyone an example for me?
    Thank you very much in advance. 

    Link to comment
    Share on other sites

    5 hours ago, Speedo67 said:

    Hello guys, i'm trying to change my HC2/HCL system to HC3/HCL. In my knowledge there is no way for a master/slave combination with HC3 and HCL. So i think i can generate QA to control devices on HCL via API-calls. I read a lot of postings - but no idea to make a useful start. Have anyone an example for me?
    Thank you very much in advance. 

    Please refer to  AOQ - 

    Please login or register to see this link.

     

    AOQ can control any other Fibaro system HC3, HC2, HCL, Yubii, HC3L (master/slave concept) 

    You can continue to use your HC2 as a save as well.

    Let me know if you need any help to configure the system.

     

     

     

    Edited by cag014
    Link to comment
    Share on other sites

    • 2 weeks later...

    @jgab

    do you know how to setup ZBS to be compatible with HC3L or Yubii?

    HC3 is 64 bit and HC3L or Yubii is 32 bit.

    ie. this return true in HC3 but false in HC3L or Yubii:

     

    Please login or register to see this code.

     

    Edited by petrkl12
    Link to comment
    Share on other sites

  • Topic Author
  • I don't think you can - easily.  

    You could compile up a 32bit integer Lua and try to make ZBS use it. There are some examples on using other interpreter/compiler with ZBS but I haven't really tried myself. You would probably also need a compatible mobdebug too - which could be a problem. 

    ...or just compile up a standalone 32bit Lua and verify against it on the side.

     

    Link to comment
    Share on other sites

    hmm, I expect something in ZBS menu :)

    it looks that sometimes QA will not work in HC3L or Yubii without visible reason :(

     

     

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