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

6 minut temu, jgab napisał:

Strange. What happens if you try to push using the fibaro api?

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

fibaro.alert(alert_type, user_ids, notification_content)

Send custom notification.

  • alert_type – one of the notification types: “email”, “sms” or “push”
  • user_ids – list of user identifiers to send the notification to
  • notification_content – content of the notification to send

Examples:
Send notification with “Test notification” content using email to users with id 2, 3 and 4.

 

 
1
fibaro.alert("push", {2,3,4}, "Test notification")

 

 

 

Then i got only one message, and working fine ............WTF :)

Link to comment
Share on other sites

  • Topic Author
  • 11 minutes ago, domin12 said:

     

    Then i got only one message, and working fine ............WTF :)

    Hmmm, can you try this

    fibaro.alert("push", {2,3,4}, "Test notification",false)

    i.e. with an extra false as 4th argument. Does it go to your phone then?

    Link to comment
    Share on other sites

    Guys,

    If I "push"

    fibaro alert one ID sends to 2 phones,  two different users

    same in ER rule

    succes

    //Sjakie

    false will give message on phone too

    (other rules disabled)

    Then i got only one message, and working fine ............WTF :)>>>>> why I get 2 phones??

    Yes I know my HC3 has his own life??

    //Sjakie

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, AshleyJoseph said:

    Hi Guys

     

    First attempt at using Event Runner. 

     

    Could someone let me know if the below makes sense or ive missed something? 

     

    Also do you need to set the parameters to use sunrise & sunset or is that something that is already set?

     

    dblight = 359
    dbfan = 362 
    dbhum = 599
    dblux = 598
    dbmotion = 397 
     
      Util.defvars(HT)
      Util.reverseMapDef(HT)
     
    rule("dbmotion:breached => 06:00..18:00 >> dblight:value=30, 18:00..6:00 >> dblight:value=70")
    rule("trueFor(00:01,dbmotion:safe) => dblight:off")

     

    You could put the variables in a table (HT). ER4 rules can use Lua globals or variables defined with Util.defvars.

    The "if-then" has the format "|| <test1> >> <actions1> || <test2> >> <actions2> ...

    It reads nicer using a multi-line string [[ ..... ]]

    Please login or register to see this code.

    The usage of a table with values allows you to structure your constants like this

    Please login or register to see this code.

    then you can have a variable named 'light' in some other place than db... like kitchen.light

    Edited by jgab
    Link to comment
    Share on other sites

    3 minuty temu, jgab napisał:

    Hmmm, can you try this

    fibaro.alert("push", {2,3,4}, "Test notification",false)

    i.e. with an extra false as 4th argument. Does it go to your phone then?

     

    Also ok , one message on my phone ..... by running this fibaro.alert("push", {2,20}, "Test notification",false) 

    2 and 20 are id's of users

     

    but on ER when run this :

      rule("@@00:01 => 2:msg=log('push 2')")
      rule("@@00:01 => 20:msg=log('push 20')")

    got push from both

     

    Link to comment
    Share on other sites

  • Topic Author
  • 26 minutes ago, AshleyJoseph said:

    Also do you need to set the parameters to use sunrise & sunset or is that something that is already set?

    sunset, sunrise,dawn,dusk are ready constants to use in the rules

    rule("@sunset-00:10 => log('10min before sunset')")

    Link to comment
    Share on other sites

    2 hours ago, jgab said:

     

    You could put the variables in a table (HT). ER4 rules can use Lua globals or variables defined with Util.defvars.

    The "if-then" has the format "|| <test1> >> <actions1> || <test2> >> <actions2> ...

    It reads nicer using a multi-line string [[ ..... ]]

    Please login or register to see this code.

    The usage of a table with values allows you to structure your constants like this

    Please login or register to see this code.

    then you can have a variable named 'light' in some other place than db... like kitchen.light

    Thanks @jgab

     

    I get the following error - Is there anything I need to amend?

     

    [04.09.2020] [19:59:35] [DEBUG] [QUICKAPP618]: ------------------------------------- Setting up rules (main) -------------------------------------[04.09.2020] [19:59:35] [ERROR] [QUICKAPP618]: Error in 'db.motion:breached =>      || 06:00..18:00 >> db.light:value=30     || 18:00..6:00 >> db.light:value=70     ': ./include/EventRunner.lua:1193: non constant property 'function: 0x11fec320'[04.09.2020] [19:59:35] [ERROR] [QUICKAPP618]: ./include/EventRunner.lua:1982: Main() ERROR:./include/EventRunner.lua:1840: ./include/EventRunner.lua:1193: non constant property 'function: 0x11fec320'

    Link to comment
    Share on other sites

  • Topic Author
  • 25 minutes ago, AshleyJoseph said:

    Thanks @jgab

     

    I get the following error - Is there anything I need to amend?

     

    [04.09.2020] [19:59:35] [DEBUG] [QUICKAPP618]: ------------------------------------- Setting up rules (main) -------------------------------------[04.09.2020] [19:59:35] [ERROR] [QUICKAPP618]: Error in 'db.motion:breached =>      || 06:00..18:00 >> db.light:value=30     || 18:00..6:00 >> db.light:value=70     ': ./include/EventRunner.lua:1193: non constant property 'function: 0x11fec320'[04.09.2020] [19:59:35] [ERROR] [QUICKAPP618]: ./include/EventRunner.lua:1982: Main() ERROR:./include/EventRunner.lua:1840: ./include/EventRunner.lua:1193: non constant property 'function: 0x11fec320'

     

    Sorry, the time must be on format 'HH:MM' - 2 digits for hour and 2 digits for minutes

    Ex. "|| 18:00..06:00 >> db.light:value=70"

    6:00 gives a strange error message as it's interpreted as <device>:<method> where method is '00'...  

    Good error messages are hard to implement - lets see if I can improve on this....

    Edited by jgab
    Link to comment
    Share on other sites

    16 godzin temu, jgab napisał:

    But testing on temp/month/closed windows etc is easily done in the rule head.

    For You, for sure :)
    How to create a rule so that it uses the outside temperature from YR Weather? I've been struggling with this for an hour and no success...

     

     

    16 godzin temu, jgab napisał:

    To always turn off a light 1minute after it's turned on, no matter what

    rule("trueFor(00:01,light:isOn) => light:off")

     

    I want to make rule like this:

    rule("door:isbreached & light:isOff & sunset..sunrise & (lux:lux < 20) & motion:safe =>       turn the light on for one minute

    is it possible without using a scene ?

     

     

     

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 9 hours ago, michal85pl said:

    For You, for sure :)
    How to create a rule so that it uses the outside temperature from YR Weather? I've been struggling with this for an hour and no success...

    I want to make rule like this:

    rule("door:isbreached & light:isOff & sunset..sunrise & (lux:lux < 20) & motion:safe =>       turn the light on for one minute

    is it possible without using a scene ?

    For the weather you could do something like

    Please login or register to see this code.

     

    The second question

    Please login or register to see this code.

    In general, these way of writing rules are not optimal. Here we turn on the light, wait a minute, and no matter what we turn off the light after 1minute. If someone opens the door and starts the light and then closes the door and open it again after 30s, it's still the first rule that will turn off the lights after 30s.

    One would probably like that if the rule triggers again the minute timer would be extended.

    One way to do that is to re-fire an event every time the rule triggers and let that event turn off the light.

    Please login or register to see this code.

     

    • Thanks 1
    Link to comment
    Share on other sites

    3 godziny temu, jgab napisał:

    For the weather you could do something like

    Please login or register to see this code.

    As always, the answer is complete and solving the problem :)

     

    3 godziny temu, jgab napisał:

    The second question

    Please login or register to see this code.

    In general, these way of writing rules are not optimal. Here we turn on the light, wait a minute, and no matter what we turn off the light after 1minute. If someone opens the door and starts the light and then closes the door and open it again after 30s, it's still the first rule that will turn off the lights after 30s.

    One would probably like that if the rule triggers again the minute timer would be extended.

    One way to do that is to re-fire an event every time the rule triggers and let that event turn off the light.

    Please login or register to see this code.

    in this case, first one is a sufficient solution, but thank You once again for showing how it should be done :)

    Link to comment
    Share on other sites

    can You please tell me how to write this rule to loop checking if the window is closed?

     

    rule("trueFor(24:00,window:safe) => 2:msg=log('air out bedroom')")

    Link to comment
    Share on other sites

  • Topic Author
  • 4 hours ago, michal85pl said:

    can You please tell me how to write this rule to loop checking if the window is closed?

     

    rule("trueFor(24:00,window:safe) => 2:msg=log('air out bedroom')")

     

    Please login or register to see this code.

    It will send a push every time the window been safe for 24 hours. If it's not opened it will repeat at 48, 72, 96 hours etc.

    'again' is the function that re-triggers the trueFor statement.

    again can also take an argument that is the number of times it should re-trigger the trueFor

    Please login or register to see this code.

    again also return as a value the number of times it has re-triggered. That number can be used to give better messages 

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    18 godzin temu, jgab napisał:

    rule("trueFor(24:00,window:safe) => 2:msg=log('air out bedroom'); again()")

    I thought this rule would work a little different ... But after enabling this rule it doesn't start working until I open and close the windows again ... is it possible to force it to work right away? otherwise, after each restart or HC3 or QA, you would have to open, close all windows, or turn on / off all switches for which such a rule was created.
    I thought just adding "again ()" would make it count its time after restarting QA / HC3

    Link to comment
    Share on other sites

  • Topic Author
  • 7 minutes ago, michal85pl said:

    I thought this rule would work a little different ... But after enabling this rule it doesn't start working until I open and close the windows again ... is it possible to force it to work right away? otherwise, after each restart or HC3 or QA, you would have to open, close all windows, or turn on / off all switches for which such a rule was created.
    I thought just adding "again ()" would make it count its time after restarting QA / HC3

    Yes, rules typically only run when a state change in a device/variable in the head triggers the rule.

    You can force the rule to trigger by adding .start()

    Please login or register to see this code.

    'again' just makes it start to watch another 24h period.

    The problem with trueFor is that it will restart to count time when the HC3/QA is restarted. There is no "memory"

    You could make a rule that checks every hour if the window has been closed for 24 hours (and make 

    Please login or register to see this code.

    :last is the time since the device changed state last, and then we check that it was a 'close' (i.e. :safe)

    This will continue to run the action every hour after 24 hours.

    Only do it once

    Please login or register to see this code.

    ..then the window needs to be opened and closed for it to trigger again.

     

    Come to think about it.... this may also work ?

    Please login or register to see this code.

    it should reduce the waiting time with the time it has been closed when the rule starts

    Link to comment
    Share on other sites

    @jgab And what about to create new "function" that will setup for define devices and properties last values (via direct reading from system after HC3 start)

    Link to comment
    Share on other sites

  • Topic Author
  • 2 minutes ago, petrkl12 said:

    @jgab And what about to create new "function" that will setup for define devices and properties last values (via direct reading from system after HC3 start)

    But device properties are preserved, like :last. It's part of the device properties.

    It's just that the trueFor is a local timer in the scene, and to preserve timers over restarts.... no I don't think so. (most of the cases you don't want that anyway)

    Link to comment
    Share on other sites

    is it possible to use two or more conditions with "trueFor"? for more windows in one room im my exaple?

     

     

    in this case:

    rule("bedroomwindows = {window1,window2,window3}")

    rule("trueFor(24:00,bedroomwindows:safe) => 2:msg=log('air out bedroom'); again()").start()

     

    i get:

    ./include/EventRunner.lua:1982: Main() ERROR:./include/Toolbox_events.lua:211: attempt to call a nil value (field '_invokeRule')

     

     

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 44 minutes ago, michal85pl said:

    is it possible to use two or more conditions with "trueFor"? for more windows in one room im my exaple?

    in this case:

    rule("bedroomwindows = {window1,window2,window3}")

    rule("trueFor(24:00,bedroomwindows:safe) => 2:msg=log('air out bedroom'); again()").start()

    i get:

    ./include/EventRunner.lua:1982: Main() ERROR:./include/Toolbox_events.lua:211: attempt to call a nil value (field '_invokeRule')

    Your rule is perfectly valid. This is the way to check it.  It was a bug in the code that must have happened some versions ago.

    I'm trying to understand why I haven't seen this before.. strange.

    Anyway, I have pushed v0.5fix14 - so if you have the update rules enabled it should work by restarting the QA.

    Link to comment
    Share on other sites

    Godzinę temu, jgab napisał:

    Your rule is perfectly valid. This is the way to check it.  It was a bug in the code that must have happened some versions ago.

    I'm trying to understand why I haven't seen this before.. strange.

    Anyway, I have pushed v0.5fix14 - so if you have the update rules enabled it should work by restarting the QA.

    Updated...

     

    Now this one works:

    rule("bedroomwindows = {window1,window2,window3}")

    rule("trueFor(24:00,bedroomwindows:safe) => 2:msg=log('air out bedroom'); again()").start()

     

     

     

    But that two, not:

     

    rule("bedroomwindows = {window1,window2}") 

    rule("@@01:00 & bedroomwindows:last >= 24:00 & bedroomwindows:isOff => log('Closed for 24+ hours')")

     

    [06.09.2020] [20:53:31] [DEBUG] [QUICKAPP367]: tokenizer failed at  & bedroomwindows:last >= 24:00 & bedroomwindows:isOff => log('Closed for 24+ hours')
    [06.09.2020] [20:53:31] [DEBUG] [QUICKAPP367]: @@01:00 & bedroomwindows:last >= 24:00 & bedroomwindows:isOff => log('Closed for 24+ hours') = true

     

     

     

    rule("bedroomwindows = {window1,window2}") 

    rule("trueFor(24:00-bedroomwindows:last,bedroomwindows:isOff) => log('Closed for 24+ hours')").start()

     

    [06.09.2020] [19:20:52] [ERROR] [QUICKAPP367]: in Rule:17[trueFor(24:00-bedroomwindows:last,bedroomwindows:isOff) => log('Closed for 24+ h...]: {"msg":"Error executing instruction:'[\"-\",2]'","src":"Rule:17[trueFor(24:00-bedroomwindows:last,bedroomwindows:isOff) => log('Closed for 24+ h...]","ERR":true,"err":".\/include\/EventRunner.lua:1391: attempt to perform arithmetic on a table value"}

     

     

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