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)

Good morning,

I would like to ask about time-driven events. We have a definition in the scenes like this:

Please login or register to see this code.

Does it generate an regular event that can be listened and handled by RefreshStateSubscriber or similar subscription -  after met given time conditions - like on example device when changes state? If so, how HC knows if user wants to throw time event? Is it necessary to "register" it somewhere? I will be glad to know more about it.
I would like to use it in QA, not scenes, above is just example what I mean.

Thanks in advance.

Edited by Łukasz997
Posted

No, it doesn't generate any regular event. It's only for scenes.

However, you can define a customEvent (General -> Events) and submit that as the action in your scene.

The customEvent will generate a regular event you can listen to with RefreshStateSubscriber.

  • Thanks 1
  • Topic Author
  • Posted

    Thank you. My goal is to handle time-scheduled activity other way than every minute check the clock - if it's right now to do something.

    I thought this could somehow be handled with events. But it seems that it can't.

     

    Posted
    51 minutes ago, Łukasz997 said:

    Thank you. My goal is to handle time-scheduled activity other way than every minute check the clock - if it's right now to do something.

    I thought this could somehow be handled with events. But it seems that it can't.

    Write your own time scheduler. 

    EventLib allow you to subscribe to a time during the day (or sunset/sunrise) and it will generate an event at the time calling the right handler.

    Scheduling (and rescheduling at midnight for the upcoming day) makes it possible without checking time every minute...

    • Like 1
  • Topic Author
  • Posted

    I know that Eventlib has such ability. I’d rather not use EventLib directly because I want to embed that mechanism into my own program.
    Unfortunately, I don’t know how to emit my own event to RefreshStateSubscriber - could you tell me how to do that? Could you lift the veil on how EventLib technically handles time-driven events? I think there must be an internal mechanism for registering time-based events. But what I’m really asking is whether it’s possible, INTERNALLY, to avoid continuously (even if once a minute) polling the clock - and how? 

    Posted (edited)

    Please login or register to see this code.

     

    My version of EventMgr is the same as outlined earlier, but with the addition to being able to post an event.

    The post function can also take a time (24 hour, "HH:MM") when the event should be posted

     

    Please login or register to see this spoiler.

     

    Edited by jgab
    • Thanks 1
  • Topic Author
  • Posted

    As I understand it, the architecture is based on the concept of taking the user-defined table of scheduled times and, in simplified terms, setting a setTimeout delay equal to the number of seconds from “now” until each scheduled execution time. The setTimeout then emits the event as if the arrival of the specified time were the event source - both for one-off and for recurring events.

     

    Outstanding concept. 10 "likes"!

    Posted
    38 minutes ago, Łukasz997 said:

    As I understand it, the architecture is based on the concept of taking the user-defined table of scheduled times and, in simplified terms, setting a setTimeout delay equal to the number of seconds from “now” until each scheduled execution time. The setTimeout then emits the event as if the arrival of the specified time were the event source - both for one-off and for recurring events.

     

    Outstanding concept. 10 "likes"!

    Yes, being able to post your own events like this is a powerful concept.

    After a while you start to think of post as calling a subroutine, and the handler being the subroutine.

    With the time option, you call subroutines in "the future".

    It requires a bit different thinking, compared to function calls that return values. Here we have subroutines that don't...

    Instead one thinks of it as a chain of events/subroutines that pass on arguments that eventually ends up at the handler that knows how to deal with the result.

  • Topic Author
  • Posted

    Sure. Thank you for helping me make a significant progress. I’ll put discovery of emitCustomEvent to good use… for me it’s just a bit of fun, a hobby - but a great one.

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