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

W dniu 12.09.2020 o 12:49, jgab napisał:

Here is a version of HC2Proxy that supports rollerShutter better - the buttons on the childDevice sends the right commands back to the HC2 device.

v.1.10

Please login or register to see this attachment.

 

I have the same problem again, it looks like a problem with the authorization of HCL to HC3, even though I did not change anything, HCL stopped sending triggers to HC3 ...
from the hc3 level I can switch the device status in HCL ... but HCL does not send messages to HC3 ...
After restarting the QA, the HC3 obviously reads the states of the devices in the HCL
Any ideas to solve the problem?

Link to comment
Share on other sites

6 hours ago, Rover said:

You are right (as always):

 
   
id 88
name "OverloopSwitch (HC2)"
roomID 219
view []
type "com.fibaro.remoteSceneController"
baseType "com.fibaro.remoteController"
enabled true
visible true
isPlugin true
parentId 73
viewXml false
configXml false
interfaces  
0 "quickAppChild"
1 "zwaveSceneActivationEvent"
properties  
availableScenes []
categories  
0 "remotes"
dead false
deadReason ""
deviceControlType 0
deviceIcon 103
emailNotificationID 0
emailNotificationType 0
log ""
logTemp ""
manufacturer ""
model ""
pushNotificationID 0
pushNotificationType 0
quickAppVariables  
0  
name "className"
value "sceneActivationDevice"
1  
name "id"
value 306
2  
name "HC2PROXY"
value "306:com.fibaro.remoteSceneController"
saveLogs true
smsNotificationID 0
smsNotificationType 0
useEmbeddedView true
userDescription ""
actions {}
created 1600082539
modified 1600082539
sortOrder 55

But this device does not react in a HC3 test scene, neither do I see a trigger in HC2 when pushing button 1 of the remote controller1x or 2x.

Please login or register to see this spoiler.

 

Link to comment
Share on other sites

On 9/13/2020 at 5:36 PM, Rover said:
On 9/13/2020 at 4:43 PM, jgab said:

I meant in the header of the HC2  scene

Please login or register to see this code.

 

Hoeray! That works!

I had used 263 value.

TNX jgab ?

It does not work anymore...

Please login or register to see this spoiler.

 

