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


jgab

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

    • 2 weeks later...

    Hi 

    I am new with this tema. Can you give an example? 

    • function QuickApp:getView(elm,prop)                      -- Get value of UI element

    At elm and prop what comes in and in what format??

    An example, please. 

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, parip69 said:

    Hi 

    I am new with this tema. Can you give an example? 

    • function QuickApp:getView(elm,prop)                      -- Get value of UI element

    At elm and prop what comes in and in what format??

    An example, please. 

     

    All QA controls have an "ID", if you open the QA editor and look at the controls you get the IDs. Labels, buttons and Sliders have IDs.

    self:getView('myLabel',"text") retrieves the text of the Label with id "myLabel"

     

    Link to comment
    Share on other sites

    Danke schön. 

    I have installed the fibaroExtra. 

    I would like to read the value from a slider. 

    With the example from above, I can't do that. 

    print(self:getView(sliderID, "value")) 

    How do I have to do this?

    Thank you againThank you again. 

     

     

    Why do you get this message?

    attempt to index a nil value (global 'self')

    Edited by parip69
    Link to comment
    Share on other sites

    • 4 weeks later...
    On 12/25/2021 at 10:14 PM, parip69 said:

    Danke schön. 

    I have installed the fibaroExtra. 

    I would like to read the value from a slider. 

    With the example from above, I can't do that. 

    print(self:getView(sliderID, "value")) 

    How do I have to do this?

    Thank you againThank you again. 

     

     

    Why do you get this message?

    attempt to index a nil value (global 'self')

     

    I think its because you cant get sliders value with getView function..

    To get skiders value you need to call self:getValue(sliderID,"value")..i think

    If you are getting that error message that means, that self object is unreachable at that point of your code. Its not created yet. This means, you are trying to access self object outside of the QA class functions. At least this is what came to my mind at first sight.

    Edited by Neo Andersson
    Link to comment
    Share on other sites

    • 2 months later...

    Hi 

    Please login or register to see this link.

     

    Please login or register to see this link.

    Is it possible to ask for a date or time? Something similar?

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 29 minutes ago, parip69 said:

    Hi 

    Please login or register to see this link.

     

    Please login or register to see this link.

    Is it possible to ask for a date or time? Something similar?

    Please login or register to see this code.

     

     

    Hi,

    Please login or register to see this code.

    is to register handlers for the built in triggers/events that the HC3 generates (like when devices changes states). The same type of triggers you can get in a Scene with the conditions.

    In scenes they have cron triggers but they are not really native HC3 events, but rather generated by the Scene framework.

     

    If you want to run something at a specific time I recommend that you use the fibaro.post and fibaro.event functions that is included in fibaroExtra

    Please login or register to see this code.

     

    The fibaro.event declares a handler for events that matches the event pattern specified, in this car {type='data'}

    When an event is posted that matches the event pattern the handler/function will be called. 

    The matching event is is the argument env.event so we can check other keys of the event.

     

    The fibaro.post(event[,time]) posts an event and the advantage is that we can specify an optional time when the event should be posted.

    The time formats are

    "t/HH:MM" or "t/HH:MM:SS" to post an event exact at the time today. If the time has already passed the event will not be posted

    "n/HH:MM" or "n/HH:MM:SS" will post today or if time has passed, the same time tomorrow.

    "+/HH:MM" or "+/HH:MM:SS" will post at the time offset from the current time.

     

    In the example above we declare a timer for the 'time' event. When the event is handled we print the message and post the same event next day at the same time.

    We start the "loop" by posting the initial event.

     

    fibaro.post returns a reference (like setTimeout) that can be used to cancel the post before it's posted, using fibaro.cancel(ref)

     

    It's simple but very powerful model for running timers at specific times during the day.

    fibaro.event can also be used to declare handlers for the HC3's built-in triggers/handlers.

    Please login or register to see this code.

     

     

    If you give me an example of what you want to accomplish I can try to help you 

     

     

     

    Link to comment
    Share on other sites

    Thank you. My questions have been answered. 

     

    Please login or register to see this code.

     

    OK you can post the time but how do I compare both values in one query?

    Edited by parip69
    Link to comment
    Share on other sites

    You mean date and time? 

    With fibaroextra you can do something like this. There you have date and time in arguments. Here is an example from JGAB's tutorial.

    Please login or register to see this code.

    Link to comment
    Share on other sites

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

    You mean date and time? 

    With fibaroextra you can do something like this. There you have date and time in arguments. Here is an example from JGAB's tutorial.

    Please login or register to see this code.

    yes, so instead of comparing times to find out when something should be done - you post an event for the time you want something done. and then you trigger on that event.

    Edited by jgab
    Link to comment
    Share on other sites

    Please login or register to see this code.

    Hi

    That's only an example.

    OK. At the first condition, I make a post and trigger the event.
    I trigger the second.

    can I get an example with what I put in there further up?

     

     


    But how do I bring them together?

    Can you link me to an example quick app as an example and I will learn from it. I notice that the translation is not so optimal.

     

    Thanks for your patience.

    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.

    ×
    ×
    • Create New...