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

The problem with the above presence rules is the statement

Please login or register to see this code.

id:value = x is translated to fibaro.call(id,'setValue',x) which is not always supported by devices.

multilevelSwitches do support 'setValue' but a generic binarySwitch do not.

 

I'm contemplating keeping up-to-date device info so :value could be more intelligent and choose appropriate action for devices...

[10.01.2024] [18:58:19] [DEBUG] [QUICKAPP2970]: Stopping simulation[10.01.2024] [18:58:19] [ERROR] [ER2970]: [Rule:97:1]>> [Rule:97:simulationButton:isOff => log('Stopping simulation'); for i,id in ipairs(simDe..] Runtime: table is 'nil' for array reference
            id:value = oldSimValues[i]

 

 

Please login or register to see this code.

 

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

    [10.01.2024] [18:58:19] [DEBUG] [QUICKAPP2970]: Stopping simulation[10.01.2024] [18:58:19] [ERROR] [ER2970]: [Rule:97:1]>> [Rule:97:simulationButton:isOff => log('Stopping simulation'); for i,id in ipairs(simDe..] Runtime: table is 'nil' for array reference
                id:value = oldSimValues[i]

     

     

    Please login or register to see this code.

     

    1. It did the simulation without error? The error is when you stop?

    2. The error message usually has ^^^on the row under the code that caused the error. In this case either simDevices or oldSimValues. It would help to know - but I guess it's oldSimValues??

    3. oldSimValues would be nil if you stop before you start, was that the case?

    4. Did the QA restart before you stopped the simulation so it lost the oldSimValues?

    5. What kind of lights are office_light, livingroom_main_light ?

     

    Edited by jgab
    Posted (edited)
    22 minutes ago, jgab said:

    1. It did the simulation without error? The error is when you stop?

    yes

    2. The error message usually has ^^^on the row under the code that caused the error. In this case either simDevices or oldSimValues. It would help to know - but I guess it's oldSimValues??

    oldSimValues / i can guess only, becuase i cant see it now, but 99% oldSimValues

    3. oldSimValues would be nil if you stop before you start, was that the case?

    no

    4. Did the QA restart before you stopped the simulation so it lost the oldSimValues?

    no

    5. What kind of lights are office_light, livingroom_main_light ?

    regular bulbs, non dimmable, binary switch types

     

    I am out of home, but will run it again, or even multiple times to give you even more precise info

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

    I am out of home, but will run it again, or even multiple times to give you even more precise info

    If the QA restarted, you could make oldSimValues into a quickAppVariable by doing

    Please login or register to see this code.

    and then

    Please login or register to see this code.

    and then it will survive a restart.

    Posted
    1 hour ago, jgab said:

    If the QA restarted, you could make oldSimValues into a quickAppVariable by doing

    Please login or register to see this code.

    and then

    Please login or register to see this code.

    and then it will survive a restart.

    Jan i run some more test and can't reproduce the error.. So, it was me accidentally doing something, i don't know..Will keep you informed, if anything occours..

    THanks

    Posted

    @jgab Jan, hello, whats wrong with this?

     

    Please login or register to see this code.

     

    Please login or register to see this attachment.

  • Topic Author
  • Posted (edited)

    '=' has lower priority/precedence than '&' and '|' (and '==' has higher priority than '&' and '|')

    This is pretty standard operator precedence for most languages. In ER4 '=' has higher precedence than '&' and '|' due to a special hack needed as their were no if-then-else support in the beginning. In ER5 that was removed to make it more streamlined...
     

    So, the expression is interpreted as 

    Please login or register to see this code.

    which doesn't make sense - and is faulty.

     

    Solution, wrap assignments in ()

    Please login or register to see this code.

     

    or, rewrite as

    Please login or register to see this code.

     

    or just 

    Please login or register to see this code.

     

    Edited by jgab
    • Thanks 1
  • Topic Author
  • Posted

    I was looking at the expression again, and if you instead of 'yes' and 'no' store true and false in the variable you can do

    Please login or register to see this code.

    '!' is the not operator

    • Thanks 1
    Posted
    On 1/6/2024 at 10:57 PM, jgab said:

     

    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.

    Same, I tried in a fresh ER5 and still had the same error but it works if the 'local' is dropped 

    Posted (edited)

    So! I'm back with more problems ;) 

     

    This code works:

    Please login or register to see this code.

    It probably seems like an odd thing to do, but there's a reason - I'm trying to get some of the blinds (the group blinds_morning_halfopen) to stop partially, and the "stop" command sent via Automation Bridge and then the Somfy cloud API has some kind of epic delay on it. So I get the blinds to open completely (the 1-minute wait - it actually takes about 20 seconds for the longest one to open, but sometimes the open command also lags), then I send some of them a "close" followed immediately by "stop".

     

    Anyway, it works.

     

    But this, which I would have thought should have the same effect, does not:

     

    Please login or register to see this code.

     

    All I've done is split the rule so I have the action triggered by the #morningopen event, and then separately invoke that event at the right time. I also made a button to let me manually trigger it (in case I wake up before 7am)

     

    Please login or register to see this code.

     

    Note - deliberately not changing the status of the button when pressed (no setValue to make it true), it is just a momentary switch.

     

    However, what happens now is that the event #morningopen kind of half-works. It opens all the blinds (blinds_morning_open:open)... and that's it. This is the case whether triggered by the button or by the 7am trigger time. 

     

    Any ideas what could be causing this? I couldn't gather logs because unfortunately they scrolled off since the last trigger, but I will do this in a follow-up. (My HC3 can only seem to retain a couple of hours of console logs...)

     

    Separately on that note - @jgab, is it possible to inject a variant of the log function so that it posts things to the console but also to a syslog server on my network? Can I just copy your "log" function, and define a new function named "log" that does the syslog send and then invokes your original one? I have something similar going in a separate ER4, but that's just set up as a separate function that is explicitly called from some rules... not as nice. 

    Edited by bonhomme
    Posted

    @jgab Jan i need to call functions in sequence inside a rule..Can you assist a bit how to achieve my goal

    Please login or register to see this code.

     

     

  • Topic Author
  • Posted
    48 minutes ago, bonhomme said:

    So! I'm back with more problems ;) 

     

    This code works:

    Please login or register to see this code.

    It probably seems like an odd thing to do, but there's a reason - I'm trying to get some of the blinds (the group blinds_morning_halfopen) to stop partially, and the "stop" command sent via Automation Bridge and then the Somfy cloud API has some kind of epic delay on it. So I get the blinds to open completely (the 1-minute wait - it actually takes about 20 seconds for the longest one to open, but sometimes the open command also lags), then I send some of them a "close" followed immediately by "stop".

     

    Anyway, it works.

     

    But this, which I would have thought should have the same effect, does not:

     

    Please login or register to see this code.

     

    All I've done is split the rule so I have the action triggered by the #morningopen event, and then separately invoke that event at the right time. I also made a button to let me manually trigger it (in case I wake up before 7am)

     

    Please login or register to see this code.

     

    Note - deliberately not changing the status of the button when pressed (no setValue to make it true), it is just a momentary switch.

     

    However, what happens now is that the event #morningopen kind of half-works. It opens all the blinds (blinds_morning_open:open)... and that's it. This is the case whether triggered by the button or by the 7am trigger time. 

     

    Any ideas what could be causing this? I couldn't gather logs because unfortunately they scrolled off since the last trigger, but I will do this in a follow-up. (My HC3 can only seem to retain a couple of hours of console logs...)

     

    Separately on that note - @jgab, is it possible to inject a variant of the log function so that it posts things to the console but also to a syslog server on my network? Can I just copy your "log" function, and define a new function named "log" that does the syslog send and then invokes your original one? I have something similar going in a separate ER4, but that's just set up as a separate function that is explicitly called from some rules... not as nice. 

    Just splitting it up that way should not affect the behaviour. However, I see in your rule you do wait('00:01')

    which sends a string to wait and it will give a runtime error (after blinds_morning_open:open) when the rule is invoked.

    Do

    Please login or register to see this code.

    and see if it works

    56 minutes ago, Pica2017 said:

    Same, I tried in a fresh ER5 and still had the same error but it works if the 'local' is dropped 

    Are you calling enable inside a rule? Then ruleSet needs to be either a Lua global (remove the local), or declare it as

    Please login or register to see this code.

    so it becomes declared as a ER variable.

  • Topic Author
  • Posted
    31 minutes ago, Neo Andersson said:

    @jgab Jan i need to call functions in sequence inside a rule..Can you assist a bit how to achieve my goal

    Please login or register to see this code.

     

     

    So the general principle is

    Please login or register to see this code.

    The abc[i+1] will return nil for the last items so then we don't call wait.

    • Thanks 1
    Posted (edited)

    @jgab Jan some questions

     

    1. can we create a device from ER rule?

     

    Please login or register to see this code.

    How to create a real QA device? and right after its created, get its ID

     

    2. Want to run an action at 10:00 on 1st november or on 1st july if actionEnabled global var is true

    Please login or register to see this code.

    Should I use extra parentheses like below?

     

    Please login or register to see this code.

     

    Edited by Neo Andersson
  • Topic Author
  • Posted

    1. Only support for childDevices at the moment. I would suggest to create a real QA with a home made Lua function.

    2. Unnecessary to have 2 daily at 10:00

    Do

    Please login or register to see this code.

    '&' has higher priority than '|', and '==' has higher than '&'.

     

    However, month() can take a list of months, so you can do

    Please login or register to see this code.

    and $actionEnabled==true is the same as just $actionEnabled, so

    Please login or register to see this code.

     

    • Thanks 1
    Posted (edited)
    On 10/30/2023 at 3:22 PM, jgab said:

    EventRunner5-v1.0.fqa

    @jgab Jan isn't this v1.0 bugged in Main file? Actually i have never updated my Main file so far, but seems to me that there is missing 

    Please login or register to see this code.

     

    when i tried to update my Main function too i got errors

     

    Last err: Expr Runtime: table is 'nil' for array reference for k,v in pairs(DTB) do shs.turnBasedOnValue(k:value,v) end ^^^

     

    so i put back mu old Main file, that is working. The only difference i can see is the missing self:main(er)

     

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

    @jgab Jan isn't this v1.0 bugged in Main file? Actually i have never updated my Main file so far, but seems to me that there is missing 

    Please login or register to see this code.

     

    when i tried to update my Main function too i got errors

     

    Last err: Expr Runtime: table is 'nil' for array reference for k,v in pairs(DTB) do shs.turnBasedOnValue(k:value,v) end ^^^

     

    so i put back mu old Main file, that is working. The only difference i can see is the missing self:main(er)

     

    In 1.0 self.main was added to MODULES in the main file and was called that way.

    Unfortunately it got a lower priority than the other modules so v1.01 fixed that.

    The whole MODULE loading logic was also moved away from main file.

    ...then there was still a bug, so v1.02 fixed that. v1.02 detects if the main is old and loads self.main.

    So, use v1.03 that is the latest, and it should work.

     

    Posted (edited)
    4 minutes ago, jgab said:

    In 1.0 self.main was added to MODULES in the main file and was called that way.

    Unfortunately it got a lower priority than the other modules so v1.01 fixed that.

    The whole MODULE loading logic was also moved away from main file.

    ...then there was still a bug, so v1.02 fixed that. v1.02 detects if the main is old and loads self.main.

    So, use v1.03 that is the latest, and it should work.

     

    Okay, but v1.0 is the oldest on forum for download..so i will go to github

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

    Okay, but v1.0 is the oldest on forum for download..so i will go to github

    ok, willl update page as v1.0 is not optimal...

    Posted
    On 1/4/2024 at 2:35 PM, ChristianSogaard said:

    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 :-)

     

     

    Hi Jan
    would you teach me to do the round ?
     

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