Link to comment
Share on other sites

  • Topic Author
  • 12 hours ago, michal85pl said:

    I have the same problem again, it looks like a problem with the authorization of HCL to HC3, even though I did not change anything, HCL stopped sending triggers to HC3 ...
    from the hc3 level I can switch the device status in HCL ... but HCL does not send messages to HC3 ...
    After restarting the QA, the HC3 obviously reads the states of the devices in the HCL
    Any ideas to solve the problem?

    Can you see the console/log on the HCL? 

    It logs "Updating ..." when it tries to send a message to the HC3 and it logs the error if the http request failed.

    12 hours ago, Rover said:

    But this device does not react in a HC3 test scene, neither do I see a trigger in HC2 when pushing button 1 of the remote controller1x or 2x.

    Please login or register to see this spoiler.

     

    How does your scene header look like on the HC2? That you don't get a trigger indicates that there is something wrong with that, or?

    Link to comment
    Share on other sites

    12 minutes ago, jgab said:

    How does your scene header look like on the HC2? That you don't get a trigger indicates that there is something wrong with that, or?

    Please login or register to see this spoiler.

    Obviously is CentralSceneEvent not correct, but what should it be for a ZWAVE.ME WALLC-S ?

    Link to comment
    Share on other sites

  • Topic Author
  • 40 minutes ago, Rover said:

    Please login or register to see this spoiler.

    --[[

    %% properties

    306 sceneActivation

    --]]

    Link to comment
    Share on other sites

    14 minutes ago, jgab said:

    --[[

    %% properties

    306 sceneActivation

    --]]

    Test scene works now, TNX!

     

    Now the issue that 263 CentralSceneEvent device did work, but not anymore in this version 1.10. No trigger in HC2 either.

    Link to comment
    Share on other sites

    12 godzin temu, jgab napisał:

    Can you see the console/log on the HCL? 

    It logs "Updating ..." when it tries to send a message to the HC3 and it logs the error if the http request failed.

     

    How does your scene header look like on the HC2? That you don't get a trigger indicates that there is something wrong with that, or?

    I think I found the cause of the problem. Most likely, HCL cannot get to HC3 if https access is set in HC3, it only works for http. Can You verify this in Yours environment?

    Link to comment
    Share on other sites

    On 9/15/2020 at 9:41 PM, michal85pl said:

    I think I found the cause of the problem. Most likely, HCL cannot get to HC3 if https access is set in HC3, it only works for http. Can You verify this in Yours environment?

    For secure access to the HC3 do not use its IP but use the gateway’s serial number. like.

    Please login or register to see this link.

     

     

    For example: 

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • On 9/15/2020 at 9:41 PM, michal85pl said:

    I think I found the cause of the problem. Most likely, HCL cannot get to HC3 if https access is set in HC3, it only works for http. Can You verify this in Yours environment?

     

    You could try to change the http.request call in the HC2 scene script to use https and see if it works.

    Please login or register to see this code.

     

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

    On 9/15/2020 at 9:57 AM, Rover said:

    Now the issue that 263 CentralSceneEvent device did work, but not anymore in this version 1.10. No trigger in HC2 either.

    Please login or register to see this spoiler.

    So i exchanged also Released with Pressed2.

    What could be the problem?

     

    Link to comment
    Share on other sites

    15 hours ago, jgab said:

     

    You could try to change the http.request call in the HC2 scene script to use https and see if it works.

     

    Please login or register to see this code.

    Question, shouldn't the data be outside the header for a PUT command?

     

     

    Edited by NLWaard
    Link to comment
    Share on other sites

  • Topic Author
  • 6 hours ago, NLWaard said:

    Please login or register to see this code.

    Question, shouldn't the data be outside the header for a PUT command?

     

     

    Yes, really strange. It is in my code but what I pasted here is wrong.

    Link to comment
    Share on other sites

    On 2/24/2020 at 11:13 PM, jgab said:

    Here is a simple webhook QD.

    The idea is that instead of having external apps continuously polling the HC3 for events, the app makes a call to the HC3 and register it's url for callbacks.

    The HC3 will POST all events to the apps that have registered with it.

    If an app doesn't answer to the POST it's just unregistered. 

    If an app register twice it's detected and won't cause a duplicate post. Thus, a strategy for apps could be to re-register at intervals in case the HC3 QuickApp have been restarted.

    To register, the external app does a POST to http://<HC3IP>/api/devices/<QD ID>/action/registerForEvents with the payload = {args = {"<callback url>"}}

     

    Here is a simple NodeRed flow that register for call-backs and the receives events (just logs them)

    Please login or register to see this spoiler.

     

    but if there's an error in pollEvents the whole systems stops polling. How to prevent from every crash? So in all situations the polling is gone..

    Link to comment
    Share on other sites

  • Topic Author
  • If you fear that it will crash you wrap it in a pcall

    Please login or register to see this code.

    However, this code is pretty dated by know - most of us do a http request to localhost:11111 to avoid the api.get to hang.

    Link to comment
    Share on other sites

    Hi jgab,
    Do I understand that not all code can be run by the editor?
    Or am I doing something wrong.

     

    I'm trying to save a frequently used function in a global string, so I can use it in multiple classes.
    For this I use the code below (which works with small changes in a LUA test environment).

    I get the following error ''attempt to call a nil value (global 'load')'

    Please login or register to see this code.

    Is the 'load' function not possible in the HC3?

    Edited by NLWaard
    Link to comment
    Share on other sites

    3 hours ago, NLWaard said:


    Do I understand that not all code can be run by the editor?

     

    Is the 'load' function not possible in the HC3?

     

    yes, there is set of things not available on HC3:

     

    Please login or register to see this code.

     

    • Thanks 1
    Link to comment
    Share on other sites

  • Topic Author
  • Yes, some functions are not available in the HC3 (or HC2) environment. 

    I do question why many of these functions are not allowed. os.execute & friend I understand but load and coroutines would make the environment so much powerful. I have heard security issues being raised but for load and coroutine it's not a valid argument. The other aspect could be to limit resource usage (memory/cpu) by limiting the Lua expressiveness but I don't buy that either  - for me it's just a bad design decision from Fibaro that at the end forces people to write bad code to get around arbitraty limitations.

     

    load/loadstring is not allowed. We have the "multi-file QAs" now that allows us to include "library files" in our QA these days. Kind of statically linked libraries :-)

    It does makes life easier.

    I have a coding workflow where I code in ZBS, include my libraries, create the QA and debug offline in using my fibaroapiHC3.lua emulator - and with a button click build and deploy it as a multi-file QA on the HC3. The "main file" is my QA and the additional files are the library files that I include have built up during the last 6 months.

    The library is the QA_toolbox

     

    Whenever I start a QA project I have a template

    Please login or register to see this code.

    where I uncomment the libraries I need for the particular QA I want to code.

    For me this is the optimum way to share code and I don't really miss something I have in other coding environments... 

     

    In fact there is two more modules not visible in the example above the implements a Lua interpreter in Lua and allows me to have load and coroutines and metatables on the HC3.It comes with a performance penalty but in some case the expressiveness is worth more. (I'm using it for a future rule scripting language)

     

     

     

     

     

     

     

    • Like 1
    • Thanks 1
    Link to comment
    Share on other sites

    On 9/18/2020 at 4:49 PM, jgab said:

    If you fear that it will crash you wrap it in a pcall

    Please login or register to see this code.

    However, this code is pretty dated by know - most of us do a http request to localhost:11111 to avoid the api.get to hang.

     

    Do you have an updated example how to use a http request to localhost:11111 ?

    Link to comment
    Share on other sites

  • Topic Author
  • 1 minute ago, GJ Niewenhuijse said:

     

    Do you have an updated example how to use a http request to localhost:11111 ?

    Have a look at the triggers module - that's the latest code I use.

     

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