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)
4 hours ago, jgab said:

Event react immediately when the device change state, if you pol you need to choose an interval.

Event also makes a http request with 30s timeout. E.g. if an event happens while it waits it returns immediately, if there is no event within 30s it will make another 30s requests. This is more efficient than continuously polling.

Alos, Events only runs one request loop for all device states you want to check.

However, if you have a termometer where you are only interested in values every 10min, you can as easily do a poll every 10min.

 

 

and what about the refreshState subscriptions? I guess it iwll be similar to fibaro.event right?

 

Becaus here I have a pretty complex task.

User has a PV panel, and 9 heating sprails. What he wants is:

 

Every time the oveproducton of PV (so that would go back to grid) is over a certain treshold, for a ceratin time (30sec) we should turn on his one spiral, that consumes 1000 watts. So over 1000 watts turn on one spiral. In that moment ofcourse the value back to grid drops by 1000 watts, because we turned on that spiral. Now when the PV starts generate even more watts, so that the overproduction gets over 1000 watts again, we turn on anotehr spiral and so on. This would not be that hard to solve by fibaro.event. However, we need to take care of situations when the PV overproduction is getting lower than a certain treshold, like 15- watss, we need to turn off one spiral..etc..all spiral turn ON processes should however wait 30 sesonds, so to be sure, that it is staying above the reshold and it was not just an abrubpt peak voltage. That is the main challenge for me to do this with fibaro event. 

 

So when the PV overproduction is over the treshold (given for turning on a spiral ) i need to wait 30 second then if it is still over i turn on one spiral.

 

The 30 sec counter should always restart if the overpoduction drops below treshold.

 

 

