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

    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?

    Link to comment
    Share on other sites

  • 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

  • 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

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