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)

@jgab Hello Jab,

 

How to use anonymus functions in a rule, or how else to use a callback mechanism inside  a rule? 

I have a simple function that makes http post and it should return a simple text. 

Please login or register to see this code.

 

Edited by Neo Andersson
  • Topic Author
  • Posted (edited)

     

    Please login or register to see this code.

     

    Edited by jgab
    • Thanks 1
  • Topic Author
  • Posted (edited)

    Btw, I'm almost done with my new

    Please login or register to see this link.

    , so I have started to develop EventRunner6 as a way to test the emulator.

    It's keeping the basic syntax and features of EventRunner5 but is half the size and twice the speed :-) 
    (I moved away from compiling eventscript to my own virtual machine, and now compile to Lua functions using a

    Please login or register to see this link.

    )
    It's coming along well, and has most features in place, but still need some tweaking...

    Edited by jgab
    • Like 4
    Posted (edited)
    5 hours ago, jgab said:

    Btw, I'm almost done with my new

    Please login or register to see this link.

    , so I have started to develop EventRunner6 as a way to test the emulator.

    It's keeping the basic syntax and features of EventRunner5 but is half the size and twice the speed :-) 
    (I moved away from compiling eventscript to my own virtual machine, and now compile to Lua functions using a

    Please login or register to see this link.

    )
    It's coming along well, and has most features in place, but still need some tweaking...

    I am looking forward to replace it in all of my installations, if the speed is doubled, the size is halfed..so maybe this will solve the ghost processes, that are caused probably by the large size of the QA

    Edited by Neo Andersson
  • Topic Author
  • Posted (edited)

    Well, I have started to run EventRunner6 for my own automation (I don't have that much to automate these days...)
    But it's humming along. The autoupdates and some cosmetic in logs and error messages are still missing.
    It clocks in on 133kb now.

    Repo <

    Please login or register to see this link.

    > (if you want to test early versions). If you have a working ER5 there is no hurry.
    And documentation here: 

    Please login or register to see this link.


    Please login or register to see this link.

    Edited by jgab
    • Like 2
    Posted
    4 hours ago, jgab said:

    Well, I have started to run EventRunner6 for my own automation (I don't have that much to automate these days...)
    But it's humming along. The autoupdates and some cosmetic in logs and error messages are still missing.
    It clocks in on 133kb now.

    Repo <

    Please login or register to see this link.

    > (if you want to test early versions). If you have an working ER5 there is no hurry.
    And documentation here: 

    Please login or register to see this link.


    Please login or register to see this link.

    ERť is running fine so far..so i will wait for the final version.

    Posted (edited)

    Jan 

    Please login or register to see this code.

    logs me this correclty

    { January = "16:45", February = "17:30", March = "18:15", April = "19:45", May = "20:30", June = "21:15", July = "21:00", August = "20:15", September = "19:15", October = "18:00", November = "16:30", December = "16:00" }

     

    but this

     

    Please login or register to see this code.

    logs me nil

     

    ???

     

    According to the documentaion it should work 

     

    Another feature with GVs is that they auto-convert their results. Normally, we can only store strings in GVs

    but ER we can store any value that can be json.encoded.

    Ex.

    Please login or register to see this code.

    This will json.encode the table before storing it in the GV.

    The opposite, when we access a value in a GV it will convert it back to a table in this case

    Please login or register to see this code.

    Here myTable returns {a = 42, b = 17} and then we access the .a key from that table.

    This is also true for booleans and numbers.

    Edited by Neo Andersson
  • Topic Author
  • Posted
    1 hour ago, Neo Andersson said:

    Jan 

    Please login or register to see this code.

    I don't get your result. How do you store the table in the GV?
     

    Please login or register to see this code.

    Please login or register to see this code.

     

  • Topic Author
  • Posted

    Ah, it's EventRunner5.
    Well, the same code produces the right output for ER5 too
     

    Please login or register to see this code.

    How do you store the table in the first place?

    Posted
    6 minutes ago, jgab said:

    I don't get your result. How do you store the table in the GV?
     

    Please login or register to see this code.

    Please login or register to see this code.

     

    i stored the table like this in GV

    {January="16:45",February="17:30",March="18:15",April="19:45",May="20:30",June="21:15",July="21:00",August="20:15",September="19:15",October="18:00",November="16:30",December="16:00"}
     

    1 minute ago, Neo Andersson said:

    i stored the table like this in GV

    {January="16:45",February="17:30",March="18:15",April="19:45",May="20:30",June="21:15",July="21:00",August="20:15",September="19:15",October="18:00",November="16:30",December="16:00"}
     

    it logs the full table correctly, but $LIGHT_ON_TIMES.January is nil

  • Topic Author
  • Posted (edited)
    4 minutes ago, Neo Andersson said:

    i stored the table like this in GV

    {January="16:45",February="17:30",March="18:15",April="19:45",May="20:30",June="21:15",July="21:00",August="20:15",September="19:15",October="18:00",November="16:30",December="16:00"}
     

    How stored? using eventScript? or as the string in your example?
    The syntax above is lua table syntax and that is not json. 
    {"February":"17:30","January":"16:45","December":"16:00","March":"18:15","May":"20:30","July":"21:00","April":"19:45","November":"16:30","October":"18:00","September":"19:15","June":"21:15","August":"20:15"}

    needs to be stored in the GV for ER to recognize it as json.
    The lua table is automatically converted to json if you do

    rule("$LIGHT_ON_TIMES = { January = '16:45', February = '17:30', March = '18:15', April = '19:45', May = '20:30', June = '21:15', July = '21:00', August = '20:15', September = '19:15', October = '18:00', November = '16:30', December = '16:00' }")

    or

    var.myGV = { January = '16:45', February = '17:30', March = '18:15', April = '19:45', May = '20:30', June = '21:15', July = '21:00', August = '20:15', September = '19:15', October = '18:00', November = '16:30', December = '16:00' }

    rule("$LIGHT_ON_TIMES = myGV")

    Edited by jgab
    Posted
    1 minute ago, jgab said:

    How stored? using eventScript? or as the string in your example?
    The syntax above is lua table syntax and that is not json. 
    {"February":"17:30","January":"16:45","December":"16:00","March":"18:15","May":"20:30","July":"21:00","April":"19:45","November":"16:30","October":"18:00","September":"19:15","June":"21:15","August":"20:15"}

    needs to be stored in the GV for ER to recognize it as json.
    The lua table is automatically converted to json if you do

    rule("$LIGHT_ON_TIMES = { January = '16:45', February = '17:30', March = '18:15', April = '19:45', May = '20:30', June = '21:15', July = '21:00', August = '20:15', September = '19:15', October = '18:00', November = '16:30', December = '16:00' }")

    Stored manually as i showd above. I thought ER5 handles it even if i store it as a LUA table format, but apparently i ned to store it as a JSON string using string keys : value syntax..

     

    Okay i will change it

    • 1 month later...
    Posted

    Hello Jan
    I have a lua table type fibaro global variable. I store there some infos about speakers.
    I am using speaker's IPs in ER5 but for some reason, it fails to assign speaker ips to rule vars if i use it like this
     

    Please login or register to see this code.

     

    it works only like this
     

    Please login or register to see this code.

     

    the second approach is okay as far i dont change the fibaro global. I think it wont update in the second case.
    I want to initialize the rule speaker vars on startup and update them when the fibaro global changes.

    What am i missing??
     

  • Topic Author
  • Posted (edited)
    1 hour ago, Neo Andersson said:

    Hello Jan
    I have a lua table type fibaro global variable. I store there some infos about speakers.
    I am using speaker's IPs in ER5 but for some reason, it fails to assign speaker ips to rule vars if i use it like this
     

    Please login or register to see this code.

     

    it works only like this
     

    Please login or register to see this code.

     

    the second approach is okay as far i dont change the fibaro global. I think it wont update in the second case.
    I want to initialize the rule speaker vars on startup and update them when the fibaro global changes.

    What am i missing??
     

    The reason is that rule(...) defines the rule, but .start() will run the rule asynchronously - like we had done a wait(0) before starting it.

    This means that rules never runs until we return from main().

    Expressions, rule(<expr>) where expression is not a rule (no '=>') are executed immediately.

    So,

    Please login or register to see this code.

    So, this will log nil as the first rule has not run yet when the second rule, that is an expression runs.

    .start() means, run me as soon as we exit from main()....

     

    If we do

    Please login or register to see this code.

    It will log the ip of terraceSpeaker, because it will also delay it until we return from main(), e.g. all rules defined.

     

    We can use terraceSpeaker in another rule, as other rules will not run either until we return from main().

    Edited by jgab
    • Thanks 1
    Posted

    Jan, here is another puzzle, and my hair is dropping off already,
    At 9:00 in date range (oct-apr), the shutter should go to a number from a global variable $dadShutWint_I (and the light should be off)

     

    Please login or register to see this code.

     

     

    but shutter goes to 80% all the time at 09:00

    Please login or register to see this attachment.

     

    and global values are anything but 80%, they are correctly set to 20% for shutter and 40% for slats. Slats get to 40% but the shutter goes to 80%.

    Please login or register to see this image.

    /monthly_2025_10/image.png.fa76b224d858763669cf76d2fc0c6969.png" />

     

     

     

     

    image.png.3227f960b8307bcb3937cb9cea77bd8f.png

     

     

    I have tripple checked the ER5 code. Only here are shutters accessed.
    Double checked device IDs, double checked other codes...

    Nowhere are these shutters accessed.

    Why is this happening...

    Please check it and help if you can
    thanks

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

  • Topic Author
  • Posted
    14 hours ago, Neo Andersson said:

    Jan, here is another puzzle, and my hair is dropping off already,
    At 9:00 in date range (oct-apr), the shutter should go to a number from a global variable $dadShutWint_I (and the light should be off)

     

    Please login or register to see this code.

     

     

    but shutter goes to 80% all the time at 09:00

    Please login or register to see this attachment.

     

    and global values are anything but 80%, they are correctly set to 20% for shutter and 40% for slats. Slats get to 40% but the shutter goes to 80%.

    Please login or register to see this link.

     

     

     

     

    Please login or register to see this link.

     

     

    I have tripple checked the ER5 code. Only here are shutters accessed.
    Double checked device IDs, double checked other codes...

    Nowhere are these shutters accessed.

    Why is this happening...

    Please check it and help if you can
    thanks

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    I don't think it's ER... X:value=Y is translated to fibaro.call(X,'setValue',Y)
    and nothing special is done with the argument...

    Have you tried to just make a fibaro call to set the value?

    Please login or register to see this code.

    Could it be that the 0-100 is reversed for the shutter so 80 is 20% open?
     

    Posted
    1 hour ago, jgab said:

    I don't think it's ER... X:value=Y is translated to fibaro.call(X,'setValue',Y)
    and nothing special is done with the argument...

    Have you tried to just make a fibaro call to set the value?

    Please login or register to see this code.

    Could it be that the 0-100 is reversed for the shutter so 80 is 20% open?
     

    well, as this is in customer's house i cant test it right now, he is 300 km from me..
    the 0-100 reversed thing is kinda logical, but i have no clue how can it happen...
    Anyway i will test it personally next week. I hope i will find the reason

    Posted (edited)

    Hello jan

     

    Please login or register to see this code.

     

    is that rule triggered, (is the mail being sent ) if any of the sensos got back to safe, but the other is in breached state??? Because it should not, i think. It should trigger when any of the sensors got from safe to breached, but no trigger when one is in breached and the other gets from breached to safe. My colleagues told me that they have that behaviour.

    Edited by Neo Andersson
  • Topic Author
  • Posted (edited)
    1 hour ago, Neo Andersson said:

    Hello jan

    Please login or register to see this code.

    is that rule triggered, (is the mail being sent ) if any of the sensos got back to safe, but the other is in breached state??? Because it should not, i think. It should trigger when any of the sensors got from safe to breached, but no trigger when one is in breached and the other gets from breached to safe. My colleagues told me that they have that behaviour.

    Yes, it will. The {dev1,dev2,...devn}:breached is triggered whenever any device changes state, and then the "OR" or the states is calculated, meaning that if any device is breached, the test will be breached/true.

    Trying to remember every device previous state to calculate when they go from true to false would be too much work...

    Normally, this "double" trigger is harmless, like turning on lights, but you have a side-effect, sending an email, that is not so nice to have happening twice...

     

    One could argue that it should only trigger when the whole expression goes from false to true, and we can achieve that.

    The once(<expr>) function will only trigger when the expression goes from false to true. The expression has to become false and then go to true again for it to become true again.

    Please login or register to see this code.

    which is probably what you want in this case?

    Edited by jgab
    Posted
    3 hours ago, jgab said:

    Yes, it will. The {dev1,dev2,...devn}:breached is triggered whenever any device changes state, and then the "OR" or the states is calculated, meaning that if any device is breached, the test will be breached/true.

    Trying to remember every device previous state to calculate when they go from true to false would be too much work...

    Normally, this "double" trigger is harmless, like turning on lights, but you have a side-effect, sending an email, that is not so nice to have happening twice...

     

    One could argue that it should only trigger when the whole expression goes from false to true, and we can achieve that.

    The once(<expr>) function will only trigger when the expression goes from false to true. The expression has to become false and then go to true again for it to become true again.

    Please login or register to see this code.

    which is probably what you want in this case?

    fantastic, really thanks

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