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

  • Topic Author
  • 15 hours ago, petrkl12 said:

    @jgab

    sometimes I have error in ER4 (usually my or Fibaro mistake :) ) and I also have another QA that in case of any error send me message. ER4 doesn't generate "standard" error (event) so I can't catch it via my QA for errros.

    Is it possible to generate same event as "standard" error in QA or create new ER event that will be possible to use in ER ?

     

    Can you give some example? I use self:error(...), self:warning(...) in ER so it should look similar, or?

    Link to comment
    Share on other sites

  • Topic Author
  • On 1/23/2022 at 2:00 PM, Qwerty1979 said:

    Hi and thanks for a great script.

     

    I´m trying to make some rules like

     

    time =00:05:00

    rule("Motion:breached => Dimmer:on")
    rule("trueFor("..time..",Motion:safe) =>  Dimmer:off")
     
    but then i would like to overide the time to 30 min if lights was turned on manually and keep beieng postponed when breached and after the last 30 min has passed it shold revert back to 5min is this possible can i somehow use this with some timer or something.
     
    Thanks in advance. 

     

     

     

    Try this

    Please login or register to see this code.

    If the dimmer is turned on manually the time is set to 30min.

    When the motion is safe for 'time' minutes the dimmer is turned off and 'time' is reset to 5min.

    'time' being a triggerVar means that when we set it, it will trigger all rules referencing 'time' in the head. That means that the trueFor will be retriggered and will need the sensor to be safe for 30min.

    Link to comment
    Share on other sites

    Thank you jgab.

    but i get an error

    [2022-01-26] [09:56:32] [ERROR] [QUICKAPP98]: in Rule:3[trueFor(time,Motion:safe) =>  Dimmer:off; time=00:01:00]: {"msg":"Error executing instruction:'["trueFor",2]'","ERR":true,"err":"./include/EventRunner.lua:1883: attempt to perform arithmetic on a string value (local 'time')","src":"Rule:3[trueFor(time,Motion:safe) =>  Dimmer:off; time=00:01:00]"}

     

    btw i changed 30min to 5 and 5 min to 1 for testing.

    Many thanks for your help

    Link to comment
    Share on other sites

  • Topic Author
  • 53 minutes ago, Qwerty1979 said:

    Thank you jgab.

    but i get an error

    [2022-01-26] [09:56:32] [ERROR] [QUICKAPP98]: in Rule:3[trueFor(time,Motion:safe) =>  Dimmer:off; time=00:01:00]: {"msg":"Error executing instruction:'["trueFor",2]'","ERR":true,"err":"./include/EventRunner.lua:1883: attempt to perform arithmetic on a string value (local 'time')","src":"Rule:3[trueFor(time,Motion:safe) =>  Dimmer:off; time=00:01:00]"}

     

    btw i changed 30min to 5 and 5 min to 1 for testing.

    Many thanks for your help

    What did you set 'time' to? It seems like it is set to a string according to the error message.

     

    Edited by jgab
    Link to comment
    Share on other sites

    2 hours ago, jgab said:

     

    Try this

    Please login or register to see this code.

    If the dimmer is turned on manually the time is set to 30min.

    When the motion is safe for 'time' minutes the dimmer is turned off and 'time' is reset to 5min.

    'time' being a triggerVar means that when we set it, it will trigger all rules referencing 'time' in the head. That means that the trueFor will be retriggered and will need the sensor to be safe for 30min.

    Hi @jga - what is manual in the Dimmer:manual part referring to ? Can I use that the Logic Group Matrix (terasse.stor.lys:isOff)as well?

    I guess its this part it is referring to

    Quote

    Supported scene events:
      {type='device', id=<number>, property=<string>, value=<value>}
      {type='global-variable', property=<string>, value=<value>}
      {type='date', property="cron", value={ <time> }}
      {type='date', property="sunset", value={ <time> }}
      {type='date', property="sunrise", value={ <time> }}
      {type='manual', property='execute'}
      {type='custom-event', name=<string>}
      {type='device' property='centralSceneEvent', id=<number>, value={keyId=<number>, keyAttribute=<string>}}
     

     

    I have similar rules but like this

    What is pro/cons ? 

    I know my way dont turn Off the switch after x time when manual, i am more interested in the diff programming wise

    Please login or register to see this code.

     

    Edited by ChristianSogaard
    P
    Link to comment
    Share on other sites

  • Topic Author
  • Well, the :manual command returns the number of seconds since the device was manually changed (ex. switched on).

    The way I do it inside the ER engine is to set a flag when the script changes the state of the device.

    If the device's last change was with a script, :manual returns a negative number.

    You cant't trigger a rule on :manual changing value, only check what it is and use it as a condition.

     

    I guess your rule works - you just must be sure that the flag is set and cleared correctly (ex. when lys is turned on/off manually)

     

    The problem with checking if something is manually set is that we don't know if a switch is flipped manually and the script flips it at the same time. If they happen at the same second I let the manual win, but there are always border cases.

    • Like 1
    Link to comment
    Share on other sites

    10 hours ago, jgab said:

    Can you give some example? I use self:error(...), self:warning(...) in ER so it should look similar, or?

    in case of error in standard QA there is generated event - PluginProcessCrashedEvent

    ie.

    26.01.2022] [19:34:25] [WARNING] mainEvent={"type":"PluginProcessCrashedEvent","created":1643222065,"data":{"error":"\t.\/include\/main.lua:181: syntax error near 'end'","deviceId":996}}

    [26.01.2022] [19:34:25] [WARNING] mainEvent={"type":"PluginProcessCrashedEvent","created":1643222065,"data":{"error":"\t.\/include\/main.lua:179: unexpected symbol near '=='","deviceId":996}}

     

    but in case of error in rules in ER4 there is no event PluginProcessCrashedEvent 

    [26.01.2022] [19:46:29] [ERROR] [QA_ER4_996]: Error in 'HT.Pracovna.Okno1:breached => fibaro.call(HT.Pracovna.Termostat,'setThermMode','PermanentOverride',5.0)': ./include/EventRunner.lua:1821: no triggers found in header
    [26.01.2022] [19:46:29] [ERROR] [QA_ER4_996]: main() error:./include/EventRunner.lua:2374: Main() ERROR:./include/EventRunner.lua:2209: ./include/EventRunner.lua:1821: no triggers found in header

     

    what's happend in my case - Fibaro from unknown reason deleted my window sensor. I have autogenerated HomeTable every night incl. restart ER4 in case of change global variable HomeTable. Then ER4 started but myRoom.window was nil with error message but nothing came to mobile phone - in log window there is of course red error but no event: PluginProcessCrashedEvent ...


     

    Edited by petrkl12
    Link to comment
    Share on other sites

    this reason why I suggested:

    -  generate same event as "standard" error in QA (I'm not sure that it's possible ... )

    - or create new ER event (error event) that will be possible to use in other ER ?

    Edited by petrkl12
    Link to comment
    Share on other sites

    Jan, I guess the idea with two pirs as barrier wil not be faill safe too.

    Sorry for bothering but I want to tackle this person thingy.

    Last idea if its not working the system has won.I will adapt my floormat with 3-4 sensors from car seat connected with door/window sensor Aeotech (has connection for wire ).

    floorMat will be situated outside bathroom to prevent false notification (door opens to the inside).

    Bathroom:

    Please login or register to see this code.

    Please your valuable comment

    //Sjakie

    Link to comment
    Share on other sites

  • Topic Author
  • 12 hours ago, petrkl12 said:

    this reason why I suggested:

    -  generate same event as "standard" error in QA (I'm not sure that it's possible ... )

    - or create new ER event (error event) that will be possible to use in other ER ?

    Well, I will generate an error event. 

    To generate a 'PluginProcessCrashedEvent' trigger I need to crash ER - don't want to do that ;-) 

    • Thanks 1
    Link to comment
    Share on other sites

  • Topic Author
  • 13 hours ago, Sjakie said:

    Jan, I guess the idea with two pirs as barrier wil not be faill safe too.

    Sorry for bothering but I want to tackle this person thingy.

    Last idea if its not working the system has won.I will adapt my floormat with 3-4 sensors from car seat connected with door/window sensor Aeotech (has connection for wire ).

    floorMat will be situated outside bathroom to prevent false notification (door opens to the inside).

    Bathroom:

    Please login or register to see this code.

    Please your valuable comment

    //Sjakie

     

    Let me know how it goes :-)

    Note, you must do 

    $personInBathRoom += 1

    The operators are '+=' and '-=' and they increment/decrement the variable to the left with the value to the right.

    Link to comment
    Share on other sites

    On 1/26/2022 at 11:50 AM, jgab said:

    What did you set 'time' to? It seems like it is set to a string according to the error message.

     

    I also get the same mistake ...
    all that has changed is the time for 1 minute ...
    ER4 version v0.5fix78

     

      Util.triggerVar('time'1*60 )
      rule("motionsAbab:breached & lampAbab1:isOff => lampAbab1:on; log('Абабіна рух, лампу ВКЛ')")
      rule("lampAbab1:isOn & lampAbab1:manual >= 0 => time=00:30:00; log('Включено вручну лампу, тому час вимкнення 30хв')")
      rule("trueFor(time,motionsAbab:safe) =>  lampAbab1:off; time=00:01:00; log('Абабіна нема руху вже 1хв, тому лампу ВИКЛ')")

     

    [27.01.2022] [15:05:04] [ERROR] [QUICKAPP1192]: in Rule:24[trueFor(time,motionsAbab:safe) =>  lampAbab1:off; time=00:01:00; log('Абабі...]: {"msg":"Error executing instruction:'["trueFor",2]'","ERR":true,"err":"./include/EventRunner.lua:1924: attempt to perform arithmetic on a nil value (local 'time')","src":"Rule:24[trueFor(time,motionsAbab:safe) =>  lampAbab1:off; time=00:01:00; log('Абабі...]"}

    Edited by fastvd
    Link to comment
    Share on other sites

    I made it easier:
    just 2 separate rules on shutdown: if it was manually turned on then 1 shutdown time, and if it was automatically turned on by the sensor, then another time ... the essence is the same)

     rule("motionsAbab:breached & lampAbab1:isOff=> lampAbab1:on; log('Абабіна рух, лампу ВКЛ')")
      rule("trueFor(00:00:30,motionsAbab:safe) & !lampAbab1:manual >= 0 & lampAbab1:isOn=>  lampAbab1:off")
      rule("trueFor(00:01:00,motionsAbab:safe) & lampAbab1:manual >= 0  & lampAbab1:isOn=> lampAbab1:off")
    Link to comment
    Share on other sites

  • Topic Author
  • This is a simple multiPositionSwitch QA.

    Please login or register to see this attachment.

    The code is minimal, it's just one line

    Please login or register to see this code.

    (and we wouldn't actually need that one either as we can update the position property from ER instead)

     

    The QA in itself doesn't do much, but we can easily add "state buttons" by updating the 'availablePositions' property of the QA.  The last activated button is highlighted and it generates triggers when selected.

     

    If we add these rules to the new version of ER4 (v0.75) we can use it as a way to trigger rules easily.

    Please login or register to see this code.

     

    We can easily update the "state buttons" on the StateQA by setting the property 

    Please login or register to see this code.

    where 'states' is a Lua table with label and  names like in the example.

    We update the state by setting

    Please login or register to see this code.

    where 'state' is one of the names in the Lua  states table.

    ...and we can trigger if it  changes (i.e.  the user clicks on  one of the buttons) by triggering on

    Please login or register to see this code.

     

    In this example we have TimeOfDay so we could add ER rules that advances the state during the day

    Please login or register to see this code.

    which will change the selected button on the QA to blue and send event to the other rules. This way we can change state automatically or manually if we want to set 'dinner' time earlier.

     

    We could of course have done this with a Qa with defined buttons but this is easy to dynamically update if we need more buttons (states), and the QA keeps the current state in the 'position' property.

    Please login or register to see this image.

    /monthly_2022_01/273276876_Screenshot2022-01-31at12_50_27.png.ee7bdf18761351ae0d4886db247700a2.png" />

    Edited by jgab
    • Thanks 1
    Link to comment
    Share on other sites

  • Topic Author
  • v0.75 also have support for generating events when  there is  an error/warning

    fibaro.debugFlags.eventError=true

    fibaro.debugFlags.eventWarning=true

    will turn  on the event mechanism for the errors/warnings.

     

    It will generate events

    Please login or register to see this code.

     

    It's  not perfect yet as some errors may generate duplicate events.

    • Thanks 1
    Link to comment
    Share on other sites

    I don't know how I never found this before, but man, event runner is so much easier than lots of messy scenes.

     

    I had a question, I am using this code to set the time of day

     

    Please login or register to see this code.

     

    However, if for some reason the HC3 restarts, or while I am adding stuff to the script, I have to wait for the schedule to set the state. is there a way to say if its between the times to set it rather than having to wait for the schedule to run?

    Link to comment
    Share on other sites

    i tride this 

    Util.triggerVar('time',5*60 )

      rule("RorelseSensorAllrum:breached & Bel_matbordet:isOff => Bel_matbordet:on")

      rule("Bel_matbordet:isOn & Bel_matbordet:manual >= 0 => time=00:10:00")

      rule("trueFor(time,RorelseSensorAllrum:safe) =>  Bel_matbordet:off ;time=00:05:00")

     

     

    An get this  felmedelande / error 

    [2022-01-31] [20:52:48] [ERROR] [QUICKAPP695]: in Rule:93[trueFor(time,RorelseSensorAllrum:safe) =>  Bel_matbordet:off ;time=00:05:00]: {"msg":"Error executing instruction:'["trueFor",2]'","ERR":true,"err":"./include/EventRunner.lua:1929: attempt to perform arithmetic on a nil value (local 'time')","src":"Rule:93[trueFor(time,RorelseSensorAllrum:safe) =>  Bel_matbordet:off ;time=00:05:00]"}

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, systemfel said:

    i tride this 

    Util.triggerVar('time',5*60 )

      rule("RorelseSensorAllrum:breached & Bel_matbordet:isOff => Bel_matbordet:on")

      rule("Bel_matbordet:isOn & Bel_matbordet:manual >= 0 => time=00:10:00")

      rule("trueFor(time,RorelseSensorAllrum:safe) =>  Bel_matbordet:off ;time=00:05:00")

     

     

    An get this  felmedelande / error 

    [2022-01-31] [20:52:48] [ERROR] [QUICKAPP695]: in Rule:93[trueFor(time,RorelseSensorAllrum:safe) =>  Bel_matbordet:off ;time=00:05:00]: {"msg":"Error executing instruction:'["trueFor",2]'","ERR":true,"err":"./include/EventRunner.lua:1929: attempt to perform arithmetic on a nil value (local 'time')","src":"Rule:93[trueFor(time,RorelseSensorAllrum:safe) =>  Bel_matbordet:off ;time=00:05:00]"}

     

    Sorry, It should be 

    Please login or register to see this code.

    Util.triggerVar doesn't define the time variable - it's just a test.

    I believe @fastvd was hit by the same mistake in my answer to him.

     

    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, Joel said:

    I don't know how I never found this before, but man, event runner is so much easier than lots of messy scenes.

     

    I had a question, I am using this code to set the time of day

     

    Please login or register to see this code.

     

    However, if for some reason the HC3 restarts, or while I am adding stuff to the script, I have to wait for the schedule to set the state. is there a way to say if its between the times to set it rather than having to wait for the schedule to run?

     

    Yes, it requires a bit more advanced rules.

    Please login or register to see this code.

     

    The interval test <time1>..<time2> will trigger the rule at <time1>, but it also checks and is true between the times in the interval. (We shrink the end interval with 1s to not  overlap with the other rule starting at that time)

    The .start() added to the end of the rule will trigger the rule when it is defined (i.e. ER starts up) and if the interval check is true it will set the correct variable value.

    Link to comment
    Share on other sites

    First off @jgab you are a genius.

    You made my first experience with home automation a whole lot easier, if there is a way to buy you coffee or something stronger like whiskey let me know.

     

    Iam started to automate my home, first off is the lighting and for now I have a small setup like i want with as few interaction with me and the system as possible.

    I still get an error sometimes and I think it has to do with my rule when I control my lght manually but cannot figure it out yet.

    in Rule:4[trueFor(time,229:safe) =>  208:off; time=00:20:00]: ./include/EventRunner.lua:1954: ./include/EventRunner.lua:1755: attempt to perform arithmetic on a nil value (local 'time')

     

    Read somewhere that you can color the debug lines but I cannot find it anymore (read so many pages) can you plz point me in the right direction.

     

    And I have the following rule when I turn of my hue light (180,203,175)of I want to turn of the main light but cannot figure it out.

    rule("207:scene ==  21.single   =>  {180,203,175}:on ; 208:off")
    also tried the follow 
    rule("207:scene ==  21.single   =>  {180,203,175}:on & 208:off")


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