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)
29 minutes ago, jgab said:

Yes, you can split up the rules. Besides creating more QA files it shouldn't have any real effect on memory usage.

 

There is a rule function

Please login or register to see this code.

that creates a global variable if it doesn't exist. 

The function returns true if the global was created and false if it existed.

So, you can do this

Please login or register to see this code.

It will create the variable if it doesn't exists, and if so also initialise it to someValue

If i save a boolean in global, should i use quotes or it doesnt matter

 

Please login or register to see this code.

 

3 minutes ago, Neo Andersson said:

If i save a boolean in global, should i use quotes or it doesnt matter

 

Please login or register to see this code.

 

sorry, getting this error for this rule

Please login or register to see this code.

 

Please login or register to see this attachment.

Edited by Neo Andersson
Posted

sorry, getting this error for this rule

Please login or register to see this code.

 

Please login or register to see this attachment.

Posted
On 11/23/2023 at 5:53 PM, jgab said:

 

Well, one way is to enable and disable rules with the functions er.enable() and er.disable()

If you declare the rules in a table, like this

Please login or register to see this code.

you end up with a table of rules, as the rule(...) function returns the rule object.

By default the rules are enabled, but you can use the function er.disable(ruleSet) 

to disable all the rule in the table directly after they are defined.

The advantage with this is that you can use enable and disable from within rules so you could have another 

rule that says 

rule("@10:00 => enable(ruleSet); wait(03:00); disable(ruleSet)")

in other words, enable the rules for a certain time during the day.

I have used this to enable special Holliday rules in the past, lightning etc. (there is something similar for ER4)

 

The other simple(r) approach is just the put the rules within an if-then-else

 

in main where you load the modules you set up a table with the "rule sets" you want to enable/disable 

Please login or register to see this code.

 

Then in the local main in the modules you have an extra parameter, config

Please login or register to see this code.

 

end

 

Hi Jan, trying to setup disable rules using rulesets as posted but getting this error

Runtime: ./include/builtins.lua:764: enable: not a rule enable

Also, trying to implement ruleset to be enabled when internet is up and disabled when down, is  #onlineEvent best for this? I can't seem to get a result from this for true or false?

Posted

sorry this one as well not working  for me, ok in ev4

