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

Well... as if everything works)
I changed the report to arrive at 1:00 p.m.
At 12:42:46 I turned on the test light id=497 and at 12:51:11 I turned it off!
At 13:00 we received the report
Device 497 on for 492 00:08:12

Bravo, Jan!

Please login or register to see this attachment.

  • Like 1
Link to comment
Share on other sites

Well, my telemetry is almost done.

With the help of ER4 and constant support, help from Jan, we are already able to report:

1) count the operating time of the device (latest development)

2) calculate the used electricity

3) track dead devices

4) monitor the controller's memory and processor

5) work with the climate panel

and much more, which is too long to list here.

There is still one painful issue, these are battery devices. More precisely, their monitoring, telemetry.

I have your code:

---

bat_devices = {70,104}
battLevel = 80
rule([[#bat_devices{id=devices,property='batteryLevel',value="$batt"} & batt < battLevel =>
     local device = env.event.id;
     log("Less than %s% % battery charge of '%s' in room %s",battLevel,device:HTname,device:roomName);
     fibaro.call(teleg_fastvd, 'sendMessage', fmt("Less than %s%% battery charge of '%s' in room %s",battLevel,device:roomName), -700919895)
]])

 

---

But how to say it correctly...he doesn't quite do what I want. It is logical, but as far as I understand, it does not work when we would like.
For understanding, I will give an example of how I did it with dead devices.
1) If the device received the status of dead, then I IMMEDIATELY report it online in my telegram that there is a problem!
2) In the morning report I receive:
2.1) Uptime of the system
2.2) Number of consumed kilowatts
2.3) Are all devices available, if not - then I give a list of devices...

---

Similarly, it would be good with battery devices... let's say such a technical task
1) if the level is less than 50% on some device, then give a one-time message!
2) If the level is less than 25%, then throw in the morning report that there are problems with such and such devices...

 

P.S. in parallel, I ask the question, is it possible to extract data from another QA from ER4? Bottom line: on the French forum, there is already ready a VERY cool QA just for monitoring all devices on batteries. Can you extract the meaning from it directly or at least take some working moments of the code and use it for ER4?

 

Please login or register to see this link.

Link to comment
Share on other sites

as far as I understood, after studying more about logging in the console, the whole problem with the above-mentioned rule is that battery-powered devices give their information about the state of the battery very rarely, or if I understood correctly, only when in Notifications
 there is a check mark in Low Battery. in this case, the rule will really be followed little and it will not work. We can easily get this data through the API, but then for each device we want to monitor, we have to write a lot of code... how can we optimize the code to read several data from several devices at the same time through the API with one request?

Link to comment
Share on other sites

On 1/7/2023 at 11:39 AM, fastvd said:

Yes, I've been using your code to report energy consumption for about 1 year now, and I've gotten it to work the way I want, namely:
1) Every day at 09:00 a.m. it gives me a report on how much electricity was used yesterday
2) Every day at 09:00 a.m. gives me a report on how much electricity has been used since the beginning of the month (from the 1st)
It is very convenient for me to control my expenses in this way and to understand in general whether everything is working correctly! Thank you so much again Jan!
Perhaps someone did not fully understand the energy function, so I will give 2 versions of the code here.

 

Hi @fastvd,

 

Will try this out..

 

Could this be modified to only look at a specific device ID? ex just the fridge?

 

Thanks

Link to comment
Share on other sites

1 hour ago, Ace02 said:

Hi @fastvd,

 

Will try this out..

 

Could this be modified to only look at a specific device ID? ex just the fridge?

 

Thanks

I didn't understand what you mean! tell me clearly, what is your task!?

