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


fibaroExtra


Recommended Posts

  • Topic Author
  • 7 minutes ago, Neo Andersson said:

    Daer Jgab, how can we format the event post with a condition where posting would be depending on next day name. If user doesnt want scheduled irrigation on Wednesday, the event post in the loop shouldnt be happening if the next day is Wednesday.

    You always schedule an event per day and check inside the event handler if it's a Wednesday.

    Please login or register to see this code.

     

     

    7 minutes ago, Neo Andersson said:

     

    The other thing: Can we cancel an event which was already posted? I couldnt manage to find any description in your topic, how to cancel an event. You have there a function FIbaro.event(ref).cancel, but somewhere i saw that it cant be used for posted events, it only cancel the declaration so the event won't be posted next time, because it won't exist. Am i right?

     

    Yes, (Note that QuickApp:post and fibaro.post response QuickApp:event and fibaro.event are the same functions - just convenient to have them accessible from self:)

    A fibaro.post(event, delay) is really implemented as a

    Please login or register to see this code.

    so as long as the setTimeout has not timeout and the event been posted we can cancel it

     

    Please login or register to see this code.

    Assume that we start a loop

    Please login or register to see this code.

    This won't work. The ref we get when we start the loop is only valid to cancel the initial post. The new post inside the handler creates a new ref.

     

    We can get around it if we are careful and set the ref in the loop

    Please login or register to see this code.

    but this is very similar to have we use setTimeout...

     

    7 minutes ago, Neo Andersson said:

     

    What happens with "RunIrrigation" event if its forexample posted once for 9:00, once for 11:00? The posting mechanism will overwrite the first one, or it will create a paralell instance and both events will be triggered? Thanks a lot for help

    No it creates parallel instances (two setTimeouts waiting to post the events at 9:00 and 11:00 respectively).

     

    A small change to the example to make it more reusable

    Please login or register to see this code.

    What we do here is that we include the scheduled time as a field in the runIrrigation event.

    The runIrrigation handler then use that field as the delay time for the post. 

    Thus, we can post and run (start) many "loops" in parallel. 

     

    The event handler function gets an argument 'env' that is a table that contains the event that triggered the handler (env.event)

    We just repost that event and we pick out the scheduled time and use that for the delay.

     

    You could run 100 irrigation loops during a day and there is no problem if they overlap or not as all "actions" are asynchronous setTimeouts under the hood.

    ...and you could run other event loops doing other housekeeping tasks - like doing http requests to fetch weather data or something.

     

    The event model of structuring a QuickApp (or code in general) is really powerful and I have preached about it for years but I don't think I have any followers yet ;-) 

    Link to comment
    Share on other sites

    26 minutes ago, jgab said:

    You always schedule an event per day and check inside the event handler if it's a Wednesday.

    Please login or register to see this code.

     

     

     

    Yes, (Note that QuickApp:post and fibaro.post response QuickApp:event and fibaro.event are the same functions - just convenient to have them accessible from self:)

    A fibaro.post(event, delay) is really implemented as a

    Please login or register to see this code.

    so as long as the setTimeout has not timeout and the event been posted we can cancel it

     

    Please login or register to see this code.

    Assume that we start a loop

    Please login or register to see this code.

    This won't work. The ref we get when we start the loop is only valid to cancel the initial post. The new post inside the handler creates a new ref.

     

    We can get around it if we are careful and set the ref in the loop

    Please login or register to see this code.

    but this is very similar to have we use setTimeout...

     

    No it creates parallel instances (two setTimeouts waiting to post the events at 9:00 and 11:00 respectively).

     

    A small change to the example to make it more reusable

    Please login or register to see this code.

    What we do here is that we include the scheduled time as a field in the runIrrigation event.

    The runIrrigation handler then use that field as the delay time for the post. 

    Thus, we can post and run (start) many "loops" in parallel. 

     

    The event handler function gets an argument 'env' that is a table that contains the event that triggered the handler (env.event)

    We just repost that event and we pick out the scheduled time and use that for the delay.

     

    You could run 100 irrigation loops during a day and there is no problem if they overlap or not as all "actions" are asynchronous setTimeouts under the hood.

    ...and you could run other event loops doing other housekeeping tasks - like doing http requests to fetch weather data or something.

     

    The event model of structuring a QuickApp (or code in general) is really powerful and I have preached about it for years but I don't think I have any followers yet ;-) 

     

    Thanks man..no worries..you have at least 1 follower for sure..:-)

     

     

     

    Link to comment
    Share on other sites

    3 hours ago, Neo Andersson said:

     

    Thanks man..no worries..you have at least 1 follower for sure..:-)

     

     

     

    Hey bro,

    I am doing everything as you recommended, but it doesnt work for me..If I cancel the event it still runs.. Maybe i have somehow lost the track of all created events in the code, so it would be nice, if we could list out all the events "runIrrigation" that have been posted, so i can have some overview over them, and see if i misscoded something..Can we list out all events created as you showed me? Becuase listing custom events doesnt show "runIrrigation". I assume it is becuase "runIrrigation" is not a custom event...how can we differeciate custom-events from events like "runIrrigation", and how can i list all posted "runIrrigation" events and its times? Does fibaroextra have any function for that ? Thanks

    Link to comment
    Share on other sites

  • Topic Author
  • 56 minutes ago, Neo Andersson said:

    Hey bro,

    I am doing everything as you recommended, but it doesnt work for me..If I cancel the event it still runs.. Maybe i have somehow lost the track of all created events in the code, so it would be nice, if we could list out all the events "runIrrigation" that have been posted, so i can have some overview over them, and see if i misscoded something..Can we list out all events created as you showed me? Becuase listing custom events doesnt show "runIrrigation". I assume it is becuase "runIrrigation" is not a custom event...how can we differeciate custom-events from events like "runIrrigation", and how can i list all posted "runIrrigation" events and its times? Does fibaroextra have any function for that ? Thanks

    The HC3's custome vents are something different.

     

    You can actually print a ref and get some info, like when it expires

    Please login or register to see this code.

     

    Well, not at the moment. How would you like to get an overview of them? Dumping them to the log? It's similar to setTimeout and I guess that one could keep a list of all outstanding timers so they could be dumped to the log. One could patch fibaro.post to keep a list of outstanding posts and a command fibaro.listOutstandingPosts() to dump them. Haven't tried the code below but I think it would work.

    Please login or register to see this code.

    However, it doesn't scale if you have 100's of events running like I have in my programs. 

    Link to comment
    Share on other sites

  • Topic Author
  • Just discovered a small change in the non public fibaro api so debugging in fibaroExtra had some issues. Pushed new version.

    Link to comment
    Share on other sites

    7 hours ago, Neo Andersson said:

     

    Thanks man..no worries..you have at least 1 follower for sure..:-)

     

     

     

    Hello Jgab, please check the attached picture. I just copy pasted the code what you recommended, ..wanted to test it and get some overview about

    event mechanism..It doesnt work for me..It doesnt cancel the event..so i can't manage in my irrigation QA the schedule cancelling.

    As there is noy a single Fibaro documentation to Fibaro.event processing, I cant really get it work on my own.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

  • Topic Author
  • Can you post the whole example code?

    Link to comment
    Share on other sites

    42 minutes ago, jgab said:

    Can you post the whole example code?

    Please login or register to see this code.

    I have changed it already so i can't show you, but i am trying your suggestion for workaround. The "Ding" is not printed anymore, but in the log there is a new ref created anyway. Also i noticed, that after that previous problematic code my system is getting slower and slower, its not reacting immediately to keypresses, i need to wait some seconds while the debug window opens. I hope i didnt triggered some infinite loops somehow..

    I just cant get it work in my irrigation QA. The cancellation doesnt cancel the event. I am saving the ref right after the sequence, as you recommended, but it still runs the code..Can you recommend any documentation of these Fibaro functions, like fibaro.event, and so on.. Theres not a single reference for any help on the net, or maybe i am blind. How can be an event cancelling, or deleting so complicated..Ohhh,,man

    Please login or register to see this attachment.

    Just now, Neo Andersson said:

    Please login or register to see this code.

    I have changed it already so i can't show you, but i am trying your suggestion for workaround. The "Ding" is not printed anymore, but in the log there is a new ref created anyway. Also i noticed, that after that previous problematic code my system is getting slower and slower, its not reacting immediately to keypresses, i need to wait some seconds while the debug window opens. I hope i didnt triggered some infinite loops somehow..

    I just cant get it work in my irrigation QA. The cancellation doesnt cancel the event. I am saving the ref right after the sequence, as you recommended, but it still runs the code..Can you recommend any documentation of these Fibaro functions, like fibaro.event, and so on.. Theres not a single reference for any help on the net, or maybe i am blind. How can be an event cancelling, or deleting so complicated..Ohhh,,man

    Please login or register to see this attachment.

    Or maybe the logic behind my QA is wrong. I am doing it like this.

     

    In Oninit function

     - declaring the event with a callbak where the post for next schedule is done with reference2

    - posting the schedule for first time with reference1

     

    there is a button for users: Deactivate schedules

    If its pressed,i call Fibaro.cancel(reference1), and Fibaro.cancel(reference2)

     

    If user presses Activate schedules

    - posting the schedule for first time with reference1

     

    It doestn work...

     

     

     

     

     

     

     

    Link to comment
    Share on other sites

    5 minutes ago, Neo Andersson said:

    Please login or register to see this code.

    I have changed it already so i can't show you, but i am trying your suggestion for workaround. The "Ding" is not printed anymore, but in the log there is a new ref created anyway. Also i noticed, that after that previous problematic code my system is getting slower and slower, its not reacting immediately to keypresses, i need to wait some seconds while the debug window opens. I hope i didnt triggered some infinite loops somehow..

    I just cant get it work in my irrigation QA. The cancellation doesnt cancel the event. I am saving the ref right after the sequence, as you recommended, but it still runs the code..Can you recommend any documentation of these Fibaro functions, like fibaro.event, and so on.. Theres not a single reference for any help on the net, or maybe i am blind. How can be an event cancelling, or deleting so complicated..Ohhh,,man

    Please login or register to see this attachment.

    Or maybe the logic behind my QA is wrong. I am doing it like this.

     

    In Oninit function

     - declaring the event with a callbak where the post for next schedule is done with reference2

    - posting the schedule for first time with reference1

     

    there is a button for users: Deactivate schedules

    If its pressed,i call Fibaro.cancel(reference1), and Fibaro.cancel(reference2)

     

    If user presses Activate schedules

    - posting the schedule for first time with reference1

     

    It doestn work...

    And if I check the log there are hundreds if timers created

    5 minutes ago, Neo Andersson said:

     

     

     

     

     

     

     

     

    1 minute ago, Neo Andersson said:

    And if I check the log there are hundreds if timers created

     

    *of

    Link to comment
    Share on other sites

  • Topic Author
  • Obviously something wrong with your code  - shouldn't be more than two timers per irrigation loop.

    You could PM me the QA and I can have a look at it - I may learn something.

    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.

     Share

    ×
    ×
    • Create New...