rule("log('%s',listglobals())")

 

 DEBUG table: 0xaaaabe33c5d0

  • Topic Author
  • Posted

    Sorry, I was sloppy. The assignment needs to be in parenthesis as '&' has higher priority than '='

    So,

    Please login or register to see this code.

     

    Assignment to a fibaro global  translates the value to a string (fibaro globals can only store strings)

    So

    rule("$foo = false")

    is the same as

    rule("$foo = 'false'")

    tables are json.encoded automatically so

    rule("$foo = { a = 42, b = 77 }")

    json.encodes the value before storing it in the global var.

    It also automatically decodes the value when reading from a global variable

    rule("t = $foo; log(t.a)")

    or shorther

    rule("log($foo.a)")

     

    rule("$houseCheckTime = '23:30'") 

    will store the string "23:30" in the variable.

    rule("$houseCheckTime = 23:30") 

    will store the number 23*3600+30*60 in the variable

     

     

    Posted

    Thanks @jgab

    I had no chance of working that one out on my own 😅

    I'll give your suggestion a try tomorrow but it sounds on the money. 

  • Topic Author
  • Posted
    15 minutes ago, Pica2017 said:

    Hi Jan, trying to setup disable rules using rulesets as posted but getting this error

    Runtime: ./include/builtins.lua:764: enable: not a rule enable

    Also, trying to implement ruleset to be enabled when internet is up and disabled when down, is  #onlineEvent best for this? I can't seem to get a result from this for true or false?

     

    This works

    Please login or register to see this code.

    so how do you do it?

     

    The online event could work, but my feeling is it may take a while before it triggers.

    Posted (edited)

    @jgab Jan, i am probably blind, but i am stuck like an hour..why arent all the buttons shown in UI

     

    Please login or register to see this image.

    /monthly_2024_01/image.png.ad30f5709b47ac9df09b61bd2dc69cbd.png" />

     

    Please login or register to see this attachment.

     

    Edited by Neo Andersson
  • Topic Author
  • Posted
    27 minutes ago, Neo Andersson said:

    @jgab Jan, i am probably blind, but i am stuck like an hour..why arent all the buttons shown in UI

     

    Please login or register to see this link.

     

    Please login or register to see this attachment.

     

    It's difficult with screen dumps - can you post the header code as text? then I can test it also.

    Do you get any warnings error when it starts up?

    (bw, it's more a vscode thread than ER5)

    1 minute ago, jgab said:

    It's difficult with screen dumps - can you post the header code as text? then I can test it also.

    Do you get any warnings error when it starts up?

    (bw, it's more a vscode thread than ER5)

    or post me the whole file so I can run it.

    I can't see any strange in the dump but there can be strange chars or a space squeezed in...

    Posted
    7 minutes ago, jgab said:

    It's difficult with screen dumps - can you post the header code as text? then I can test it also.

    Do you get any warnings error when it starts up?

    (bw, it's more a vscode thread than ER5)

    or post me the whole file so I can run it.

    I can't see any strange in the dump but there can be strange chars or a space squeezed in...

    Okay, restart from VS code was not enough to update UI. Thats why it did not work. Had to reload the browser to see changes.

    I should have start with this. OMG

    Thanks

    Posted (edited)

    @jgab Jan, how to merge two tables in a rule

    Please login or register to see this code.

     

    Edited by Neo Andersson
  • Topic Author
  • Posted (edited)
    41 minutes ago, Neo Andersson said:

    @jgab Jan, how to merge two tables in a rule

    Please login or register to see this code.

     

     

    Well, there are some extra methods assigned to table.

    you can do table.append({1,2,3},{4,5,6})

    that just appends the lists so you get

    {1,2,3,4,5,6}

    There is also table.union({1,2,3},{4,5,6})

    that "merges" the tables and removes duplicates, in this case you get the same {1,2,3,4,5,6}

    So, 

    rule("switches = table.union(group1,group2)")

    would work for you.

    Edited by jgab
  • Topic Author
  • Posted
    3 hours ago, Neo Andersson said:

    Okay, restart from VS code was not enough to update UI. Thats why it did not work. Had to reload the browser to see changes.

    I should have start with this. OMG

    Thanks

    Yes, if you change the UI layout you need to reload the web UI.

    Posted
    10 hours ago, Neo Andersson said:

    @jgab Jan may i have two questions

     

    1. How to detect in a rule, if global variable exists, and if not, create it with some default value ? Would this work????

    Please login or register to see this code.

    2. If i want to devide my code to multiple different files, and load them..

    a) Does this have effect on general memory usage? / having more files means more memory consumption, or it is just dependent on the code in it itself

    b) Can i even use something like this

     

    Please login or register to see this code.

     

    Jan, turned out, that I can not split my files as I described above..It complains  attempt to call a nil value (global 'rule') 

    So i need to keep everything in one function that contains rule calls i think.

  • Topic Author
  • Posted

    If you look at the main file there is a function

    Please login or register to see this code.

    wheee you define your rules.

    The rule function (local rule) is defined as er.eval that is the function that does the job.

    So if you want to define rules in other files you need to pass the er table to those files, so they can get the rule function.

     

    We discussed it in this post

     

    Posted
    4 minutes ago, jgab said:

    If you look at the main file there is a function

    Please login or register to see this code.

    wheee you define your rules.

    The rule function (local rule) is defined as er.eval that is the function that does the job.

    So if you want to define rules in other files you need to pass the er table to those files, so they can get the rule function.

     

    We discussed it in this post

     

    Jan, sorry, i forgot to mention, that after that error i realized what's the problemt, and i placed this line

    Please login or register to see this code.

    into every function where rules are accessed. After that it started to complain about er

    so i stopped to try it further.

    If you say, that it should work, i will try it tomorrow again, becuase my function that now loads my rules is like 1000 line long so i want to make some more transparent structure.

     

    Posted

    @jgab your suggestion worked, thank you!

     

    Now, I'm trying to make that child device work - it is triggering OnAction events 'open' and 'closed' but the :isOpen and :isClosed rules are not getting triggered. What's the correct way to pick up those actions?

     

    Please login or register to see this code.

     

    gives

     

    Please login or register to see this code.

     

    Setting the last two rules to watch Blinds_Upstairs instead of Blinds_Upstairs_D doesn't generate any errors, but the open/close events don't trigger the rules.

     

    Please login or register to see this code.

     

     

  • Topic Author
  • Posted
    7 hours ago, bonhomme said:

    @jgab your suggestion worked, thank you!

     

    Now, I'm trying to make that child device work - it is triggering OnAction events 'open' and 'closed' but the :isOpen and :isClosed rules are not getting triggered. What's the correct way to pick up those actions?

     

    Please login or register to see this code.

     

    gives

     

    Please login or register to see this code.

     

    Setting the last two rules to watch Blinds_Upstairs instead of Blinds_Upstairs_D doesn't generate any errors, but the open/close events don't trigger the rules.

     

    Please login or register to see this code.

     

     

    Ok, the way it works in the last version of ER5 is that the Childs instance object is <name>_D and the Childs deviceId is <name>_ID

    So either

    Please login or register to see this code.

    or

    Please login or register to see this code.

    That is why you can call the instance method with

    Please login or register to see this code.

    which also could have been done as

     

    Please login or register to see this code.

     

    Secondly, when you get 

    [07.01.2024] [10:47:35] [ERROR] [QUICKAPP293]: Rule setup error(s) - fix & restart...

    You will probably have had a log message with the console tag [ER293] also with a more informative error.

    Per default, ER5 separate "system message" on tag ER<ID> and user messages on the normal QUICKAPP<ID>

    So, select both in the console.

    It that can be confusing (I admit that I sometimes forget. to look at the ER tag) ad you can get all logs on QUICKAPP<ID> if you comment out the line

    Please login or register to see this code.

    in the main file.

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

    Jan, sorry, i forgot to mention, that after that error i realized what's the problemt, and i placed this line

    Please login or register to see this code.

    into every function where rules are accessed. After that it started to complain about er

    so i stopped to try it further.

    If you say, that it should work, i will try it tomorrow again, becuase my function that now loads my rules is like 1000 line long so i want to make some more transparent structure.

     

     

    So, in the later ER5's in the main file there is already a setup for loading modules from other files. You may not have updated the main file so you haven't seen it.

    It's in the :onInit() setup part and looks like

     

    Please login or register to see this code.

    The commented part is the instructions.

    Ex.

    create a QA file named u_myRules1

    with the content

    Please login or register to see this code.

     

     

    you also need to make sure that you have the module loading code in main

    Please login or register to see this code.

     

    The prio thing is so that you can decide in what order the modules should load if they have dependencies on each other...

  • Topic Author
  • Posted
    19 hours ago, Pica2017 said:

    sorry this one as well not working  for me, ok in ev4

    rule("log('%s',listglobals())")

     

     DEBUG table: 0xaaaabe33c5d0

    Yes, that's an interesting bug. I fixed it in the next version, but I have some more stuff to add before releasing the next version.

    For now you need to encode it explicitly

    Please login or register to see this code.

    It is listglobals() that is problematic - most other tables will print out encoded automatically.

    There is also a new constant in ER5, 'globals', that gives you a list of all the names of the globals

    Please login or register to see this code.

     

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