Link to comment
Share on other sites

  • Topic Author
  • 23 hours ago, fastvd said:

    Well, my telemetry is almost done.

    With the help of ER4 and constant support, help from Jan, we are already able to report:

    1) count the operating time of the device (latest development)

    2) calculate the used electricity

    3) track dead devices

    4) monitor the controller's memory and processor

    5) work with the climate panel

    and much more, which is too long to list here.

    There is still one painful issue, these are battery devices. More precisely, their monitoring, telemetry.

    I have your code:

    ---

    bat_devices = {70,104}
    battLevel = 80
    rule([[#bat_devices{id=devices,property='batteryLevel',value="$batt"} & batt < battLevel =>
         local device = env.event.id;
         log("Less than %s% % battery charge of '%s' in room %s",battLevel,device:HTname,device:roomName);
         fibaro.call(teleg_fastvd, 'sendMessage', fmt("Less than %s%% battery charge of '%s' in room %s",battLevel,device:roomName), -700919895)
    ]])

     

    ---

    But how to say it correctly...he doesn't quite do what I want. It is logical, but as far as I understand, it does not work when we would like.
    For understanding, I will give an example of how I did it with dead devices.
    1) If the device received the status of dead, then I IMMEDIATELY report it online in my telegram that there is a problem!
    2) In the morning report I receive:
    2.1) Uptime of the system
    2.2) Number of consumed kilowatts
    2.3) Are all devices available, if not - then I give a list of devices...

    ---

    Similarly, it would be good with battery devices... let's say such a technical task
    1) if the level is less than 50% on some device, then give a one-time message!
    2) If the level is less than 25%, then throw in the morning report that there are problems with such and such devices...

     

    P.S. in parallel, I ask the question, is it possible to extract data from another QA from ER4? Bottom line: on the French forum, there is already ready a VERY cool QA just for monitoring all devices on batteries. Can you extract the meaning from it directly or at least take some working moments of the code and use it for ER4?

     

    Please login or register to see this link.

     

    To check for low battery you need to do it differently

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    29 minutes ago, jgab said:

     

    To check for low battery you need to do it differently

    Please login or register to see this code.

     

    i have error

    Please login or register to see this attachment.

    Edited by fastvd
    Link to comment
    Share on other sites

    11 hours ago, fastvd said:

    I didn't understand what you mean! tell me clearly, what is your task!?

    I would like to monitor the power usage of my freezer and my fridge. If the compressor in one of these suddenly goes bad and stop, the powerusage wil deviate from the normal usage and I would like to be alerted. It could also, and maybe more likely, be that the temperature sensor in the fridge goes bad and forces the compressor to run constantly. This will the make the power usage way higher than normal and then i also would like to be alerted.

     

    So my though was, if possible, to compare yesterdays powerusage of a specific device (ex fridge), to the power usage of the same device on the day before that. If the deviation is more than like 10%, send an alert/push.

     

    Of course such a "rule" could be used for a lot of other things like for example monitoring a fountain pump, pool pumps and so on.

     

    Hopes this makes sense. :-)

    Link to comment
    Share on other sites

  • Topic Author
  • 42 minutes ago, fastvd said:

    i have error

    Please login or register to see this attachment.

    Sorry, 'bat_device' should be 'bat_devices'. Fixed in org. post.

    Link to comment
    Share on other sites

  • Topic Author
  • 34 minutes ago, Ace02 said:

    I would like to monitor the power usage of my freezer and my fridge. If the compressor in one of these suddenly goes bad and stop, the powerusage wil deviate from the normal usage and I would like to be alerted. It could also, and maybe more likely, be that the temperature sensor in the fridge goes bad and forces the compressor to run constantly. This will the make the power usage way higher than normal and then i also would like to be alerted.

     

    So my though was, if possible, to compare yesterdays powerusage of a specific device (ex fridge), to the power usage of the same device on the day before that. If the deviation is more than like 10%, send an alert/push.

     

    Of course such a "rule" could be used for a lot of other things like for example monitoring a fountain pump, pool pumps and so on.

     

    Hopes this makes sense. :-)

    If your device has a 'power' property you can monitor that value.

    It's easiest if you have defined low and high interval. Comparing with another day depends on if that day was "normal".

    If you have high and low values your rule could look like

    Please login or register to see this code.

    with some extra coding one could see if the values are outside the limits for a certain time....

    • Like 1
    Link to comment
    Share on other sites

    28 minutes ago, jgab said:

    Sorry, 'bat_device' should be 'bat_devices'. Fixed in org. post.

    and no...I saw that grammatical error right away, as well as the parentheses not being closed correctly...then the problem is something else!

    bat_devices = {70,104}
    battLevel = 80
    -- Check when device change bat state
    rule("bat_devices:dID:bat < battLevel => post(#notifyBat{id=env.event.id})")
    -- Check at startup
    rule("for _,id in ipairs(bat_devices) do id:bat < battLevel & post(#notifyBat{id=env.event.id}) end") -- the problem is here,but i don't know which one(((
    -- Notify
    rule([[#notifyBat{id='$id'} =>
         log("Less than %s% % battery charge of '%s' in room %s",battLevel,id:HTname,id:roomName);
         fibaro.call(teleg_fastvd, 'sendMessage', fmt("Less than %s%% battery charge of '%s' in room %s",battLevel,id:roomName), -700919895)
    ]])
    Edited by fastvd
    Link to comment
    Share on other sites

    3 hours ago, jgab said:

     

    To check for low battery you need to do it differently

    Please login or register to see this code.

     

    what is :dID:bat ?

    I see such a record for the first time!

    can you explain?)))

    Link to comment
    Share on other sites

  • Topic Author
  • 20 minutes ago, fastvd said:

    what is :dID:bat ?

    I see such a record for the first time!

    can you explain?)))

     

    when we do

    rule("55:isOn =>

    this :isOn returns the true/false value of device 55 being on.

    When we do 

    rule("{55,66}:isOn => 

    :isOn knows that it's applied to a list of devices. It will get the 'on' value for each device and return true if any device is on in the list.

    Likewise,

    rule("{55,66}:isOff => 

    will return true if all devices in the list are off.

    However, if we do

    rule("{55,66}:bat < 20 => 

    it will not work, because :bat applied to a list of devices returns the list of values

    Ex. {99, 95}

    It's difficult for :bat to return a single value - should it be the average?

    We can calculate the average of a list of values with

    rule("average({55,66}:bat) < 20 =>

    Anyway, in many cases when we test a list of devices we want to check the device that triggered the rule

    rule("{55,66}:bat & env.event.id:bat < 20 =>

    For convenience there is an operator that gets the triggered device out of a list of devices,

    :dID (should be read "device ID")

    rule("{55,66}:dID:bat < 20 =>

    :dID returns the device that triggered in the list, ex. 66, and then we apply :bat on 66 and get the current battery value of device 66 that just changed.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, fastvd said:

    and no...I saw that grammatical error right away, as well as the parentheses not being closed correctly...then the problem is something else!

    bat_devices = {70,104}
    battLevel = 80
    -- Check when device change bat state
    rule("bat_devices:dID:bat < battLevel => post(#notifyBat{id=env.event.id})")
    -- Check at startup
    rule("for _,id in ipairs(bat_devices) do id:bat < battLevel & post(#notifyBat{id=env.event.id}) end") -- the problem is here,but i don't know which one(((
    -- Notify
    rule([[#notifyBat{id='$id'} =>
         log("Less than %s% % battery charge of '%s' in room %s",battLevel,id:HTname,id:roomName);
         fibaro.call(teleg_fastvd, 'sendMessage', fmt("Less than %s%% battery charge of '%s' in room %s",battLevel,id:roomName), -700919895)
    ]])

    Sorry, my fingers were too fast. Second rule should be

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    3 minutes ago, jgab said:

    Sorry, my fingers were too fast. Second rule should be

    Please login or register to see this code.

     

    I do not understand what is difficult?
    maybe you mean that the bat parameter is not transmitted by the device often and therefore this rule does not work online?

    edited the rule, but there is still an error, but a different one!

    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 '%s' in room %s",battLevel,id:HTname,id:roomName);
         fibaro.call(teleg_fastvd, 'sendMessage', fmt("Less than %s%% battery charge of '%s' in room %s",battLevel,id:roomName), -700919895)
    ]])

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

     

    We can do it through  api, then everything is PERFECT!
    rule("@@00:01 & (bat_dev1=api.get('/devices/70').properties.batteryLevel) & bat_dev1 < 70 => log('The motion sensor in the child has a low battery, namely %s% %',bat_dev1)")

     

    One minus is that you have to write such a separate rule for each device! How to optimize it for a large number of devices - I don't know! Here you will be able to work with tables!

    Edited by fastvd
    Link to comment
    Share on other sites

  • Topic Author
  • 11 minutes ago, fastvd said:

    I do not understand what is difficult?
    maybe you mean that the bat parameter is not transmitted by the device often and therefore this rule does not work online?

    edited the rule, but there is still an error, but a different one!

    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 '%s' in room %s",battLevel,id:HTname,id:roomName);
         fibaro.call(teleg_fastvd, 'sendMessage', fmt("Less than %s%% battery charge of '%s' in room %s",battLevel,id:roomName), -700919895)
    ]])

    Please login or register to see this attachment.

     

    The log string needs to quote the % sign

    log("Less than %s%% battery 

     

    As I understand it battery level is reported when the battery level of a device changes a pre-defined amount.

    The rules in my example test all devices at startup (the for loop) and then triggers when a device reports a new battery level.

    No need to poll the device continuously....

    Link to comment
    Share on other sites

    2 hours ago, jgab said:

     

    The log string needs to quote the % sign

    log("Less than %s%% battery 

     

    As I understand it battery level is reported when the battery level of a device changes a pre-defined amount.

    The rules in my example test all devices at startup (the for loop) and then triggers when a device reports a new battery level.

    No need to poll the device continuously....

     

    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
    Edited by fastvd
    Link to comment
    Share on other sites

    I can't understand the errors...
    I want that if all batteries were normal, namely their charge level is more than indicated, then I received a report that everything is ok, and if less, then to say where the problematic devices are... but for some reason with the condition bat_devices:dID:bat > battLevel I can't tie any more conditions!

    in Rule:19[@ {catch, 09:00} & bat_devices:dID:bat > battLevel => ...]: ./include/EventRunner.lua:1802: ./include/EventRunner.lua:1171: attempt to compare number with nil

    Edited by fastvd
    Link to comment
    Share on other sites

  • Topic Author
  • 45 minutes ago, fastvd said:

    I can't understand the errors...
    I want that if all batteries were normal, namely their charge level is more than indicated, then I received a report that everything is ok, and if less, then to say where the problematic devices are... but for some reason with the condition bat_devices:dID:bat > battLevel I can't tie any more conditions!

    in Rule:19[@ {catch, 09:00} & bat_devices:dID:bat > battLevel => ...]: ./include/EventRunner.lua:1802: ./include/EventRunner.lua:1171: attempt to compare number with nil

     

    bat_devices:dID:bat > battLevel

    relies on that you got a battery event that triggered the rule, but your rule is a time rule.

    To see if all devices have a battery level > battLevel at 09:00 do

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

     

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