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 (edited)

Surfing through the forum I found old topic about delays with fibaro.call

It inspired me to go back to my old-fashion, never corrected and malfunctioning scene in LUA. However It's very often used with various results.

I wrote it a year ago knowing very little about HC3.

This scene is invoked by  "the button" and serves as a help to exit the house.

It has to:

- open the lock

- wait for user open the door and then close it

- close the lock

- open the yard gate

...etc.

The problem occurs with first three points, when sleep() and call() is used:

Please login or register to see this code.

The problem is that sometimes (not always, no pattern) behaves like it misses an event: I mean - is "hold" for few second (not for 500 ms sleep) and misses that user already open and close the door. So securing the lock and later operations does not occur. I'm wondering if it's the delay with hub.call?... Using sleep() - which masters of HC does not like - seemed to me inevitable, because I don't know other way to "unload" busy loop asking sensor for value. My knowledge about sleep(n) is that it freezes execution of current QA making it blind and deaf for 'n' ms, nothing bad in this case I hope.

 

This is answer from this "ancient" thread:

Cytat

 

I asked the question, here is the response of the SW team: 

Cytat

It’s taking so long because there is 5 s timeout on communication with QuickApp process. QuickApp process is unable to handle this because it’s still processing fibaro.call.

 

 

 

The script is longer and do other actions, in particular based on waiting until a device reaches desired state. Everywhere small delays by sleep() are used.

I described it as I can.

Could you advice me what can be wrong with it - and - how to realise it better way?

Edited by Łukasz997
Posted


Consider making it a QA instead and trigger on each event instead of waiting for a "check"?🤔

Because like that if you open, close fast it might not have the time to see you opened the door and closed again. 

 

Also what type of doorlock do you have? 
 



If you use the eventlib by Jgab


you can trigger on the doorlock like this:

--place this in top of QA:    (remember to add the eventlib file to  the QA) 
 
-------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
----jgab eventlib
Event.id='start'
Event{type='QAstart'}
function Event:handler(event)
Event:attachRefreshstate()
end



--place this inside of the oninit 
 
-------------------------------------------------------------------------------------------------------------------------------
doorlock_id = 1044
Event.id='_'
Event_std.tagColor='Orange'
Event {type='device', id={doorlock_id}, property='value', value='$value'}
function Event:handler(event)
  --event.id
  --event.value
  self:debug("Sensor ID: ",event.id,"value: ",event.value)
  --local var = ""..event.id..""
  if event.value == true then
    door_locked()
  end
  if event.value == false then
    door_opened()
  end
 
end ---function eventlib
 
-------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
function door_locked()
 
end
-------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
function door_opened()
 
