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! I have used your 

Please login or register to see this link.

 library before, but now trying to use this new one.

 

I used it like this:

 

Please login or register to see this code.

 

Idea is that event will be triggered every hour (aligned) and then current hour will be compared with variable's value (that can be changed by a QA's slider, for example) - so the event will not be changed, but the conditions can be different.

But I got an error:

Please login or register to see this code.

so my self.config is not visible inside the Event and this is reasonable. self.parent construction not working as well.

 

How to have an access to self (QuickApp)? I even could not use self:getVariable...

 

P.S. I used eventStart() function to start an event, because it should not be started if QuickApp is disabled. 

 

Thank you!

 

 

  • Topic Author
  • Posted

    Yes, the self inside Event is referring to the Event object, not the QuickApp. Here you have other methods like the self:post(...) etc

    So, the self variable of the Event object is shadowing the self variable of the QuickApp object.

    One approach, in your case, is just to assign the QuickApp variable's self to another variable. Like

    Please login or register to see this code.


     

    • Like 1
    Posted

    Hi @jgab.

    I am trying to use the eventlib to trigger on this event:

    Please login or register to see this image.

    /monthly_2025_04/image.png.19ac0ba7a8e6d868504632ec91f45ee6.png" />

     

    It works from scenes like this:
    image.png.70c28b14a251053e5b0089d1d3353b2b.png

     

     

    But it seems like it dosent trigger anything in the Eventlib when I set it up like this:

     

    Please login or register to see this code.


    The last on should have posted all events if I am not wrong? 🤔

    It is a zooz range extender that I am trying to trigger a QA on 

     

     

     

     

  • Topic Author
  • Posted

    The first picture seems to be cut off,
    I see the data, objects and id keys... 

    was there a 'type' key on the top-level of the datastructure?

     

    In the scene it looks like it triggers on a DevicePropertyUpdatedEvent type of event.

    It usually has a property key, and here is the property key 8??? which seems to match the notificationType in the event...

    Generally property keys are strings not numbers.

     

    Are you sure you match the right event with the right scene trigger? Sometimes a device action can create multiple events...

     

    Also, if you turn the scene into a lua scene and print the sourceTrigger, how does it look like?

    Posted (edited)
    38 minutes ago, jgab said:

    The first picture seems to be cut off,
    I see the data, objects and id keys... 

    was there a 'type' key on the top-level of the datastructure?

     

    In the scene it looks like it triggers on a DevicePropertyUpdatedEvent type of event.

    It usually has a property key, and here is the property key 8??? which seems to match the notificationType in the event...

    Generally property keys are strings not numbers.

     

    Are you sure you match the right event with the right scene trigger? Sometimes a device action can create multiple events...

     

    Also, if you turn the scene into a lua scene and print the sourceTrigger, how does it look like?


    The first pic is of this api call:

    Please login or register to see this attachment.

     

     

    This is the sourcetrigger from a lua scene:

    Please login or register to see this image.

    /monthly_2025_04/image.png.d5751c0822f4c3f51121e5da106741d5.png" />

     

    I have tried to match diffrent ways with strings and numbers. But the event like this should trigger on all?🤔 

    Please login or register to see this code.

     

    and in the history tab it looks like this:

    Please login or register to see this attachment.

     

     

     

    Edited by Brors94
  • Topic Author
  • Posted
    2 hours ago, Brors94 said:


    The first pic is of this api call:

    Please login or register to see this attachment.

     

     

    This is the sourcetrigger from a lua scene:

    Please login or register to see this link.

     

    I have tried to match diffrent ways with strings and numbers. But the event like this should trigger on all?🤔 

    Please login or register to see this code.

     

    and in the history tab it looks like this:

    Please login or register to see this attachment.

     

    But the data returned in the Response body don't have a 'type' field?

    I see the 'sourceType' field, but events should always have a 'type' field too.

    ...otherwise it will not be picked up by event lib that uses refresh state api to get the events.

     

    ...and property name of '8' with the value of '2' is bonkers... looks almost like a bug.


    How did you know how to write the scene condition? Can you set the condition from the block editor?

  • Topic Author
  • Posted

    See if you can see the event with fibaro's own function

    Please login or register to see this code.

    This prints out all events that are generated. I don't know how to filter it for your specific event so you need to look through the log and identify it somehow... I guess it should have similar structure as the Response body above...

  • Topic Author
  • Posted

    The events in the notification panel should have a type, like this

    Please login or register to see this attachment.

    Posted (edited)
    5 minutes ago, jgab said:

    The events in the notification panel should have a type, like this

    Please login or register to see this attachment.

     

    Aha sorry 

    this is the type: 

    Please login or register to see this image.

    /monthly_2025_04/image.png.39cc2362cfa2a9198f20074af6d21a89.png" />

     

     

    and this is from the refreshstate subscriber print:

    Please login or register to see this attachment.

     

    Btw, This is on my test HC3 on Engine 3. so you know :)

     

     

    Edited by Brors94
  • Topic Author
  • Posted

    Ok, that type is not supported as it is the first time I see it.

    I could add it but I I think it's strange to set the property to the number value of the notificationType....

    I wonder if this is typical for this type of event....???

    In the sourceTrigger from the scene you only get the id (950) timestamp,  value (2) and the property (8). Is that ok?

    The event contains more values?

     

    I added it, try this and let me know if it works... 

    Please login or register to see this attachment.

    • Thanks 1
    Posted
    12 minutes ago, jgab said:

    Ok, that type is not supported as it is the first time I see it.

    I could add it but I I think it's strange to set the property to the number value of the notificationType....

    I wonder if this is typical for this type of event....???

    In the sourceTrigger from the scene you only get the id (950) timestamp,  value (2) and the property (8). Is that ok?

    The event contains more values?

     

    I added it, try this and let me know if it works... 

    Please login or register to see this attachment.


    Worked straight away :D

    I guess it is new to the z-wave 3 eninge 🤔 Since this can support a lot of devices without a template? 🤔  
    image.png.c3ee009c2ac7a8c1da2953132f358c33.png

    Posted (edited)

    Please pardon my question — the answer is probably somewhere here already, but I’d rather ask than search...

    Is it possible to define an event handler condition like this?

    Please login or register to see this code.

    I can see that it's possible to subscribe to multiple devices, but I’m not sure how to match exact values from each one.  In my case, two devices change their values within milliseconds of each other, and I’d like to “weld” those changes into a single event — instead of handling them separately.

    Please consider that value condition is AND: exact values from both devices must be obtained.

     

    Thanks in advance!

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

    Please pardon my question — the answer is probably somewhere here already, but I’d rather ask than search...

    Is it possible to define an event handler condition like this?

    Please login or register to see this code.

    I can see that it's possible to subscribe to multiple devices, but I’m not sure how to match exact values from each one.  In my case, two devices change their values within milliseconds of each other, and I’d like to “weld” those changes into a single event — instead of handling them separately.

     

    Thanks in advance!

     

    I guess this will always be 2 events? even when it is a few millisec between. 
    Because when one of them change it would always then be a "check" condition of the other? 

    But you can make 1 Event handler that trigger on both the devices true/false events with teh "filters" and update values the you store and use as conditions and then again trigger what you want. 


     

     

    • Thanks 1
    Posted
    21 minut temu, Brors94 napisał:

    I guess this will always be 2 events? even when it is a few millisec between. 

    Yes, you are right - two events and only one pattern to handle. In real world it's an expansion card who has two binary output connected to the smart implant. Basically it changes only one of two bits, but there's one situation where values changes from 0 and 1 to 1 and 0. And it means two very close events and - now I'm not sure that 1 and 0 will be the values of second event. It may be a value of first and second, I'm afraid...

     

    The event does not wait until handling of first is over. It seems that in the "middle" of one handler is invoked again - I saw this because of repeating log messages: one sequence of messages didn't end and there's second sequence interlaced in first. So the filtering should take part as soon as possible - in the evening trigger stage. At least that’s how I imagine it.
    Maybe it will be safe to ignore first event and handle second. 

     

    Or ignore both and maintain the logic other way. Its possible and need two handlers. Rest events from devices need to be ignored...

    1. device = {a, b} and values of both a, b == true

    and

    2. device = {a, b} and values of both a, b == false

     

     

     

     

     

    Posted (edited)

    If it’s too much for you, just delete it and pretend it never existed. I simply eliminate reaction for event(s) 1,0 -> 0,1. And call it a day.

    Well, not quite. But maintaining the logic of this device was to eliminate not necessary events first...

     

    Edited by Łukasz997
  • Topic Author
  • Posted (edited)

    Probably would do something like this

    Please login or register to see this code.

    The "issue" here is to check that the events are close in time. os.time() only have second resolution so here we check that time is equal or less to 1 second between the events.

     

    Then one could code it a bit more clever to reduce the events in the second rule

    Please login or register to see this code.

    However, a month later one would like to understand what the code does, so being too clever is not always optimal.. 

     

    And probably most elegant would be

    Please login or register to see this code.

    Using the pattern matching with '$value' to only match where the values are the same.

    There are no if-then statements in the handlers - all selections are done by the event matching logic..

    Edited by jgab
    • Thanks 1
    Posted (edited)
    2 hours ago, Łukasz997 said:

    If it’s too much for you, just delete it and pretend it never existed. I simply eliminate reaction for event(s) 1,0 -> 0,1. And call it a day.

    Well, not quite. But maintaining the logic of this device was to eliminate not necessary events first...

     

     

    Sry just busy with other stuff, so dosent have time at the moment to give you an example of how I would have done it :D 
    But jgab know it alot better on how things work 😄 
    I cant elaborate it like jgab does to so 😅 

    Since I actually dont know how things run behinde the code :D 



    But may I ask one question to jgab? 

    If we define an event like this below, wouldnt that just run the first handling and check this 2 if statements? and then run the next event millisecs later and check them again?
    Or is this toslow? 🤔

     

    local id = {x_id,y_id}
    local x_val
    local y_val
    --------------------------------------------
        Event.id='_'
        Event_std.tagColor='Orange'
        Event {type='device', id={id}, property='value', value='$value'}
        function Event:handler(event)
          if event.id == x_id then
            event.value = x_val
          elseif event.id == y_id then
            event.value = y_val
          end
          if (x_val == true and y_val== false) then
            Do_what_you_want()
          end
          --event.value
          --self:debug("Sensor ID: ",event.id,"value: ",event.value)
          --local var = ""..event.id..""
        end ---function eventlib
        Event_std:post({type='device', id=x_id, property='value', value=hub.getValue(x_id, "value")})  
        Event_std:post({type='device', id=y_id, property='value', value=hub.getValue(y_id, "value")})  

     

    After posting, I reread again and think my example wont work since it will trigger the action if the relays is just for a millisec with the right position 😅
    But I guess the solution from Jgab will work fine :D 
     

    Edited by Brors94
  • Topic Author
  • Posted

    Ok, my code test if the values are the same, yours if they are not the same - anyway, both examples are adjustable.

    My first attempt looked something like your example but there were problems...

    The issue with your code is that it could also take years between the events and it would "do something".

    If x_val == true then it will "do something" for every y_val == false coming in.

    ...and the opposite, x_val == false and y_val == true should also work....

    So one wants to isolate sequences of x,y and y,x events where the values are the same (or different) and the time between is not too long.

     

    If we could guarantee that x and y events always alternate, and never comes in duplicates it could be simplified

    • Like 1
    Posted (edited)

    Thank you for help. If I may I would like to share some observations coming from this case... I know it's not exactly this thread, but it's about EVENTS. And probably the story might be of some value.
    I do not expect further help, just have a read and look at the kind of traps that await a lone driver programmer.

     

    My first attempt to make door smart was with Hörmann garage door: close sensor, open sensor (by a window sensors) and engine run/idle sensor (by outlet power consumption) - that's enough and easy to maintain. It has one hidden state: After opening, the gate would come to rest against a rubber bumper, slightly compressing into it and then springs back. SOMETIMES it alters the state of open sensor. This "hidden state(s)" was easy to manage.

     

    Now it's time for yard gate with Tousek motor. No traditional end sensors this time - just an internal encoder and an expansion card that exposes its state externally.This damned card has not one - as before - but two bits output. Very small difference, isn't it?

    Transitions between states are the following:

    closed: 00 -> opening: 01 -> opened: 11

    or more complex: closed: 00 -> opening: 01 -> stopped: 10 (2 events)-> started again: 01 (2 events) -> closed again: 00 or opened: 11

    Initially, I was actually pleased since it eliminated the need to read the current draw, which was somewhat unreliable (delayed changes).

     

    There's no need to handle 01 and 10 (gate ajar, moving or not moving) - this can be done when gate end it's move to 00 or 11 position.

    I eliminate all events when there's no 11 or 00 (K1, K2 - sensors) at first line of event handler:

    Please login or register to see this code.

    But look at the log. gate is open (11), Close command is issued and:

    [2] Event from sensor come at once. Sure - gate leaves the open position -> ajar, the sensor changes 11 -> 01

    [3] But inside the handler the sensor reading is still 11. What, on earth, generates this event? According to value 11, nothing yet happens.

    [4] Then, during that same event handler execution, a second event is fired. This is the one I expected to be the first, and it gets ignored (because it doesn't show 11 or 00). All log lines from 21:40:09 are part of a single event block. The orange debug message ("Ignoruję...") must come from the second event firing inside the handling of the first.

     

    Milliseconds, microseconds. How can they do the plane not (very often) fall from the sky? 

    I heard French TGV trains still use Motorola 68000 (Atari, Amiga, ~1985) processors in their control systems - just because it works.

    As @jgab said elsewhere a driver looking simple shouldn't be that simple.

     

    This is all funny, isn't it?

    Aha... this is from hc3emu, not HC3. Maybe it behaves other way on HC3.

     

    Please login or register to see this image.

    /monthly_2025_05/image.png.5ec2e2f8ef95564a7dbc8e8f0e6ed6f4.png" />

    Edited by Łukasz997
    • Like 1
  • Topic Author
  • Posted (edited)

    Welcome to the real messy physical world :-) 
    The world is highly asynchronous and events doesn't always come in the order we expect...

    They may have always come in a specific order, but then because of a delay somewhere, one event get sent earlier...

    or an event may get sent twice... or get lost.

    So, to adapt to the real world we need some heuristics to decide what event sequences means in our specific case...

     

    One approach is to think about the events as a stream of events.

    Then we usually truncate the stream into a sliding windows of a certain size (or time).

    Ex. all events the last 5s.

    Then we constantly scan this window for patterns that has meaning.

    think of it as almost a regular expression match. 

    Ex. A id K1==true, B is K1 == false, C is K2=true and D is K2=false

    A window of the last 5s of events could be

    "ACCDBC" and we look for ex. "A.-DB". (may not make sense in your case but I haven't really dived into your "states")

    Sometimes the matching may be more complex then regular expressions can achieve.

    However, we try to get rid of the time aspect by only analyzing a window of "time size" relevant to events belonging together for our heuristics.

     

    So, with eventlib we would have one handler that collects the events we are interested in and creates the sliding window.

    Then it would sent an event to another handler(or many handlers)  that the window changed, and that handler would look for patterns that should then generate another more "high-level" event for a detected pattern. etc. Kind of like the id="XY" example previously.

     

    The alternative, without an event model of programming, instead trying to capture it with some if-then-else logic that feel like they do the right thing is way more complex in the general case...

    Edited by jgab
    • Like 1

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