Edited by Neo Andersson
  • Topic Author
  • Posted
    15 hours ago, Neo Andersson said:

    and what about the refreshState subscriptions? I guess it iwll be similar to fibaro.event right?

     

    Becaus here I have a pretty complex task.

    User has a PV panel, and 9 heating sprails. What he wants is:

     

    Every time the oveproducton of PV (so that would go back to grid) is over a certain treshold, for a ceratin time (30sec) we should turn on his one spiral, that consumes 1000 watts. So over 1000 watts turn on one spiral. In that moment ofcourse the value back to grid drops by 1000 watts, because we turned on that spiral. Now when the PV starts generate even more watts, so that the overproduction gets over 1000 watts again, we turn on anotehr spiral and so on. This would not be that hard to solve by fibaro.event. However, we need to take care of situations when the PV overproduction is getting lower than a certain treshold, like 15- watss, we need to turn off one spiral..etc..all spiral turn ON processes should however wait 30 sesonds, so to be sure, that it is staying above the reshold and it was not just an abrubpt peak voltage. That is the main challenge for me to do this with fibaro event. 

     

    So when the PV overproduction is over the treshold (given for turning on a spiral ) i need to wait 30 second then if it is still over i turn on one spiral.

     

    The 30 sec counter should always restart if the overpoduction drops below treshold.

    refreshState subscriptions are similar but is using a less efficient way of looking up the function handler. In fact, it seems to just go through all the registered subscription handlers and it is up to the coder to do the right thing. fibaro.event makes an efficient hash-lookup for the right handler depending on the event-patten provided.

     

    I don't see why your usecase would be challenging with fibaro.event (compared to anything else). in the handlers you need to set addition timers for the waits...

    Posted
    3 hours ago, jgab said:

    refreshState subscriptions are similar but is using a less efficient way of looking up the function handler. In fact, it seems to just go through all the registered subscription handlers and it is up to the coder to do the right thing. fibaro.event makes an efficient hash-lookup for the right handler depending on the event-patten provided.

     

    I don't see why your usecase would be challenging with fibaro.event (compared to anything else). in the handlers you need to set addition timers for the waits...

    Its challenging becuase i was not able to interupt the timer inside the eventhandler when its needed. We were talking about it in other topics. For some reason fibaro.clearTimeout(ref) did not stop the (ref) timer, and i did not want to bother you with this again, so we rather went for the polling way. We deleted fibaroExtra, and started using the looping, an then the clearTimeout worked.

     

    Anyway it seems to me from your anwers that using fibaro.event, is definitely the way to go, the only reason i hesitate to use it, becuase i need the whole fibaroExtra modul for it, and it seems to me too much. If we only had an event modul separatelly from fibaroExtra, taht would change the whole situation. Like my code for that customer has some 4000 lines, and using fibaroExtra just because of event handling seems to me inappropriate. A lon time ago we talked about this, so you wrote that maybe some day there will be some moduls from fibaroExtra that can be used separatlelly..but we never talked about it again.

    Posted
    3 hours ago, Neo Andersson said:

    Its challenging becuase i was not able to interupt the timer inside the eventhandler when its needed. We were talking about it in other topics. For some reason fibaro.clearTimeout(ref) did not stop the (ref) timer, and i did not want to bother you with this again, so we rather went for the polling way. We deleted fibaroExtra, and started using the looping, an then the clearTimeout worked.

     

    Anyway it seems to me from your anwers that using fibaro.event, is definitely the way to go, the only reason i hesitate to use it, becuase i need the whole fibaroExtra modul for it, and it seems to me too much. If we only had an event modul separatelly from fibaroExtra, taht would change the whole situation. Like my code for that customer has some 4000 lines, and using fibaroExtra just because of event handling seems to me inappropriate. A lon time ago we talked about this, so you wrote that maybe some day there will be some moduls from fibaroExtra that can be used separatlelly..but we never talked about it again.

     

    Hi ill join the conversation if it is okey :D

    I think @jgab made what you ask for :) The event lib. Or am i wrong jgab? :) I am using it on all my quickapps to get fast actions inside the QA. 
     

     

     

     

     

    Posted
    42 minutes ago, Brors94 said:

     

    Hi ill join the conversation if it is okey :D

    I think @jgab made what you ask for :) The event lib. Or am i wrong jgab? :) I am using it on all my quickapps to get fast actions inside the QA. 
     

     

     

     

     

    I did not know about this,.,I will check, thanks

    • Like 1
    Posted
    2 minutes ago, Neo Andersson said:

    I did not know about this,.,I will check, thanks


    Yea, it is hard to find everything on this forum 😅 

    Only good site too find things is this site that jgab made: 



     

    Posted
    25 minutes ago, Brors94 said:


    Yea, it is hard to find everything on this forum 😅 

    Only good site too find things is this site that jgab made: 



     

    It doesnt trigger for me

     

    Please login or register to see this code.

     
    doesn nothing
    Posted (edited)

    @Neo Andersson

     

    Test 

    local sensor_id = self.sensor

     

    and then insert sensor_id insted on id=

    Please login or register to see this code.

     

    as I understand it the   self.    is redefined in the eventlib, So you have to make local vars the reference the self.sensor 🤔

     

    or have you defined 

    this? 

     

    Please login or register to see this code.

     

     

     

     

     

    Edited by Brors94
    Posted
    14 minutes ago, Brors94 said:

    @Neo Andersson

     

    Test 

    local sensor_id = self.sensor

     

    and then insert sensor_id insted on id=

    Please login or register to see this code.

     

    as I understand it the   self.    is redefined in the eventlib, So you have to make local vars the reference the self.sensor 🤔

     

    or have you defined 

    this? 

     

    Please login or register to see this code.

     

     

     

     

     

    will try, yes Event was defined

    Posted
    5 minutes ago, Neo Andersson said:

    will try, yes Event was defined

    Nothing...doesnt trigger

    Posted

    this has to be defined to 😅 

     

    Event.id='start'
    Event{type='QAstart'}
    function Event:handler(event)
      Event:attachRefreshstate()
    end

     

    It might not be based on same as fibaro.event afterall 😅

     

    Please login or register to see this attachment.

     

     



     
    function QuickApp:turnOn()
        self:debug("binary switch turned on")
        self:updateProperty("value", true)
    end
     
    function QuickApp:turnOff()
        self:debug("binary switch turned off")
        self:updateProperty("value", false)    
    end



     
    local Event = Event_std
    Event.id='start'
    Event{type='QAstart'}
    function Event:handler(event)
      Event:attachRefreshstate()
    end


     
    function QuickApp:onInit()
        self:debug("onInit")
     
    local sensor_id = 2135
     
      Event.id='_'
      Event_std.tagColor='Orange'
      Event {type='device', id={sensor_id}, property='value'}
      function Event:handler(event)
     
      print("-----")
        self:debug("ID: ",event.id,"value: ",event.value)
        if (event.value==true and event.id == sensor_id) then
          self:debug("ON1  ID: ",event.id,"value: ",event.value)
        elseif self:trueFor(1000,event.value==false)  then
          self:debug("OFF1  ID: ",event.id,"value: ",event.value)
        end
      end
     
    end -- onInit
     



     

     

     

     

     

    Posted
    6 minutes ago, Brors94 said:

     

    It might not be based on same as fibaro.event afterall 😅

    Yes that was the reason...its working now, but its strange..how could i miss that..is that stated anywhere in the descirption? am i blind?

    1 minute ago, Neo Andersson said:

    Yes that was the reason...its working now, but its strange..how could i miss that..is that stated anywhere in the descirption? am i blind?

    Actually it is mentioned, but i skipped that part as it stated this for HC2

     

    "To get events from the HC2, ..."

    • Like 1
    Posted (edited)

    4th topic in the eventlib

    I have mad a standard "code/script" i pass into all quickapps so forgot that part 😅



    I use it on all my quickapps for cronejobs and triggers :) 

    I am actually trying to make a quickapp to control a 5000L waterheater powered by 12 relay like you are :)
    And checking for solar production and electricty prices too :D 


    But only started with layout and thinking of the functionality of the quickapp. 

     

    This is my Room controller made with it if you want to check it out :) 

     

     

    It acts on profile changes, get name of all light devices in the room.

    acts on motion events and set it for each profile

    you can also set 6 light scenes and make the pir trigger on :)
     

    image.png.f34e752072c6189fa02dcb7b68c04c7e.png

    image.png.a69f4f8b7b79a77646e03cc69d0baa99.png

    image.png.020c5fdaa6e2e9b17152e795ab5b891a.png

     

    Edited by Brors94
    Pics
    Posted
    2 minutes ago, Brors94 said:

    4th topic in the eventlib

    I have mad a standard "code/script" i pass into all quickapps so forgot that part 😅



    I use it on all my quickapps for cronejobs and triggers :) 

    I am actually trying to make a quickapp to control a 5000L waterheater powered by 12 relay like you are :)
    And checking for solar production and electricty prices too :D 


    But only started with layout and thinking of the functionality of the quickapp. 

     

    This is my Room controller made with it if you want to check it out :) 

    Please login or register to see this attachment.

     

    It acts on profile changes, get name of all light devices in the room.

    acts on motion events and set it for each profile

    you can also set 6 light scenes and make the pir trigger on :)
     


     

    It turned out that you are right, We can not use self variables inside the Event definitions or handlers..

    Posted

    Yea, Jgab have redefined self. inside them 😅 

    I usually make a function linked to the event to be able to use them or a local that reference the self. u want to use :)

    like this: 

     

     
      Event.id='_'                            
      Event {type='device', id=dimmer2s2, property="sceneActivation", value=20}
      function Event:handler(event)
        Dimmer2Pir = 1
        funPirStatusOn()
        self:debug("Dimmer2pirON")
      end
     
     
    function funPirStatusOn()
    self.store.pir_status = "Detected"
    cancel_timers()
      if self.store.houseprofil == profil_table_name[1] then
            check_pir_on_p1()
        elseif self.store.houseprofil == profil_table_name[2] then
            check_pir_on_p2()
        elseif self.store.houseprofil == profil_table_name[3] then
            check_pir_on_p3()
        elseif self.store.houseprofil == profil_table_name[4] then
            check_pir_on_p4()
      end
    update_pir_status()
      --print("Houseprofil: ",self.store.houseprofil)
      --print("profil_table_name: ",profil_table_name[1])
    end
     
     



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