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

3 minutes ago, jgab said:

Assume you have a real switch with id 784.

Please login or register to see this code.

Whenever the value of 784 changes it will publish that to all other scenes that subscribe to #VirtualSwitch.

Subscribers would do

aaah that was the thing i did miss. Sorry and thanks for the other examples

Link to comment
Share on other sites

  • Topic Author
  • 7 hours ago, jgab said:

    Ah, but the pattern/hack #event{device=<table of IDs>} only works for event of type 'property'. I guess I could extend it to any type of event. However that means you can't have any event with field deviceID that should be a table. We could try it and see what happens. Maybe a log message that says that the rule is expanded.

    Anyway, I'm on a business trip until Thursday so my coding time is limited for now. Will come back one this.

     

    Ok, pushed a version that expands events with a deviceID that is a list, e.g.

    rule(#foo{deviceID={1,2,3}} => true")

    will be rewritten internally as 

    rule("#foo{deviceID=1} | #foo{deviceID=2} | #foo{deviceID=3} => true")

    So, events with a deviceID field are treated specially for now. Let me know if it creates problems.

     

    Link to comment
    Share on other sites

    I don't know what you send to VirtualSensors, you can try:

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • Well, it's not that easy.

    Please login or register to see this code.

    First, there was a bug in 'for'... I think - I have pushed a new version of EventRunner.lua. It's very subtle bug that's been there for a year. Thanks for really testing the code :-) 

    Anyway, It's a bit complicated to achieve what you want.

    You see what I did in the rule above? I moved the value test out of the matching in the event to a separate test.

    The reason is that the event inside the for becomes a trigger for the rule.

    If the event is written like

    Please login or register to see this code.

    it will only trigger the rule if the value is '0'. However, we also want it to trigger the rule when value is not '0' because we want the 'for' instruction to stop the timer in that case.

    We can achieve that by moving out the value test. The rule will always trigger on a #VirtualSensor event, and if value=='0' for 10s the 'for' instruction will return true and execute the rest of the rule.

    Btw, the '$id' will match any deviceID. Is it the Wc.Fan id?

    Link to comment
    Share on other sites

    @jgab

     

    Is it possible to do it this way? I'm not sure ... because all sensors have to be 0 ...

    Is there any command like ALL?

    Please login or register to see this code.

    I guess it will create 3 rules:

    Please login or register to see this code.

     

    Edited by petrkl12
    Link to comment
    Share on other sites

  • Topic Author
  • No, there is not an ALL for user defined events. 

    In your case, do you have WcVirtualSensors sent from other scenes to this scene, and this scene wants to test if all (100,101,103) are off for 10 seconds  ?

    I'm asking because I not sure what you are trying to achieve.

    I would try to aggregate events like in the motion sensor example in

    Another approach, if the deviceIDs are real ids, would be to do in the receiving scene

    Please login or register to see this code.

    So, the receiving scene don't  declare the device triggers in the scene header. The rule is triggered only on an incoming #VirtualSwitch and then checks the values of 100,101,103

    However, I don't feel that the receiving scenes shouldn't need to know what devices there are...

     

    Lastly, create a fake deviceID with Event._registerID that behaves as the combination of several real or fake deviceIDs (safe, breached etc). However I haven't developed this concept truly yet and I think there could be helper functions to define such combined devices. The advantage is that :isOn, :safe etc all would work on those. 

    Link to comment
    Share on other sites

    Ah, now i started to understand how it works with publish/subscribe pattern, thanks for all your help.

    Please login or register to see this code.

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    22 hours ago, jgab said:

    rule("subscribe(#room)") rule("#room{safe=true,id='$id'} => log('Room %s is safe',id)") rule("#room{safe=false,id='$id'} => log('Room %s is breached',id)")

    i cannot see that "roomID" is implemented in the code, so this does not work at the moment.

    Link to comment
    Share on other sites

  • Topic Author
  • 51 minutes ago, jompa68 said:

    i cannot see that "roomID" is implemented in the code, so this does not work at the moment.

    No it’s not. You have to make your own function for now.

    on my todo.

    My thinking with the example was that the room that publish that the room is safe also should now what room it is...

    • Like 1
    Link to comment
    Share on other sites

    @jgab Houston I have a problem.. I am trying to transfer my markiscenes (I have 4 different scenes) to ER and make it just one scene. When I tried to make an average of luxreadings I did not succed. Then I simplified the rule, setting luxreading to 1200 just for testing. But ….

     

     rule([[@@00:02 => 
         || (antal < 5) >> antal=antal+1; a = a + 1200; log('antal= %s a= %s',antal,a)
         || (antal == 5) >> b = (a/antal); log('b= %s antal= %s',b,antal); antal = 0; a = 0
         ]])

    Shouldn't b become 1200? Or what am I doing wrong? When I change a to 6000 and antal to 5 b will become 1200! 

     

    16:49:25:Tue Feb 26: Demo - EventRunner v1.15 fix4
    16:49:25:Tue Feb 26: Sunrise 06:54, Sunset 17:08
    16:49:25:Tue Feb 26: Starting:02/26/19 16:49:25, Ending:02/28/19 16:49:25 (speeding)
    16:49:25:Tue Feb 26: Emulating local Fibaro API
    16:49:25:Tue Feb 26: Remote Event listener started at 192.168.1.127:6872
    16:49:25:Tue Feb 26: Hue system inited (experimental)
    16:49:25:Tue Feb 26: 
    16:49:25:Tue Feb 26: Loading rules
    16:49:25:Tue Feb 26: Initiated 1 globals from 'globals.data'
    16:49:25:Tue Feb 26: Rule:1:@@00:02 => 
    16:49:25:Tue Feb 26: 
    16:49:25:Tue Feb 26: Scene running
    16:49:25:Tue Feb 26: antal= 1 a= 1200
    16:51:25:Tue Feb 26: antal= 2 a= 2400
    16:53:25:Tue Feb 26: antal= 3 a= 3600
    16:55:25:Tue Feb 26: antal= 4 a= 4800
    16:57:25:Tue Feb 26: antal= 5 a= 6000
    16:59:25:Tue Feb 26: b= 6000 antal= 5
    17:01:25:Tue Feb 26: antal= 1 a= 1200
    17:03:25:Tue Feb 26: antal= 2 a= 2400
    17:05:25:Tue Feb 26: antal= 3 a= 3600
    17:07:25:Tue Feb 26: antal= 4 a= 4800
    17:09:25:Tue Feb 26: antal= 5 a= 6000
    17:11:25:Tue Feb 26: b= 6000 antal= 5
     

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, FrankT said:

    @jgab Houston I have a problem.. I am trying to transfer my markiscenes (I have 4 different scenes) to ER and make it just one scene. When I tried to make an average of luxreadings I did not succed. Then I simplified the rule, setting luxreading to 1200 just for testing. But ….

     

     rule([[@@00:02 => 
         || (antal < 5) >> antal=antal+1; a = a + 1200; log('antal= %s a= %s',antal,a)
         || (antal == 5) >> b = (a/antal); log('b= %s antal= %s',b,antal); antal = 0; a = 0
         ]])

    Shouldn't b become 1200? Or what am I doing wrong? When I change a to 6000 and antal to 5 b will become 1200! 


     

    Really sorry, basic division was broken since some versions ago because of a typo  - I have added it to my test case so it shouldn't be repeated.

    Pushed a new version.

     

    Link to comment
    Share on other sites

    Experience that the pub/sub function is a bit too slow to use in a live environment. Takes 3-4 seconds before the subscribed scene gets the value.

    Anyone else who experiences the same thing?

    Link to comment
    Share on other sites

  • Topic Author
  • 2 minutes ago, jompa68 said:

    Experience that the pub/sub function is a bit too slow to use in a live environment. Takes 3-4 seconds before the subscribed scene gets the value.

    Anyone else who experiences the same thing?

    No I haven't experienced that.

    There is nothing especially compute intensive to do it. Just a quick filtering before sending, but that is in the range of milliseconds. Then it is a fibaro:startScene and that we can't control. Normally a startScene takes ~100ms and then we add the overhead of ER but I would expect 300-500ms.

    In 4.530 I have seen strange slowdown of the HC2 especially if I have the web GUI open to see the log of many scenes. But I haven't been able to reproduce it.

    If you want to pm me the code I can take a look at it?

    /J

    Link to comment
    Share on other sites

    When i setup same devices in a blockscene the respond time is ms but with ER it is 3-4 seconds

    Please login or register to see this image.

    /monthly_2019_02/image.png.fc48a618f6a358ba6c5595afa05331f4.png" alt="image.png.fc48a618f6a358ba6c5595afa05331f4.png" />

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    Really sorry, basic division was broken since some versions ago because of a typo  - I have added it to my test case so it shouldn't be repeated.

    Pushed a new version.

     

    No problem, thank you jgab@

    Link to comment
    Share on other sites

  • Topic Author
  • 6 hours ago, jompa68 said:

    When i setup same devices in a blockscene the respond time is ms but with ER it is 3-4 seconds

    Please login or register to see this link.

    Please login or register to see this code.

     

     

    That feels like something is buggy with ER. Is this something you have started to notice in the last version(s)?

    Tomorrow I will do some tests on my HC2 and try to figure out what's going on...

    Link to comment
    Share on other sites

    From the published scene to subscribed scene i would say it is ms, so it is when a device is triggered it takes 2-4 seconds before the code is executed.
     

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