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

50 minutes ago, jgab said:

 

bat_devices:dID:bat > battLevel

залежить від того, що ви отримали подію заряду батареї, яка запустила правило, але ваше правило є правилом часу.

Щоб перевірити, чи всі пристрої мають рівень заряду акумулятора > battLevel о 09:00, виконайте

rule("@{catch,09:00} & min(bat_devices:bat) > battLevel => ....")

 

no, it doesn't work as it should! The reason is that I don't understand why it should work! With api, everything is easier, there all > or < work clearly, but here there is some kind of mysticism!!! 1000 firsts work, but this one does not want to do anything!!! MYSTICISM!

Link to comment
Share on other sites

4 hours ago, fastvd said:

 

bat_devices = {70,104}
battLevel = 80
-- Check when device change bat state
rule("bat_devices:dID:bat < battLevel => post(#notifyBat{id=id})")
-- Check at startup
rule("for _,id in ipairs(bat_devices) do id:bat < battLevel & post(#notifyBat{id=id}) end")
-- Notify
rule([[#notifyBat{id='$id'} =>
log("Less than %s  battery charge of in room %s",battLevel,id:roomName)
]])
 
all ok

I don't understand how these rules work and MAINLY - why do we post twice (#notifyBat{id=id}

I also do not understand this expression
bat_devices:dID:bat
we catch the word bat as value as power, but why dID?

