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


Battery & device check 1.3.9

   (0 reviews)

3 Screenshots

About This File

Just another battery and device check script

The initial version and many updates were first uploaded to the german siio-forum.
After one year of use and many user hints, I would like to share my script with you.

What are the features of the script?
At first it reads the battery status of the devices from the HC2.
Over time, some useful features have been added.

For example, the status of non-battery devices is also being checked.

In addition,on some battery devices, the "last breached" status can be read.
This 
for example can be useful ifa battery died between 2 wake-up cycles. So please note if the last breached status changed or not.

There are a lot of variables for control and output, the meaning of each variable is explained in the attached PDF. Please play with it to see how it works.

How does the script work?
The script is triggered by the autostart function and every day at a specific time.

Depending on which days are entered in the variable "maildays" an email will be sent.

In addition to emails, the script can also send push or telegram messages.

At the end of the script a summary of the dead devices and a summary of the last breached status is displayed.

Have fun with the script and if you have any questions: I am happy to help.
 
Version history:
v 0.1    2017-03-12 : first published version
v 0.2    2017-05-10 : minor improvements
v 0.3    2017-05.14 : Introduced a few control variables
v 0.4    2017-06-10 : Added possibility to split the emails.
v 0.5    2017-06-16 : Corrected typing error in variable name, immediate push messages for dead devices
v 0.6.2  2017-06-22 : Just a few cosmetic changes
v 0.8.1  2017-06-24 : Major change in code, new functions 
v 0.8.3  2017-06-26 : Introduced mail numbers.
v 0.8.4  2017-07-04 : Check for "last breached" status introduced.
v 0.9.1  2017-08-23 : Introduced new array for sending email
v 0.9.2  2017-10-16 : Optimized ouput line lenght
v 0.9.3  2017-12-11 : Minor code changes 
v 1.1.3  2018-02-09 : Added section names
v 1.1.5  2018-02-18 : Minor code changes, optimized output
v 1.2.0  2018-03-18 : Output sorted by sections
v 1.2.1  2018-03-25 : Only english translation.
 

What's New in Version 1.3.9   See changelog

Released

Changelog for Version 1.3.9

 

What's new in version 1.3.9?

  • Above all, the output of the 'Summary' section has changed.
  • Via the variable 'onlySummaryM' only the output of the 'summary' is sent as an email.
  • The 'Summary' always comes in a separate mail (always the last one).
  • This became necessary for larger installations with about 40 battery devices and because Fibaro rejects mails that are too large.
  • In the 'Summary', the specification of hours is converted into days if the device has not been triggered for more than 72 hours (3 days).
  • In addition, at the end of the 'Summary' section there is an output about the runtime in days of the HC2 with the installed firmware version.

 

BatterieCheckV1.3.9-en.lua.txt is the English version.

BatterieCheckV1.3.9-DE.lua.txt is the German version.

 

Because the encoding ( UTF-8) often gets confused when uploading, I have now provided the LUA files as a txt file. Use UTF-8 encoding when saving as a lua file.

  • Like 3
 Share


Other Files from jwi


User Feedback

Recommended Comments

 

2 hours ago, lcseh said:

Can you explain in a few words, how to install this?

 

Simply download the file "BatterieCheckV1.2.1-en.lua" and open it in an editor. Then create an empty LUA scene and paste the contents of the LUA file there. Save and done.
For a better understanding you can still download the "BatteryStatus1.2.3en.pdf".

Good luck.

Link to comment
Share on other sites


Thank you for a very useful scene. 

I ran into the error below when the ID scanned is nil. 

