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

2 hours ago, jgab said:

instead of just queuing up the event structure (with much less memory requirement). Events  that will then be consumed by a single running instance polling the queue in a loop.

 

And avoiding the penalty of starting a new Lua environment...

 

I think, this would help me:

 

Please login or register to see this code.

 

But that is more or less what you have written if I'm correct...

 

Edited by petergebruers

Share this post


Link to post
Share on other sites
  • Topic Author
  • @petergebruers 

    Yes, I guess there is a "cold start" penalty for scene instances. However, starting a Lua scene instance doesn't seems to take that much time - but I would expect it to eat some memory.  

    The "read queue" is more or less what I have implemented - but Fibaro could make it much more efficient and there would be no real need for having "max allowed instances"... On top of a read_queue primitive one can then add all kind of fancy event dispatching handlers or domain specific script languages...

    Having people loop and read events is no more dangerous (or easy to get wrong) than driving people to do while-sleep loops in scenes and killing events with countScenes()>1...

    Share this post


    Link to post
    Share on other sites
    4 hours ago, jgab said:

    Yes, I guess there is a "cold start" penalty for scene instances.

    About 0.1 second on a HC2 running 4.512 IMHO. It hurts CPU as well.

     

    4 hours ago, jgab said:

    countScenes()>1

    That does not always work because 2 instances can run at the same time, and both will have scene count 2.

    Test case: momentary switch -> qubino relay module. Quickly press button (as you may have guessed, < 100 ms "on" time) and 2 instances start, one for "on" and one for "off". Both will have scene count 2. Not tested on 4.512 but 4.510 or 4.511...

    • Like 1

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • 1 hour ago, petergebruers said:

    About 0.1 second on a HC2 running 4.512 IMHO. It hurts CPU as well.

     

    That does not always work because 2 instances can run at the same time, and both will have scene count 2.

    Test case: momentary switch -> qubino relay module. Quickly press button (as you may have guessed, < 100 ms "on" time) and 2 instances start, one for "on" and one for "off". Both will have scene count 2. Not tested on 4.512 but 4.510 or 4.511...

    Yes, if there are many quick triggers the HC2 will startup parallel instances and the countInstances() is only a way to close down instances after they started. I do expect, but I didn't test, that the "set max instances" would limit the number of instances spun up by the HC2 in the first place.

    Yes, I seen that behaviour when countScenes report wrong (just do a couple of quick startScene from another scene... Doesn't seem that it should be that difficult to synchronize a correct scene count. Although, I haven't seen it reporting 1 when there really were 2 or more scenes... knock on wood...

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • Made a small ping-pong test.

    Scene 1

    Please login or register to see this code.

    Scene 2

    Please login or register to see this code.

    ...and get ~0.13s consistently with all other scenes on the HC2 stopped. Running 4.510. 

    If I make an EventRunner scene 1

    Please login or register to see this code.

    and a corresponding Scene 2

    Please login or register to see this code.

    I get ~0.35 to ~0.37 (random GCs adds a lot)

    0.37-0.13 = 0.24ms. And considering that I only poll the mailbox every 250ms that makes for acceptable

    • Thanks 1

    Share this post


    Link to post
    Share on other sites

    @jgab 

    have you change the behavior of  csEvent?
    This did work before my latest update from GitHub

    Please login or register to see this code.

    Get this error now.

    Please login or register to see this code.

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • @jompa68 Yes, sorry about that. It changed in the last version. I have updated the "

    Please login or register to see this link.

    ". It now uses the ':prop' syntax.

    I will start to update a changelog going forward and up the version numbers too.

     

    'ID:scene' - :scene returns sceneActivation value (button clicked value) of the device

    Please login or register to see this code.

    'ID:central' - CentralSceneEvent - returns the 'data' portion of the event

    Please login or register to see this code.

    'ID:access' - AccessControlEvent- returns the 'data' portion of the event

    Please login or register to see this code.

    Edited by jgab

    Share this post


    Link to post
    Share on other sites

    @jgab

    will this logics work? 

    Please login or register to see this code.

    If power is less than 0.5 for 10minutes then powerOff water

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • now is a moving target so that wouldn't work 

    Isn't it this you want?

    Please login or register to see this code.

     

    Share this post


    Link to post
    Share on other sites
    1 hour ago, jgab said:

    now is a moving target so that wouldn't work 

    Isn't it this you want?

    Please login or register to see this code.

     

    If power have been less than 0.5 for 10 minutes then xxxx is what i try to accomplish 

    Share this post


    Link to post
    Share on other sites

    Hi @jgab, I have now running dozens of rules. Many of them with the same variables but with different combinations of conditions. I was wondering, is it possible to introduce some kind of hierarchy to reduce the number of rules?

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • 2 hours ago, jompa68 said:

    If power have been less than 0.5 for 10 minutes then xxxx is what i try to accomplish 

    and if power is less than 0.5 for 10 minutes that rule should work - doesn't it work?

    1 hour ago, 3JL said:

    Hi @jgab, I have now running dozens of rules. Many of them with the same variables but with different combinations of conditions. I was wondering, is it possible to introduce some kind of hierarchy to reduce the number of rules?

    Like only run a certain set of rules only when a variable is set to a specific value? e.g. eval("$HomeStatus=='home' & ... => ...")

    I'm thinking about a way to enable and disable rules conditionally, and that could solve some of this, because one could have a rule triggering on the variable and enabling/disabling other sets of rules.

    However, sometimes it's possible to have pre conditions that spawn new events that check for sub conditions. Do you have some examples of your rules that I can see if it's possible to rewrite?

     

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • This is a changelog for EventRunner framework - the post will be updated for every new (significant) update.

     

    v1.6, Dec 17, 2018

    New version, v1.6, of EventRunner. Update EventRunner.lua, EventRunnerDebug.lua, example_rules.lua

    Lot's of changes but mostly internal stuff . Most changes are in EventRunnerDebug, so there shouldn't be much affecting (live) HC2 versions.

     

    -Complete rewrite of setTimeout on ZBS (doesn't affect HC2). The framework depends on setTimeout for scheduling rules and posting events, and Lua/ZBS doesn't have a setTimeout. I used to have home cooked version that worked, but now it is implemented with Lua's coroutines which makes it much more robust and cleaner and allows for mixing setTimeout with fibaro:sleep etc. I hope this will allow me to add more features like stepping through time etc (It is also a preparation for reusing EventRunnerDebug.lua  to implement a framework that can run standard HC2 scenes (and VDs), and several in parallell... a nice Xmas project). I have tested it quite extensively but there can still be bugs - it's like replacing the heart of the code, and I may have overlooked something...

     

    -Incompatible changes; _setClock, and _setMaxTime is replaced by _System.setTime(string starttime, int number). Ex. _System.setTime("08:00", 24*30), start simulation at 08:00 and run for 30 days.

     

    -EventRunner.lua. Fixed parsing of scene headers when running without debug in ZBS. Fix {}:safe to return true.

     

    -Log output in ZBS uses colors like on the HC2.

    ----------------------------------------------------------------------------------------------------

    v1.5, Dec 14, 2018

    - Support to enable/disable rules & event handlers.

    Please login or register to see this code.


      - Possible to group rules & event handlers in sections

    Please login or register to see this code.

    - Trigger window to post triggers parsed from the scene header (see

    Please login or register to see this link.

    )

    - _GLOBALS is available when running offline to initialize global variables. Needs to be set outside before the declaration of 'main()'

     _GLOBALS={timeOfDay='Night', alarm='10:00'} will initialize the offline version of the globals to the values specified, without causing a trigger because the variable changed. There is also a Util.defineGlobals(<table>) to do the same, but possible to call within 'main()'
    - bug fixes

     

    ------------------------------------------------------------------------------------------------------------------------------------------------------

    v1.4, Nov 28, 2018

    -Trigger logic for EventScript rewritten (much cleaner!)
      Logic expressions in left-hand of rules for event triggers is now allowed
      Rule.eval("#foo & 55:isOn & 11:00..12:00 => log('Hurray')")
      In fact, expressions like this works
      Rule.eval("(#foo{val='a'} | #bar{val='a'}) & 55:isOn => log('val=%s',a)")
      So, open coded event expression in the left hand will be used as trigger (event handlers).
      
    -There is a new function Util.printRule(rule) that will list the event handlers (triggers) of a rule
     Util.printRule(Rule.eval("(#foo{val='a'} | #bar{val='a'}) & 55:isOn => log('val=%s',a)"))
     ...will result in
     08:57:02:Wed Nov 28: -----------------------------------
     08:57:02:Wed Nov 28: Source:'(#foo{val='a'} | #bar{val='a'}) & 55:isOn => log('val=%s',a)'
     08:57:02:Wed Nov 28: Trigger({"type":"bar","val":"a"}) =>...
     08:57:02:Wed Nov 28: Trigger({"type":"property","deviceID":55,"propertyName":"value"}) =>...
     08:57:02:Wed Nov 28: Trigger({"type":"foo","val":"a"}) =>...
     08:57:02:Wed Nov 28: -----------------------------------
     ...and we can see that it creates trigger for the 'bar' and 'foo' event, and for the deviceID 55.
     
    -Error handling cleaned up. Still many unclear error messages but the logic is there now to improve it
    -Many small bugs fixed; local vars could not be set to 'false' etc.


    ------------------------------------------------------------------------------
    v1.3, Nov 18, 2018

    -Fixed error in central/access property introduced by "definition time trigger" below.

    -(Fixed errors where trigger rules were not run at definition time.) REVERTED for now.

     E.g. Rule.eval("5:isOff => log('x')") would not trigger if 5 was already off when rule defined and only trigger the first time that 5 changed value. This was also true for the 'for' construct.
    -More effective lookup of 'property' and 'global' triggers
    -Built-in support for 'ping'
     {type=Event.PING} => Event.postRemote(sender,{type=Event.PONG})
     Event.PING == '%%PING%%'
     Event.PONG == '%%PONG%%'
    -Better handling of HomeTable struct when running offline
     If _deviceTable is defined then fibaro:getGlobal(_deviceTable) results in _deviceTable..".data" is read in from a file in the working directory.
     This means that it is possible to have many device data files
    -Support for Event.trueFor(time,event,action)
     Only works with with 'property' and 'global' events and require the 'value' field to have a constraint.
     Ex. Event.trueFor("+/00:10",{type='property',deviceID=8, value='$>0},
                        function(env) Log(LOG.LOG,"Device 8 have been on for 10min") end)
      This works because we can create a "negative" event pattern for these kind of events. 

    Edited by jgab

    Share this post


    Link to post
    Share on other sites

    There are some errors in version 1.3 (working rules in 1.2)

     

    Error1:

    Please login or register to see this code.

    [DEBUG] 22:21:46: Error in 'ElectroPlugs:power => d=env.event.deviceID; log('Zmena napajeni v zasuvce %s id:%s v %s',d:name,d,d:roomName)': attempting to index non table with key:'deviceID'

     

    Error2:

    Please login or register to see this code.


    [DEBUG] 21:44:03: Error in 'key=Pracovna.Tlacitko4tlprac:central => log('Tlacitko pracovna u postole: key=%s %s',key.keyId,key.keyAttribute);
    [DEBUG] 21:44:03: || key.keyId=='1' & key.keyAttribute=='Pressed' >> Pracovna.Svetlolustr:btn=1;log('Tlacitko LN pracovna u postele - svetlo strop')
    [DEBUG] 21:44:03: || key.keyId=='2' & key.keyAttribute=='Pressed' >> Pracovna.Svetloustolu:btn=1;log('Tlacitko PN pracovna u postele - svetlo u stolu')
    [DEBUG] 21:44:03: || key.keyId=='3' & key.keyAttribute=='Pressed' >> Pracovna.VypZapPC:btn=2;log('Tlacitko LD pracovna u postele - zapnuti PC')
    [DEBUG] 21:44:03: || key.keyId=='4' & key.keyAttribute=='Pressed' >> Pracovna.VypZapPC:btn=3;log('Tlacitko LD pracovna u postele - vypnuti PC')': /opt/fibaro/scenes/217.lua:1073: /opt/fibaro/scenes/217.lua:292: bad argument #2 to '_format' (no value)
     

    And what is the correct format pro PING and PONG? Could you add some examples (for both sides)?

    I have some error messages with "bad event format" ...

    Please login or register to see this code.

     

    Edited by petrkl12

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • 25 minutes ago, petrkl12 said:

    There are some errors in version 1.3 (working rules in 1.2)

     

    Error1:

    Please login or register to see this code.

    [DEBUG] 22:21:46: Error in 'ElectroPlugs:power => d=env.event.deviceID; log('Zmena napajeni v zasuvce %s id:%s v %s',d:name,d,d:roomName)': attempting to index non table with key:'deviceID'

     

    Error2:

    Please login or register to see this code.


    [DEBUG] 21:44:03: Error in 'key=Pracovna.Tlacitko4tlprac:central => log('Tlacitko pracovna u postole: key=%s %s',key.keyId,key.keyAttribute);
    [DEBUG] 21:44:03: || key.keyId=='1' & key.keyAttribute=='Pressed' >> Pracovna.Svetlolustr:btn=1;log('Tlacitko LN pracovna u postele - svetlo strop')
    [DEBUG] 21:44:03: || key.keyId=='2' & key.keyAttribute=='Pressed' >> Pracovna.Svetloustolu:btn=1;log('Tlacitko PN pracovna u postele - svetlo u stolu')
    [DEBUG] 21:44:03: || key.keyId=='3' & key.keyAttribute=='Pressed' >> Pracovna.VypZapPC:btn=2;log('Tlacitko LD pracovna u postele - zapnuti PC')
    [DEBUG] 21:44:03: || key.keyId=='4' & key.keyAttribute=='Pressed' >> Pracovna.VypZapPC:btn=3;log('Tlacitko LD pracovna u postele - vypnuti PC')': /opt/fibaro/scenes/217.lua:1073: /opt/fibaro/scenes/217.lua:292: bad argument #2 to '_format' (no value)
     

    And what is the correct format pro PING and PONG? Could you add some examples (for both sides)?

    I have some error messages with "bad event format" ...

    Please login or register to see this code.

     

    I started to run each rule once when they were defined. This doesn't work because your rule "ElectroPlugs:power => " is always 'true' . ElectroPlugs:power returns {} if there is no event yet... Anyway, I reverted that patch and pushed a new version (still 1.3) so you old code should work. I have to re-think how this should behave because I would like a rule type "5:isOn => ..." to run if 5 is on when the rule is defined. Now it won't trigger until the first event.

    I'll come back on the PING thing. But if you do a Event.postRemote(otherSceneID,{type=Event.PING}), the other scene should answer with a {type=Event.PONG}

    Share this post


    Link to post
    Share on other sites
    On 10/21/2018 at 7:21 PM, jgab said:

    'ID:access' - AccessControlEvent- returns the 'data' portion of the event

    Please login or register to see this code.

    is this correct?

    Please login or register to see this code.

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • 6 minutes ago, jompa68 said:

    is this correct?

    Please login or register to see this code.

     

    Should it be ”Unlock” instead of ”Unlocked”? I don’t have a lock/keypad so I can’t check.

    Share this post


    Link to post
    Share on other sites
    1 hour ago, jompa68 said:

    Thanks, will try on my lunch :)

    Did not work. Seems to be different types when lock and unlock

     

    Please login or register to see this code.

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • 1 hour ago, jompa68 said:

    Did not work. Seems to be different types when lock and unlock

     

    Please login or register to see this code.

     

    Ok, it's

    812:access.status=='Lock' , 812:access.status=='Unlock'

    Please login or register to see this code.

     

    Share this post


    Link to post
    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...