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
  • Posted

    The code I pasted in became garbage... I updated the post with hopefully something that makes sense.

    • Like 1
    Posted

    How I return a list of rooms with a given Category in rooms - like toilet?

    I tried these non useful commands, as they return a huge list. and I expect two rooms to be returned.

     

    I need to use it in EV5, so its a little releated.

     

    Please login or register to see this code.

     

    Please login or register to see this spoiler.

     

    Posted
    1 hour ago, ChristianSogaard said:

    How I return a list of rooms with a given Category in rooms - like toilet?

    I tried these non useful commands, as they return a huge list. and I expect two rooms to be returned.

     

    I need to use it in EV5, so its a little releated.

     

    Please login or register to see this code.

     

    Please login or register to see this spoiler.

     

    I found out

    Please login or register to see this code.

     

  • Topic Author
  • Posted
    3 minutes ago, ChristianSogaard said:

     

    I found out

    Please login or register to see this code.

     

    You can get a list of IDs assigned to the ER variable 'toilets' in ER like this

    Please login or register to see this code.

    If you want the name it is

    Please login or register to see this code.

     

    • Thanks 1
    Posted
    14 minutes ago, jgab said:

    You can get a list of IDs assigned to the ER variable 'toilets' in ER like this

    Please login or register to see this code.

    If you want the name it is

    Please login or register to see this code.

     

    Damm, you are next level :-)

     

    I using this code 

    Please login or register to see this link.

     to filter out all my Matrix Switches.

    Each Matrix got 12 devices and Only 5 devices are interesting at this time
    2,5,7,9,11 - the Scene and the 4 LEDS.

    I have a List like below with 25 Matrix  - can i Filter out in a new list eg 25:    "Led1": 30,     "Led2": 31,  "Led3": 32,     "Led4": 33, from the 

    rule("toilets = [_.category=='toilet',_.id in api.get('/rooms?visible=true&empty=false')]")

    list 

     

     

    {
      "25": {
        "Led3": 33,
        "Led1": 29,
        "name": "B1:v Hoveddør",
        "t4": 35,
        "roomID": 438,
        "t2": 31

        "idx": 4
      },
      "37": {
        "t3": 45,
        "t1": 41,
        "name": "I:v Gang Ø",
        "t4": 47,
        "idx": 4,
        "roomID": 441,
        "t2": 43
      },

    image.png.65fc1c8b096582d0e7a6ade4bb15f414.png

     

    Posted
    10 hours ago, jgab said:

    Please login or register to see this code.

     

    Please elaborate. 

    id:state retturn a boolean?

    ...but it doesn't trigger the rule?

    Do you see a refresh log with when property 'state' change?

    Can you post the whole device struct? Is the device a FGRGBW-442 ?

    Sorru i was out...i will post here the rule in a few minutes

    Posted
    1 minute ago, Neo Andersson said:

    Sorru i was out...i will post here the rule in a few minutes

    Please login or register to see this code.

     

    Please login or register to see this attachment.

  • Topic Author
  • Posted

    Ok, it triggers the rule, but because :state returns a list of the states of the IDs (if the ID part os a list) it will of course not be == true.

    We need to check if the device that caused the trigger id:state is true

    Please login or register to see this code.

     

    • Like 1
    Posted (edited)

    @jgab

     

    Jan shouldn't this be a correct trigger for the last day of the month at 22:30 ?

    Please login or register to see this code.

     

    It did not trigger on 31 dec

     

     

     

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

    @jgab

     

    Jan shouldn't this be a correct trigger for the last day of the month at 22:30 ?

    Please login or register to see this code.

     

    It did not trigger on 31 dec

     

     

     

    wday is for testing weekdays, mon-sun...

    To test day numbers use day

    rule("@22:30 & day('last') => ....

     

    1 minute ago, jgab said:

    wday is for testing weekdays, mon-sun...

    To test day numbers use day

    rule("@22:30 & day('last') => ....

     

    You can test it with

    Please login or register to see this code.

     

    • Thanks 1
    Posted

    @jgab did you overkook or is't it possible.

    General tab there is an option to export data.

    Can I activate it in ER5?

    If yes is it also possible that timestamp can be a date I can read?

    Thanks

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

    @jgab did you overkook or is't it possible.

    General tab there is an option to export data.

    Can I activate it in ER5?

    If yes is it also possible that timestamp can be a date I can read?

    Thanks

    Eh, I don't have that in my general tab...?

    Posted (edited)

    Hei Jan

     

    I have manually rounded daily to two decimals, as im still struggling with the code to do it..

    First i tried with fmt %.2f - rule is accepted and seems to round the 'value', but it ends up in the table with may decimals

    Please login or register to see this code.

     

    I also tried this - but this still creates many decimals in daily  {"total":9942.0,"daily":5.4400000000005,"date":"2024-01-04"},

    Please login or register to see this code.

     

    Please login or register to see this code.

     

    So in the other rule i also tried adding the math.floor.

    But this give wrong numbers  {"daily":-9751,"total":186.54,"date":"2024-01-04"},

    Please login or register to see this code.

     

    Using  fmt in the line, almost works - it adds the correct data in the table, but with Quotes around (String) 

    Please login or register to see this code.

     

    Ill use a lifeline and ask a friend :-)

     

     

    Edited by ChristianSogaard
    Typo
    Posted (edited)

    Jan, See below export data

     

    Please login or register to see this attachment.

    Edited by Sjakie
    Posted

    @jgab Jan can you please help with formatting?

     

    In  following rule the break line never gets applied..Everything is logged in one line

     

    Please login or register to see this code.

     

    Posted
    42 minutes ago, Neo Andersson said:

    @jgab Jan can you please help with formatting?

     

    In  following rule the break line never gets applied..Everything is logged in one line

     

    Please login or register to see this code.

     

    OK, it turned out, that only in debug window they dont have effect..When sending in push, they are there.

    • Like 1
    Posted

    Hi, I'm trying to port the following ER4 code:

     

    Please login or register to see this code.

     

    This code is a bit messy but it works: in the morning, the blinds in the living room plus kitchen_2 are opened, then some of them are half-closed using a timing hack (best I could come up with with Somfy blinds and Automation Bridge). 

     

    with some modifications to clear obvious errors and tidy up, it comes across like this in ER5

     

    Please login or register to see this code.

     

    I added a child device - that isn't what this post is about but including it for completeness in case it ends up somehow relevant.

    The problem is that the loops that populate blinds_morning_open and living_blinds don't seem to work, I end up with those variables just having the one device. When I go into the terminal to debug:

     

    Please login or register to see this code.

     

    Also, trying to reference the HT variable in the terminal brings back nothing but errors:

    Please login or register to see this code.

     

    Note the code doesn't generate any errors, it appears everything ran successfully. Just that variable isn't populated. If I remove the initial assignment and make it a blank table (living_blinds = {}) then the rule referencing living_blinds:isClosed will throw an error.

     

    I've tried a few permutations to try to get this going including dropping HT, using var instead of HT, etc - but seems the scope where that loop is run is different to the scope where rules are run, which is also what the terminal sees, making it tricky to find the winning combination.

     

    Interestingly, listVariables() in the terminal shows a nested list:

    living_blinds = [[284],286,285,282,279,281]

     

    Any advice?

  • Topic Author
  • Posted (edited)

    Without completely setting myself into your rules one issue is the var assignment.

    Try this

    Please login or register to see this code.

     

    The reason is that var is not a plain Lua table, it's a metatable that does stuff with assignment.

    It "boxes" the value in a {_}

    var.x = 42 actually creates var.x = {42}

    The reason is that var.x = nil create var.x = {} so we can represent a variable with a nil value.

     

    Having said that, I could probably fix it so that var.x returned the "unboxed" value, but I haven't done that yet.

    But for now be aware of that when accessing var values. You could also have done 

    Please login or register to see this code.

    ...but that will break if/when I fix the access to var. :-) 

    Edited by jgab
    • Thanks 1
    Posted (edited)

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

     

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

    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

    Edited by jgab
    • Thanks 1

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