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
  • On 1/16/2021 at 8:24 AM, Sjakie said:

    Jan,

    Overview HC3:

    6 QA with 160, 186, 267,4, 106, 240 rules

    35 HUE light bulbs

    Children for HUE

    Open Weather with API calls

    HC2 only heating all other scenes on manual.

     

    Yesterday evening No physical light in bath room according debug fibaro.call light on.

    I joined the last two QA's, check for errors in debug (only one humidity calculation need to  be solved later) and did a restart to start fresh.

    Night, no action of night protocol in the morning also no action and I performed  a restart.

     

    Because previous you mentioned HUE but I am with 35 pieces far below their 50 bulbs.

    During migration HC3 was running without big isues other I shoild stop continuing migration.

    Any tip or hint what to check or what to do?

    Option back to HC2 and scratch HC3?

    Your opinion is very much appriciated,

    //Sjakie

    It's very difficult to say why your HC3 has these problems. 

    6 QAs 800+ rules is a huge installation but ER is clever to only invoke relevant rules on incoming triggers so it usually scales very well. 

     

    The Hue with 35 lights seems not to be overly demanding either. The CoH polls all lights in each loop. It seems though from some of your other posts that the Hue Hub declines requests. sometimes. It could be the network, the hub itself. Difficult to say.

     

    In any case, your installation is quite large and it can be HC3 issues like coping with huge amount of debug messages. http requests that fails, or other things. Once again, difficult to say,

     

    I will implement some statistics in ER4 to get how many triggers and rules that have run. That could give some hint on the traffic in your system...

     

    You could try to add this to your main() ER QAs (the one you suspect generating a lot of load / having a lot of rules)

    Please login or register to see this code.

    Then we can get a feeling how "loaded" the ER rule system becomes in the QA.

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • On 1/15/2021 at 11:11 PM, petrkl12 said:

     

    a bit modified @jgab QA:

    - now it's a motion sensor

    - added parameter devicesDW for windows and doors because I want to have different behaviour: generate motion only during opening/closing of windows/doors (for default value: n/a)

     

    Please login or register to see this attachment.

     

     

    If many devices of this type is needed it could make sense to do a master QA that creates child devices of selected types.

    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • Sometimes it can be annoying with the debug statements "onAction: ..." when your QA is called. Especially if you log the calls in another way anyway.

    This is a simple hack that I use in my Toolbox to optionally silent those debug statements

    Please login or register to see this code.

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

    7 hours ago, jgab said:

    Sometimes it can be annoying with the debug statements "onAction: ..." when your QA is called. Especially if you log the calls in another way anyway.

    This is a simple hack that I use in my Toolbox to optionally silent those debug statements

    Please login or register to see this code.

    Does it work also in History panel?

    Edited by petrkl12
    Link to comment
    Share on other sites

  • Topic Author
  • Another tip from my

    Please login or register to see this link.

    is to redefine the log functions for the QA

    QuickApp:debug(...)

    QuickApp:trace(...)

    QuickApp:warning(...)

    QuickApp:error(...)

     

    First we would like that strings with space or newline where honoured. The log console usually strip multiple spaces and newlines.

     

    Secondly, we can add nice to have tags.

    self:debug("#T:myTag#This is a log statement with tag myTag")

    self:debug("#C:red#This is a log statement in red color") -- cloud also use html b

     

    Lastly, it is very common that we use string.format before logging, and we can combine that with 'f' version of the log functions

    QuickApp:debugf(fmt,...)

    QuickApp:tracef(fmt,...)

    QuickApp:warningf(fmt,...)

    QuickApp:errorf(fmt,...)

    Ex. 

    Please login or register to see this code.

     

    It's easy to extend with additional tags or features , like log-levels.

    Please login or register to see this code.

     

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

    Jan,

    I have this error:

    [21.01.2021] [08:41:05] [DEBUG] [QUICKAPP796]: [{"type":"File_update"}]>>'Rule:3[#File_update{} => Util.updateFile(env.event.file)]'
    [21.01.2021] [08:41:05] [ERROR] [QUICKAPP796]: QuickApp crashed
    [21.01.2021] [08:41:05] [ERROR] [QUICKAPP796]: EventRunner.lua:719: attempt to call a nil value (method 'getFiles')

     

    line 719 is green as its a part of --[[     ---]]

    Please advice,

    //Sjakie

     

     

     

    Link to comment
    Share on other sites

    How to fill the deviceIcon of a "com.fibaro.hvacSystem" QA?

    Please login or register to see this spoiler.

    When I created the QA the circle had a temperature value in it. Later it disappeared.

    I have tried self:updateProperty("heatingThermostatSetpoint","self.Setpoint") and self:updateProperty("heatingThermostatSetpoint","

    self.Setpoint) but no change.

    Link to comment
    Share on other sites

    Wake On Lan (WOL) for HC3

     

    Please login or register to see this code.

     

    Edited by petrkl12
    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, petrkl12 said:

    Wake On Lan (WOL) for HC3

     

    Please login or register to see this code.

     

    Please login or register to see this code.

    ..and there is the string.rep to create repetition of strings...

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

    • 2 weeks later...

    How to convert this format to standard lua date and time?

    "2018-06-15T10:00:11+02:00"

     

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, petrkl12 said:

    How to convert this format to standard lua date and time?

    "2018-06-15T10:00:11+02:00"

     

    Is it the only format? I been parsing iCAL data and the timezone time format can vary a bit. Here it seems like it's just a simple time offset.?

    To parse the above

    Please login or register to see this code.

     

    Maybe it worth porting Luadate to run on HC3....?

    ...which brings me to another issue. Because Fibaro decided to not allow metatables in Lua it's a real pain to port many external libraries to the HC3/HC2 - That's really sad as we now we have 'files' in QAs it's actually useful to bring some of these libraries to the HC3

    • Like 2
    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    Is it the only format? I been parsing iCAL data and the timezone time format can vary a bit. Here it seems like it's just a simple time offset.?

    I have only 1 item from 1 device. In device there is showing: Energy measured since 2018-06-15 09:00:11

    Link to comment
    Share on other sites

    I guess It looks like offset from London time +02:00 during saving in 2018

    because currently I have time offset +1 hour in my region and result is 09:00:11

     

    Edited by petrkl12
    Link to comment
    Share on other sites

    • 4 weeks later...

    Hello, I have 3 questions.

    1. Do you know where I can a list of the different devices "interfaces" we can use and can be used in QA .
      (tamper, energy, power...)
    2. Is it possible to create / add some custom properties other than the standard one (value)
      -> it is possible to set and retrieve those custom properties in scene and other QA.
    3. Finally, for the "selMode" UI, is it possible to set the current selected value (base on a status)
      E.G. during the creation:
              {select="selMode"text="Select",weight="6",
                options={
                  {value="1",text="Option 1"},
                  {value="2",text="Option 2"}
                },
                values={"1"},
       This will set the default option to "Option 1" during init, but I would like to be able to set the value "2" based on some QA status and display the current status when I open the QA. UpdateView call does seem to work in that case (or I didn't find the correct sintax...

    Thanks

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, chelson said:

    Hello, I have 3 questions.

    1. Do you know where I can a list of the different devices "interfaces" we can use and can be used in QA .
      (tamper, energy, power...)

    No, there is no list. We have discovered some like energy etc.

    There is api.get("/additionalInterfaces?deviceId=125") that list what additional interfaces device 125 can have.

     

    Quote
    1. Is it possible to create / add some custom properties other than the standard one (value)
      -> it is possible to set and retrieve those custom properties in scene and other QA.

    No. People resort to creative use of existing properties. Each type of device seems to be defined by an XML schema defining what properties are allowed.

    Quote
    1. Finally, for the "selMode" UI, is it possible to set the current selected value (base on a status)
      E.G. during the creation:
              {select="selMode"text="Select",weight="6",
                options={
                  {value="1",text="Option 1"},
                  {value="2",text="Option 2"}
                },
                values={"1"},
       This will set the default option to "Option 1" during init, but I would like to be able to set the value "2" based on some QA status and display the current status when I open the QA. UpdateView call does seem to work in that case (or I didn't find the correct sintax...

    All these pop-up selections seems to be a bit buggy. It's a hit and miss to use them. I. have nit managed to set defaults in the ones I used.

    Also if you re-save the QA in the UI it is destroyed. 

     

    Quote

    Thanks

     

    Link to comment
    Share on other sites

    each interface might have (at least) 3 following definitions: properties, actions and events (and if there are values defined, they can be used to catch events, run actions read/write properties)

     

    Example the voip interface type definition:

    Please login or register to see this code.

     

     

    Device itself can belongs to specific type, which defines as well things (e.g. this is how type com.fibaro.alphatechFarfisa.xml has been defined)

     

    Please login or register to see this code.

     

    As one can see, device type might have interface already pre-defined, which will then add the voip things into what device with type com.fibaro.alphatechFarfisa can (or got predefined).

    As device can have only one type, interfaces are used to add extras.

     

    Since one can't add/change values in the pre-defined xml files, we can only make use of additional interfaces (to get extra things we might use for our own idea) or sometimes use different device type, which has extras we normally don't have in predefined QA types, e.g. com.fibaro.sonosSpeaker introduce extras, additionally to what it's base type com.fibaro.player has:

     

    Please login or register to see this code.

     

    On HC3, the file system and firmware updates are signed and encrypted, so one can't unpack updates nor dump anything to get the interface/types definitions. However, all described things above exists since HC2 v3.901 i think, so one could easily download v4.600, unzip, and take a look on them - to get a feeling how they "might" looks like on HC3 - but i have to warn you, there are differences. 

     

    On HC3,due to different BUI design as on HC2, there are some BUI types/interfaces as well. In principle they do the BUI mapping based on device type and interfaces (which is why when adding some interfaces, the BUI looks different), good to know that they are there (and e.g. block scene make use ot them as well), but they not really important for QA, at least not anymore since latest beta (i mean due to blockscenes related things).

     

    Some interface types are not useful (and might create problems, because having them set, the HC3 firmware might think or try to do things, which the devices does not support), when they used in QAs. I would say generally don't add any of the following zwave interfaces in QA:

     

    Please login or register to see this code.

     

    these below are less dangerous, i made some tests in my QAs and didn't got any problems:

     

    Please login or register to see this code.

     

     

    Let's sumerize: generally one can't add any property nor action, but one can get extras (properties/events/actions) by using different device type, or by adding extra interface type.

     

    Anyway, i made some effort to get the information about available interfaces and device types on HC3 (firmware 5.062.30), see attached (remember, these might change at any time)

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

     

     

    UPDATE: 15.07.2021

     

    today FIBARO released 5.72.14 beta, so attached updated interfaces and types.

    Major changes:

    - all thermostate types have min and max values changed to max values -2147483648.0 to 2147483648.0 (not anymore these 4-28°)

    - new interface: parameters
    - new interface: virtualEnergyConsumption
    - new interface: calibratable
    - new interface: shutterWithAdjustableSpeed

    - com.fibaro.husqvarnaMower type
    - com.fibaro.pko type (polish insurance agency)
    - com.fibaro.dahuaCamera type
    - com.fibaro.yrWeather got new extra property "yrSymbolCode"
    - levelChange got removed from some types
     

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

     

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

    Just interesting test of Child devices:

    you can try to add interface "quickApp" during creating of child devices - than you can add labels and buttons to child devices. {'quickAppChild','quickApp','energy','power'}

    Labels are working from parent device OK:

    Please login or register to see this code.

    problem is with buttons :( (id 820 is parent device, id 821 is child device, button1 is in child device id 821)

    Please login or register to see this code.

     

    Maybe someone could come with idea how to solve it ...

    Edited by petrkl12
    • Like 2
    Link to comment
    Share on other sites

    buttons in child devices solved via this hack:

     

    in parent device you have to create button with same name as in child device (it can be hidden)

    and than press button in child device will be send to parent function with same name and in value there is device id from child ({"deviceId":821,"elementName":"button1","eventType":"onReleased","values":["function"]})

     

    Please login or register to see this code.

     

    Edited by petrkl12
    Link to comment
    Share on other sites

  • Topic Author
  • 36 minutes ago, petrkl12 said:

    Just interesting test of Child devices:

    you can try to add interface "quickApp" during creating of child devices - than you can add labels and buttons to child devices. {'quickAppChild','quickApp','energy','power'}

    Labels are working from parent device OK:

    Please login or register to see this code.

    problem is with buttons :( (id 820 is parent device, id 821 is child device, button1 is in child device id 821)

    Please login or register to see this code.

     

    Maybe someone could come with idea how to solve it ...

    Nice discovery.

     

    Have a look in my toolbox and the child device. There I make a UIEvent handler that forward the events to the children. For some reason it's lacking in the default implementation...

    3 minutes ago, jgab said:

    Nice discovery.

     

    Have a look in my toolbox and the child device. There I make a UIEvent handler that forward the events to the children. For some reason it's lacking in the default implementation...

    You define a UIEvent handler where you can implement your logic to find the child. The example below is pretty involved and can be simplified,

    Please login or register to see this code.

     

    Edited by jgab
    • Like 1
    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...