[DEBUG] 10:48:01: [1;31m2018-12-01 10:48:01.847093 [ fatal] Unknown exception: /opt/fibaro/scenes/214.lua:293: attempt to index global 'devices' (a nil value)

 

I modified line 293 to:

           if (tonumber(isdead) == 1) and (oldNodeId ~= nodeID) then

and the script went on but I'm not sure if this is correct. The script now runs fine and I get a push message with dead devices however at the end of the output I still get an API error below:

[DEBUG] 10:54:31:
[DEBUG] 10:54:31: There are 19 other devices, such as virtual devices, ipCams etc.
[DEBUG] 10:54:31: [1;31m2018-12-01 10:54:31.792070 [ error] API: Not found
[DEBUG] 10:54:31: Mail Nr. 1 sent.

Link to comment
Share on other sites

@aladdin ,

Thank you for your feedbak. Yes, there are always situations where the script gives errors to some and not others. The variable

'isdead' is discussed earlier in line 157, but in 293. I forgot to query for 'nil' value. Clearly my mistake.
Line 293 should be something like this:

if (isdead ~= nil and tonumber (isdead) == 1) then

With the firmware 4.520 there should be no more API errors. That was fixed by Fibaro. Are you on FW 4.520?

I also discovered another mistake. The variable from line 127:
local tdev = {};
should be moved behind the variable
 
'local stathtml =' ';'
which is in line 137.

This has only a cosmetic effect on the output in the debug window if the script has been running for some time.

 

I'll soon release version 1.2.9, where the bugs are fixed and a small feature that gives an indication if a wrong phoneID is entered.

It would be nice if you kept me up to date.

Thanks again for reporting this bug and your feedback.

Link to comment
Share on other sites

53 minutes ago, Stiven said:

how do you find the phone ID and also when does the scene send an email to the user because I am not receiving one?

@StivenI'm not looking for the phoneIDs, I'm just checking if it exists in the API. If no match is found, a warning is displayed.

if you don't know your IDs you can use this little Lua code:

usr = api.get('/users')
for i,v in pairs(usr) do
    print(v.id..' - '..v.name)
end
print('----------------------')
ios= api.get('/iosDevices')
for _,i in pairs(ios) do
    print(i.id..' - '..i.name)
end

 

Regarding the email reception. The days on which an email is sent are in the variable "maildays", line 41.
Second, Fibaro does not allow you to send big emails. Therefore sometimes the variable "devpEmail" has to be reduced, line 40.

 

If you have any questions, do not hesitate to ask.

  • Like 1
Link to comment
Share on other sites

Hi! Thank you for this LUA code, it works fine on my 4.570. Keep up the good work! After some testing I found that your 25 device/email setting is the optimal setting.

What do I have to do in order to run the code automatically at the times specified?

Tick on the "start scene on startup"...?

Link to comment
Share on other sites

2 hours ago, johndeere said:

What do I have to do in order to run the code automatically at the times specified?

 

Hi, nice that you like it, the scene is triggered via %% autostart.

It is sufficient to set "Run Scene:" to Automatic, and "Max. Running instances:" to 2

 

Link to comment
Share on other sites

Thanks!

Is there a way to turn off push messages? So far I avoid push messages by providing a wrong phone ID... I know it's not the professional way to do it :)

Link to comment
Share on other sites

Hi @johndeere,

It is even easier, a few lines up there is the local variable "pushactiv". Just set it to false.
However, push messages are still sent for dead devices.
If you don't want that, just leave the variable phoneID empty.
For example, local phoneID = {}

Link to comment
Share on other sites

Yes, that is the professionel way, thanks!

I don't know why, but it does not send emails now... Settings are:

local pushactiv = false;  -- true - sendpush notification
local teleactiv = false;  -- true - send message via telegram

local phoneID   = {}   -- phone IDs for push notification

 

I did not change email IDs, only deleted phone IDs... Do you have any idea?

 

Link to comment
Share on other sites

5 hours ago, johndeere said:

... Do you have any idea?

Hi @johndeere , I guess so,?
Take a look at the local variable maildays.

There you can set the days on which you want to receive an email.

Link to comment
Share on other sites

Well, that"s OK, but yesterday when I ran the code, it sent me emails rightaway. I was playing with device per email variable, and tested many times, it worked fine, it sent me emails without delay. It also showed me in debug window: email nr1, nr2, nr3... but now there is no such line in debug window...

Link to comment
Share on other sites

Hi @johndeere ,

I think your local variable looks like this:

local maildays  = {1,4}  -- 1=Sunday, 2=Monday, 3=Tuesday ...7=Saturday

Which means that emails will be sent on Sunday and Wednesday.
If you want to have the emails every day, then you have to enter the value in the variable for all days. {1,2,3,4,5,6,7}

Link to comment
Share on other sites

I thought this variable refers only for automatically sent emails at the time specified...

Now I set the maildays for each day and it sends me emails again, each time I start it manually. Great! Thank you !

Edited by johndeere
Link to comment
Share on other sites

@Rik274 ,

Yes, fibaro has exchanged its mail servers and now it is so. Typical fibaro. I and others have complained about that.
The problem started last Thursday
There is a post about the mailserver exchange here in the forum from A.Socha.

regards, jwi

 

 

 

Edited by jwi
Link to comment
Share on other sites

Hi. Is it possible to redesign this script for HC3?
Thank you very much in advance.
Link to comment
Share on other sites

5 hours ago, budu said:
Hi. Is it possible to redesign this script for HC3?
Thank you very much in advance.

Here it is. Due to problems with Fibaros Mail Server, the mails are not formatted. Report problems here.

HC3-BatterieCheck0.1.0-EN..lua

  • Like 1
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
Add a comment...

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