Edited by fastvd
Link to comment
Share on other sites

  • Topic Author
  • 2 hours ago, fastvd said:

    no, it doesn't work as it should! The reason is that I don't understand why it should work! With api, everything is easier, there all > or < work clearly, but here there is some kind of mysticism!!! 1000 firsts work, but this one does not want to do anything!!! MYSTICISM!

    No, it's not really mysticisms - even though it looks like that ;-) 

    Lets' start with 

    rule("@{catch,09:00} & min(bat_devices:bat) > battLevel => ....")

     

    @{catch,09:00} we know , it starts the rule at 09:00 every day.

    bat_devices:bat given that bat_devices contains 2 devices = { 55,66}

    will return a table withe the battery levels of these two devices, ex.

    { 88, 99} if device 55 had 88% left and device 66 had 99% left.

    The min() function will return the smallest value from a list. In our case 88.

    So the smallest values is 88

    min(bat_devices:bat) > battLevel => ...

    will then be true and run the action if the smallest battery_level in the list is still larger then 'battLevel' which was the wanted outcome. So this rule should work.

     

    For the other rules

    Please login or register to see this code.

    I explained the reason for :dID in an earlier post. It's just a convenience and you can write instead

    Please login or register to see this code.

    if you think it's clearer.

    The reason that why do we post twice post(#notifyBat{id=id})

    is because we have 3 rules. The first two checks the battery level and calls the 3rd rule to let that rule print/notify. This way we can let the 3rd rule act like a subroutine that we can cal from the other 2 rules to carry out the common task of notification.

    Understanding that we can post our own invented events (#notifyBat in this case) with arguments and let other rules trigger on that

    rule("#notifyBat ...

    is a very powerful construct in ER and allow us to write compact rules.

    Btw, the first rule triggers when any device has its batter level changed

    and the second rule loops through all devices at startup to check if any has a low battery_level.

    We unfortunately need 2 rules for these task as it can't be combined.

     

    Yes, you can poll device properties with the api but a large part of ER's efficiency is that we let rules trigger on events. In this case when a device's battery level actually changes. If we have 100 devices this much more efficient. Always, when devices have property changes, they emit an event to tell us that. The exception is that some properties only emit events when their properties change values over a certain amounts. 

    For battery level I think that is the case. It can be that some devices only wake up once in a while to report it's battery level. ...and then an event is emitted, and events let ER trigger rules. 

    Edited by jgab
    • Thanks 1
    Link to comment
    Share on other sites

    I solved my problem with running the report at a specific hour by slightly modifying the rule with dead devices.

    Allegedly works! thanks again maestro!

     
    battLevel = 80
    --
    rule([[@ {catch, 09:00} =>
    post(#notify_other{id=teleg_fastvd}) 
    ]])
    --
    rule([[#notify_other{id='$id'} =>
    local msg1 = { "Devices with a low battery:" };
     for _,id in ipairs(bat_devices) do 
     if id:bat < battLevel then add(msg1,fmt(' %s',id:name)) end;
      end;
      if size(msg1)>1 then 
      fibaro.call(teleg_fastvd, 'sendMessage', table.concat(msg1,"\"), -700919895)
      else fibaro.call(teleg_fastvd, 'sendMessage', 'All batteries are normal', -700919895)
      end  ]])
     
    Link to comment
    Share on other sites

    I also wanted to clarify: is there any limit on the number of rules in ER4 or recommended limits?
    Why am I asking: I have about 70 rules in one of QA (and I have 4 of them separately), and when I restart ER, I see their launch rather slowly in the console...or it just seems so to me))) that's why the question arose)))

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, fastvd said:

    I also wanted to clarify: is there any limit on the number of rules in ER4 or recommended limits?
    Why am I asking: I have about 70 rules in one of QA (and I have 4 of them separately), and when I restart ER, I see their launch rather slowly in the console...or it just seems so to me))) that's why the question arose)))

    Well, you shouldn't judge it on the speed the console is updated. Have a look at the time logged instead.

    You could have a 

    Please login or register to see this code.

    at the end. That way you could time how long it takes to compile and load rules. 

    I may build that timing into ER in the next version.

    • Like 1
    Link to comment
    Share on other sites

    14 minutes ago, jgab said:

    Well, you shouldn't judge it on the speed the console is updated. Have a look at the time logged instead.

    You could have a 

    Please login or register to see this code.

    at the end. That way you could time how long it takes to compile and load rules. 

    I may build that timing into ER in the next version.

    Please login or register to see this image.

    /monthly_2023_01/image.png.05bf7a0102e663ece862b5d6bffcf89b.png" />

    Link to comment
    Share on other sites

    Jan, in the resume of starting ER I see 0 errors

    in debug I have

    Please login or register to see this code.

    What is your definition of counting errors?

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Hello, 

    I have a quick and easy question: I'm trying to make a timer to put a plug ON or OFF... Quite basic I know. I looked into past posts but could not find specific posts on how to handle variables (addition / multiplication /...) (I guess my tentative below is full of mistakes.. As it does not work).

    Any help welcome :)

     

    Please login or register to see this code.

     

    Edited by ndelaet
    Link to comment
    Share on other sites

  • Topic Author
  • On 1/19/2023 at 5:13 PM, Sjakie said:

    Jan, in the resume of starting ER I see 0 errors

    in debug I have

    Please login or register to see this code.

    What is your definition of counting errors?

    Please login or register to see this code.

     

    Well, it only errors when the rules are invoked, your errors are when the rules are define at startup, rule("....
    Can you post the whole rules (224-227)? It could be because some deviceID is wrong so the :value returns nil.

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 50 minutes ago, ndelaet said:

    Hello, 

    I have a quick and easy question: I'm trying to make a timer to put a plug ON or OFF... Quite basic I know. I looked into past posts but could not find specific posts on how to handle variables (addition / multiplication /...) (I guess my tentative below is full of mistakes.. As it does not work).

    Any help welcome :)

     

    Please login or register to see this code.

     

     

    First, to decrease timePhono with 60 you do

    timePhono = timePhone-60

    or

    timePhono -= 60

     

    So, I guess your rule could work with that change.

    Please login or register to see this code.

     

    I like to transform :central triggers to an event that is shorter to test against.

    Please login or register to see this code.

     

    This is another version, we just keep a counter of 30 and decrease it.

    Please login or register to see this code.

     

    • Thanks 1
    Link to comment
    Share on other sites

    Thanks a lot! This one is working perfectly (just removed 2 small typos with 'RemotePhono - RemotePhone')

    thanks! :)

     

    Please login or register to see this code.

     

    Edited by ndelaet
    Link to comment
    Share on other sites

    Jan, indeed they are device errors.

    HC3 is running but not all devices are already connected. Still struggling with some other jobs to get the new apartment ready.

    Just curious if this was count as error in ER.

    Thanks for the answer,

     

    Link to comment
    Share on other sites

  • Topic Author
  • 21 minutes ago, Sjakie said:

    Jan, indeed they are device errors.

    HC3 is running but not all devices are already connected. Still struggling with some other jobs to get the new apartment ready.

    Just curious if this was count as error in ER.

    Thanks for the answer,

     

    errors  count when rules crash when they execute. not when they load.

    Link to comment
    Share on other sites

    Thanks!

    Jan I want temporary to see how it's evolving only a message if humidity change with 5%

    this does't work it will message by each change of value.

    Please advice

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 2 weeks later...

    There was a problem that when connecting HC3(master)+ HC3L(slave) from time to time the connection with

    the slave controller simply disappears. At the same time, the slave is physically available, it is available via ICMP protocol and via the web interface. A simple reboot helps. Here came the idea to send the reboot command through the API.
    I don't know how to do it
    in ER4 post overload request! You need to describe the authorization there.

    And don't forget to specify the "recovery" parameter: false, otherwise it will go into recovery mode.

    Well, the main thing is to distinguish that it is really not available. It can also be done through the API.

    If you make an API request http://10.1.44.185/api/service/slaves
    , then we see a list of all slaves and their "online" status: true
    This is where we need to find out whether it is true or false
    Jan, help please)

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Edited by fastvd
    Link to comment
    Share on other sites

  • Topic Author
  • Something like this could work - haven't tried as I only have one box...

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    30 minutes ago, jgab said:

    Something like this could work - haven't tried as I only have one box...

    Please login or register to see this code.

     

     

    ERROR

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

  • Topic Author
  • Have you set up the credentials for the slaves?

    Please login or register to see this code.

     

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