end


 

 

 

 

 

  • Thanks 1
  • Topic Author
  • Posted (edited)

    Thank you very much - eventlib is a solution. However, it makes the steering of script more demanding: the events in all this "recipe" are repeating (same state from the same sensor in different moments), but can be managed by a global variable holding the progress of whole task. 

     

    The lock is Danalock - widely known from the troubles it generate. But in my case - I cannot complain to the communication with it.

    I've been thinking about rewriting this script to QA for a long time - but having no idea how to alter the construction it seems useless...

     

    I think - this is not because very fast open-close door sequense. This is something other.

    But still has no answer about fibaro.call - is using this can lead to delays when HC3 "still processig" the call?

    Edited by Łukasz997
    • Like 1
    Posted

    fibaro.call to a QuickApp is "asynchronous"

    You can test it be calling a QA like

    Please login or register to see this code.

     

    And the QA you call looks like

    Please login or register to see this code.

    Your calling QA continuous directly while the called QA's method sleeps for a minute.

    If it was synchronous, the calling QA would wait until the test method finished...

     

    This is actually a problem when writing QAs as there is no way for a QA to "synchronize results"
    Ex. if I write a QuickApp that controls a lock over http, my method

    Please login or register to see this code.

    will return immediately to the caller and I have no way to return the fact that the locking was successful or not.

    It will then resort to having another function that returns the result of the operation

    Please login or register to see this code.

    But how long should the caller wait before calling this??

    Anyway...

     

    If the device is a (native) zwave device, the rules are different.

    The box will send a zwave request to the lock to lock (and timeout after 5s I guess according to the answer you got)

    The fibaro.call may hang waiting for this, I don't know as I have no experience of zwave device taking that long to respond.

     

    I'm not so familiar with the zwave protocol so the hanging can be just while waiting for an ack on the request.

    The actual result of the operation could be an asynchronous response even later...

    So I'm a bit unsure if

    Please login or register to see this code.

    would be problematic as the value is not yet updated when the getValue call is done...

    Someone with deeper knowledge about zwave need to help out here.

     

    It could also be that the box handles it so fibaro.call(nativeDeviceId,...) don't return until the devices has sent back a response (synchronous or asynchronous).

     

    Anyway, fibaro.call to a native device could take time depending on how fast the device responds.

    For lua QuickApps, fibaro.call returns immediately 

     

     

     

    • Thanks 1
  • Topic Author
  • Posted (edited)

    Reading above I'm not sure if rebuilding it to the evenlib driven QA will actually help. For sure it eliminate hub.sleep(n) by a cost of hundreds of lines of "never sleeping code". It's worth to do if it will run smooth. Only solution is to convert and watch... I'll do it and share with results.

    One more question - can you tell me how to define an eventlib handler to deal with event generated when a given person is entering geofence - on turn I use it when someone is going back home.

     

    BTW - have any implemented successfully similar procedure of leaving/entering home? I think this is one of the first things you would like to do...

    Edited by Łukasz997
    Posted
    6 minutes ago, Łukasz997 said:

    Reading above I'm not sure if rebuilding it to the evenlib driven QA will actually help. For sure it eliminate hub.sleep(n) by a cost of hundreds of lines of "never sleeping code". It's worth to do if it will run smooth. Only solution is to convert and watch... I'll do it and share with results.

    One more question - can you tell me how to define an eventlib handler to deal with event generated when a given person is entering geofence - on turn I use it when someone is going back home.

     

    BTW - have any implemented successfully similar procedure of leaving/entering home? I think this is one of the first things you would like to do...


    The geofence inst that good to be honest, it is better to use some kind of device connecting to wifi to trigger home/away. 
    Since phones set all apps in powersaving mods and stuff...


    I might look into making a QA for doorlocks to :D

    Thinking of adding stuff like:
    Autolock (a small delay after the door unlock --> lock again) 
    Lock timer (example: lock every day 23:00)
    Push when door unlock  on/off
    push when door lock on/off

    Auto lock on profile change with delay (Lock after 3min of changing to choosen profile(Away)) 
    Auto unlock on profile change to for example "home" (possible to choose profile) 
    Log of last 10 locks/unlocks event with timestamp
    device type doorlock, not generic so it sync status with the main device 



    Any other ideas to what a doorlock should have of functions? 🤔


    In z-wave engine 3 it seems like it is possible to add pin support for most z-wave locks to ( maybe look into this later :D
     

    My QA for now only have the push when lock/unlock and auto lock on a timer everyday :)



     

  • Topic Author
  • Posted

    In my case, geofencing is not ideal, but good and - only solution. It's used only to open the yard gate. Standing in front of gate I'm too far to reach wifi at the building (I'm not living in the castle, however).

    The "automation" will never be used to unlock the home door (or any direct entrance to home).

    So, I'm kindly asking again: how the definition of event handler to catch geofencing (using eventlib) should look like ({type, value} or somewhat is needed)?

     

    I do not recommend to use Zwave 3 - I had a very unpleasant experience with this, maybe it's worth to recall:

     

    What such script can do:
    Exit:

    - open and close lock (if available)

    - when no other at home, turn off lights & arm the alarm

    - when no other home: turn on water leak guard QA (in my case)

    - turn on lights on yard at dark

    - open the yard gate & close it after time

    I will not lower the temperature, cheaper is to maintain it for short-term empty house.

     

    Similar, at the opposite order, when arriving.

     

    I can recommend checked and reliable very easy method of fundamental - from the viewpoint of constructing such script - recognising who is at home (Iphone only unfortunately):

     

    Posted
    29 minutes ago, Łukasz997 said:

    In my case, geofencing is not ideal, but good and - only solution. It's used only to open the yard gate. Standing in front of gate I'm too far to reach wifi at the building (I'm not living in the castle, however).

    The "automation" will never be used to unlock the home door (or any direct entrance to home).

    So, I'm kindly asking again: how the definition of event handler to catch geofencing (using eventlib) should look like ({type, value} or somewhat is needed)?

     

    I do not recommend to use Zwave 3 - I had a very unpleasant experience with this, maybe it's worth to recall:

     

    What such script can do:
    Exit:

    - open and close lock (if available)

    - when no other at home, turn off lights & arm the alarm

    - when no other home: turn on water leak guard QA (in my case)

    - turn on lights on yard at dark

    - open the yard gate & close it after time

    I will not lower the temperature, cheaper is to maintain it for short-term empty house.

     

    Similar, at the opposite order, when arriving.

     

    I can recommend checked and reliable very easy method of fundamental - from the viewpoint of constructing such script - recognising who is at home (Iphone only unfortunately):

     

     

    I havent used it in event lib but this is the standard setup, so I have to test to verify :) But I have setup a test for now :) 

     

    --[[
    {
      conditions = { {
          id = 2,
          isTrigger = true,
          operator = "==",
          property = 219,
          type = "location",
          value = "enter"
        }, {
          id = 2,
          isTrigger = true,
          operator = "==",
          property = 219,
          type = "location",
          value = "leave"
        } },
      operator = "any"
    }
    ]]
     
        id = 2   ---number of user that will be tracked, mine is 2  (crate a block since and convert to lua to see your id like the above conitions)
        zone = 219
        Event.id='_'
        Event_std.tagColor='Orange'
        Event {type='location',id=id,property=zone,value='enter'}    
        --{type='location',id=<number>,property=<string>,value=<string>,timestamp=<number>}  
        function Event:handler(event)
          --event.id
          --event.value
          self:debug("Sensor ID: ",event.id,"value: ",event.value)
          --local var = ""..event.id..""
     
        end ---function eventlib

     

     

     

    • Thanks 1
    Posted



    This one works: 

    and I guess instead of enter you can have 1 more with "leave" as value

     
    --[[
    {
      conditions = { {
          id = 2,
          isTrigger = true,
          operator = "==",
          property = 219,
          type = "location",
          value = "enter"
        }, {
          id = 2,
          isTrigger = true,
          operator = "==",
          property = 219,
          type = "location",
          value = "leave"
        } },
      operator = "any"
    }
    ]]
     
        id = 2   ---number of user that will be tracked, mine is 2  (crate a block since and convert to lua to see your id like the above conitions)
        zone = 219   ---what zone that is defined in general/location tab (crate a block since and convert to lua to see your zone id like the above conitions)
        Event.id='_'
        Event_std.tagColor='Orange'
        Event {type='location',id=id,property=zone,value='enter'}    
        --{type='location',id=<number>,property=<string>,value=<string>,timestamp=<number>}  
        function Event:handler(event)
          --event.id
          --event.value
          self:debug("Sensor ID: ",event.id,"value: ",event.value)
          --local var = ""..event.id..""
          push2()
        end ---function eventlib
  • Topic Author
  • Posted

    Thank you very much for the time spent and help! I'll check it within few days.

    • Like 1
    • 2 weeks later...
    Posted

    @Łukasz997

    Want to test my Doorlock Controller? :D  
    Would love to have some feedback on aditional functions 😄

     


    Some pictures
    (have to add time/days setup on autolock)

     

    image.png.5c35c5c07c2a31a21b9a29280a9fc7d7.png

    image.png.90825a297ad5bc2aa2264efefa139ebc.png

    image.png.777c51e762acb310dcc473f204a1869d.png

    image.png.fc4265192301aeca038284c273fba13b.png

    image.png.979e93546f51ff5ab3c403cf623c1fb8.png

    image.png.bc67fee90d910255a05c611d2c076012.png

    image.png.28ad7b1ea990f68370ac1cce7aa8d927.png

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     


     

  • Topic Author
  • Posted
    2 godziny temu, Brors94 napisał:

    Want to test my Doorlock Controller? :D  
    Would love to have some feedback on aditional functions 😄

    Hello @Brors94,

    it will be a pleasure for me to test it and help you in development. Sure, if I only could.

    Posted (edited)
    1 hour ago, Łukasz997 said:

    Hello @Brors94,

    it will be a pleasure for me to test it and help you in development. Sure, if I only could.

     

    I just got finished with the autolock time/day thing :D
    Language isnt supported yet :) Only en. (will add later) 
    So now I am going to add the notification senter thing I think 🤔


    Check out new version here:  (found a bug that made the days in autolock not to work 😅)

     

    Edited by Brors94
    • Like 1
  • Topic Author
  • Posted

    After testing it, I wanto to say that it's really complete lock toolkit.
    This which should be changed is minor: the colour scheme for Yubii App (on iphone at last) to make the messages more visible. And small text mistake: when it comes to lock by profile change, description says: unlock. Clever (hidden) hour change in time setting... At start I thought, that I have to click ad mortem defecatam :)

    I really have no idea what can be added more. Super!

    Posted
    2 minutes ago, Łukasz997 said:

    After testing it, I wanto to say that it's really complete lock toolkit.
    This which should be changed is minor: the colour scheme for Yubii App (on iphone at last) to make the messages more visible. And small text mistake: when it comes to lock by profile change, description says: unlock. Clever (hidden) hour change in time setting... At start I thought, that I have to click ad mortem defecatam :)

    I really have no idea what can be added more. Super!

     

    Colors is actually changeable in quickapp variabel (set color by name or colorcode) :D I got dark mode on all apps and web btw :D 
     

    Clever (hidden) hour change in time setting.   I will add a description on the long press to change hours 😅😆 

     

    small text mistake: when it comes to lock by profile change, description says: unlock  and I will check this out to :D 

     

    Thanks for feedback! :)
     

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