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


Recommended Posts

Posted

Hi @jgab,

 

I tested both of your solutions EventLib v0.51 and older one SourceTriggerSubscriber on generic quick app added to the HC3 on previous stable firmware. Both solutions required adding QuickApp:sourceTrigger() function to be defined and I get above results from my previous post.

 

Today I added new quick app of generic type on HC3 firmware 5.201.18 beta and tested both of your code with following result:

 

1) EventLib v.051:

Used test code in main file:

Please login or register to see this code.

 

Debug console:

Please login or register to see this code.

 

Above is as expected and no need for sourceTrigger function. Still, function called from event handler must be of GLOBAL type and can't be defined as part of the quick app object.

 

2) SourceTriggerSubscriber:

Used test code in main file:

Please login or register to see this code.

 

Debug console:

Please login or register to see this code.

 

Above is as expected and no need for sourceTrigger function.

Advantage of this solution is that it is possible to call functions that are part of the QuickApp object from event handler. Not so much important, but makes code simpler and easier to follow.

 

BTW - in EventLib v0.51 local function equal(e1,e2) is declared twice, so one copy can be removed.

 

 

  • Topic Author
  • Posted
    11 hours ago, Sankotronic said:

    Hi @jgab,

     

    I tested both of your solutions EventLib v0.51 and older one SourceTriggerSubscriber on generic quick app added to the HC3 on previous stable firmware. Both solutions required adding QuickApp:sourceTrigger() function to be defined and I get above results from my previous post.

     

    I insists, neither of the libraries calls QuickApp:sourceTrigger(). Please search the code yourself to convince yourself.

     

    11 hours ago, Sankotronic said:

    Today I added new quick app of generic type on HC3 firmware 5.201.18 beta and tested both of your code with following result:

     

    1) EventLib v.051:

    Used test code in main file:

    Please login or register to see this code.

     

    Debug console:

    Please login or register to see this code.

     

    Above is as expected and no need for sourceTrigger function. Still, function called from event handler must be of GLOBAL type and can't be defined as part of the quick app object.

     

    Yes, it can. In lua (and other languages with objects), every object has its own self. In QAs, QuickApp is an object created when the QA starts and we usually use self:... to invoke our QuickApp defined methods. But it only works from within a QuickApp defined method. If object of type A wants to invoke a method of object B, we have to pass the 'self' of object B to A, so A can invoke the right method of B.

    In your case, the EventLib handlers are methods of an EventLib class and has their own 'self' with some methods defined. That 'self' is not the QuickApp self so you can't call the QuickApp methods using it.
    One way to "pass" the QuickApp self to the eventlib handler is to set it in a local from onInit.

    Please login or register to see this code.

     

    Fibaro also sets up the global variable 'quickApp' to point to QuickApp's self after we return from :onInit(). That variable could also be used.

    Please login or register to see this code.

    but I'm usually not a big fan of local variables. It works in this case as all QAs only have one QuickApp object instantiated.
    Globals doesn't work as well if you define several QuickAppChild objects and need references to them. 



     

    11 hours ago, Sankotronic said:

     

    2) SourceTriggerSubscriber:

    Used test code in main file:

    Please login or register to see this code.

     

    Debug console:

    Please login or register to see this code.

     

    Above is as expected and no need for sourceTrigger function.

    Advantage of this solution is that it is possible to call functions that are part of the QuickApp object from event handler.

     

    Yes, SourceTriggerSubscriber is simpler (older) with less bells and whistles. The handler is not part of the SourceTriggerSubscriber class so if you define the handler function within a QuickApp method you can use the QuickApp self - like you do in onInit.
    Note that 
    SourceTriggerSubscriber may not catch all events that EventLib does. EventLib is newer and there are always new system events discovered that I try to add and "convert" to something that looks like a sourceTrigger.

     

     

    11 hours ago, Sankotronic said:

     

    BTW - in EventLib v0.51 local function equal(e1,e2) is declared twice, so one copy can be removed.

    Thanks, will look into the double copy...

    • Thanks 1
    Posted

    Hi @jgab,

     

    55 minutes ago, jgab said:

    insists, neither of the libraries calls QuickApp:sourceTrigger(). Please search the code yourself to convince yourself.

    I was not insisting that it is caused by your code. The thing is that I also do not have any calls added anywhere in my code that makes that call. Since this is very odd I just taught it is good to let you know and since you have much more knowledge than me, maybe you can explain it better or maybe you also noticed that some quick apps have strange behavior.

     

    Note that generic type quick app I used to test event library was added on the previous stable firmware and original code was not changed until I pasted eventLib and a piece of my code. Yesterday added generic type quick app on latest beta firmware works as expected and no calls to sourceTrigger() function.

     

    I will keep that older generic type quick app and try to find out why it prints [TRACE] and calls sourceTrigger() function when there is no such call anywhere in the code. Note that trigger is invoked by z-wave device Fibaro eye and none of my quick apps including this one do not call sourceTrigger() function.

     

    1 hour ago, jgab said:

    Yes, it can. In lua (and other languages with objects), every object has its own self. In QAs, QuickApp is an object created when the QA starts and we usually use self:... to invoke our QuickApp defined methods. But it only works from within a QuickApp defined method....

     

    You are completely right and thanks for reminding me that I have to refresh my OOP knowledge. Thank you!

  • Topic Author
  • Posted
    14 minutes ago, Sankotronic said:

    Hi @jgab,

     

    I was not insisting that it is caused by your code. The thing is that I also do not have any calls added anywhere in my code that makes that call. Since this is very odd I just taught it is good to let you know and since you have much more knowledge than me, maybe you can explain it better or maybe you also noticed that some quick apps have strange behavior.

     

    Note that generic type quick app I used to test event library was added on the previous stable firmware and original code was not changed until I pasted eventLib and a piece of my code. Yesterday added generic type quick app on latest beta firmware works as expected and no calls to sourceTrigger() function.

     

    I will keep that older generic type quick app and try to find out why it prints [TRACE] and calls sourceTrigger() function when there is no such call anywhere in the code. Note that trigger is invoked by z-wave device Fibaro eye and none of my quick apps including this one do not call sourceTrigger() function.

     

     

    You are completely right and thanks for reminding me that I have to refresh my OOP knowledge. Thank you!

     

    Is the QA that has the sourceTrigger call issue something you can PM me so I could also test?

    Posted

    Hi @jgab,

     

    I believe I found what was causing "problem" with missing function "sourceTrigger" in my quick app with activated event subscriber. It is your quick app "TriggerQA" which is the only one that makes such call on my system, here is that part of code from main file:

     

    Please login or register to see this code.

     

    I used my generic type quick app with following code:

    Please login or register to see this code.

     

    Above code added quickvar "TRIGGER_SUB" and therefore my QA was found by TriggerQA.

    After testing that, I just replaced above code in my QA with EventLib and code that subscribes to the events. Since I have deleted above code, but didn't delete quickvar "TRIGGER_SUB" and restarted TriggerQA, I get result reported in my first post here.

     

    First I want to apologize to mislead you, not mentioning TriggerQA and previous tests, before I switched to EventLib.

    Your code is doing exactly what is meant to do, perfectly none the less and I thank you for that!

    Thank you also for invested time in this conversation. I should be more careful when reading your instructions.

  • Topic Author
  • Posted

    So, I have done a couple of event libs over time... They all contain a function that converts system events (the ones we get from refreshState) to sourceTrigger format. Scenes gets sourceTriggers but in QAs we need to transform the refresh/system events to souceTrigger format if we want to use that format. SourceTrigger formats are a bit simpler to deal with than the refreshState events we get.

    The conversion I do also converts refreshState events to sourceTriggers that don't have a corresponding official sourceTrigger format like in Scenes. Ex. a DeviceRemovedEvent is translated to a "sourceTrigger" like {type='deviceEvent', id=<id>, value='removed'}

    in my code even though in scenes we don't get such sourceTrigger.

    The problem is that new refreshState events appear over time, and I don't have all types of devices or use cases that would generate all possible refreshState events.

    So, maybe we should open a thread where we together list refreshState events we see, and together provide a translation function to an extended sourceTrigger format that makes sense?

    • Like 4
    Posted

    Hi @jgab,

     

    I just have made my first quick app using your EventLib code. Here is console debug when quick app is started:

    Please login or register to see this code.

     

    Since some of my work will most probably be commercial products I need your permission to use your code and is above sufficient to acknowledge that part of code is copyrighted by you. You, your code and copyright will also be mentioned in user manual provided with such quick apps.

     

    Thank you in advance.

    • Like 1
  • Topic Author
  • Posted

    Yes, you have my blessing 👍

    • Thanks 1
    Posted

    Hello @jgab,

     

    just two more questions :-) 

     

    1) Is there a way to get geofencing events with EventLib in quick apps. I was looking all around for anything that can be used in quick apps, but only found solution for block scenes.

     

    Maybe something like this:

     

    Please login or register to see this code.

     

    2) Also, on HC2 there where functions which could be used to get user location and calculate distance from home:

    Please login or register to see this code.

     

    Is there anything similar in quick apps?

     

    Thank you!

    • Like 1
  • Topic Author
  • Posted

    The sourceTrigger eventLob generates are
     

    Please login or register to see this code.

    location is created as
    {type='location',id=<userId>,property=<locationId>,value=<geofenceAction>,timestamp=<timestamp>}

    ...then the question is about when the HC3 feels like emitting location events....

    calculateDistance didn't make it over to the HC3 but I believe there are forum posts with code for a replacement function.

    • Like 1
    Posted

    Hello @jgab,

     

    5 minutes ago, jgab said:

    location is created as
    {type='location',id=<userId>,property=<locationId>,value=<geofenceAction>,timestamp=<timestamp>}

    ...then the question is about when the HC3 feels like emitting location events....

     

    Great!

    But <locationId> is which location ID? where can be found?

    I guess also that <geofenceAction> is either 'leave' and 'enter' as used in scene trigger or different ones?

    What <timestamp> is and of what format? Is it from timestamp or to timestamp or between timestamps? Can be this omitted?

     

    16 minutes ago, jgab said:

    calculateDistance didn't make it over to the HC3 but I believe there are forum posts with code for a replacement function.

     

    I will give some more effort to find it. Thanks!

  • Topic Author
  • Posted (edited)

    location id is the id of the location defined in the UI. You can see them when using the Swagger /api/panels/location

    Updated to 0.52 (some more error checks, and the source file is in a new location, in the plua Github directory)
    Also linked a documentation file in the first post <

    Please login or register to see this link.

    >

    Edited by jgab
    • Thanks 1
    Posted

    Thank you @jgab!

     

    I plan to have presence solution with Geofency webhooks, Ubiquiti Unify and if possible with Fibaro geofencing for users to choose. Additionally with Netatmo presence cameras.

     

    On my HC2 I use Geofency webhooks which is very reliable with addition of Netatmo presence cameras since Fibaro geofencing never worked properly. I still hope they do better job on new system.

     

     

  • Topic Author
  • Posted
    4 minutes ago, Sankotronic said:

    Thank you @jgab!

     

    I plan to have presence solution with Geofency webhooks, Ubiquiti Unify and if possible with Fibaro geofencing for users to choose. Additionally with Netatmo presence cameras.

     

    On my HC2 I use Geofency webhooks which is very reliable with addition of Netatmo presence cameras since Fibaro geofencing never worked properly. I still hope they do better job on new system.


    Some time ago I used Apple's cloud location service from the HC3 (they changed it in a way difficult to use from the HC3)
    Anyway, if you get a lat/long from another location services, it's possible to go through the locations in api/panels/location and see if the location is within the radius defined for the location. If so you can do a fibaro.post({type='location',id=<userId>,property=<locationId>,value=<geofenceAction>,timestamp=<timestamp>}
    and use the standard EventLib handler you have declared. The only thing that requires some thought is to keep the state to be able to post enter or leave geofenceactions.

    Posted

    Distance on earth:

    Please login or register to see this code.

     

    • Thanks 1
    Posted

    Hi @Łukasz997,

     

    thanks for distance calculation on Earth. On the other hand I was asking for calculating distance between home and me :-) 

    There  is such function on HC2, so I was hoping that there is something similar on HC3.

     

    Still, if there is a way to send location of my mobile phone to HC3 then it can be done.

    Posted

    @Sankotronic

    I was just thinking the same :D
    I am looking into tasker on my phone to push long/lat every 30sec over vpn. 

    Posted
    35 minut temu, Sankotronic napisał:

    On the other hand I was asking for calculating distance between home and me :-)

    I'm addressing your question about calculating distance. As far as I know theres no such function on HC3 and no way to obtain user position via HC3. Position of hub can be retrieved by HC3 API. You have to retrieve your personal position other way.


    Still, this is distance on earth. This method is quite good for short distances (and for such purpose can be even simpler, atan(...) is used here for precision on longer distances).

    Posted
    1 hour ago, Łukasz997 said:

    As far as I know theres no such function on HC3 and no way to obtain user position via HC3.

     

    For Fibaro geofencing to work HC3 must receive location of the mobile phone if location services are enabled for Yubii app, true?

    It is just that Fibaro didn't provide users that information and function to check it in LUA code on new gateways.

     

    Don't know if that is due to security reasons, but maybe @m.roszak can share some information? 

    Posted

    For 0.44$ per day per user you can get the position of any phone in "family" service called life360...

     

    If we do agree to this, the complications only begin. Next we would have to set up an intermediate integration service - our own kind of "translator" between the world of phones and the world of HC3. It would expose an HTTP server, and HC3 would fetch the position from it. Quite a lot of work, and that service would also need to be hosted somewhere. All in all - a good idea for a commercial solution for Fibaro HC3.

    *

    I absolutely agree with you - Fibaro should know the position (and also the tax office).

     

    Well then, perhaps we should once again gather signatures for the idea that - since Yubii already knows the position and all this work has already been done by Fibaro - why not simply expose the users locations in the controller?
    The issue of security? Sometimes I have the impression that this term in today world is a rather grim joke...

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