We have moved at community.getvera.com

Author Topic: [_CODE_] ADD - Alerter for Drowsy Devices V2.6  (Read 62328 times)

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
[_CODE_] ADD - Alerter for Drowsy Devices V2.6
« on: December 25, 2010, 04:49:53 pm »
EOL, unsupported.

ADD addresses the missing feature documented at http://bugs.micasaverde.com/view.php?id=1244.
It was inspired by the thread at http://forum.micasaverde.com/index.php?topic=5100.0 and is meant to be used within a scene ('Luup' tab) with an interval based timer.

If a battery operated device is drowsy (defined as: 'current time' - LastWakeup > sensitivity * WakeupInterval), ADD will send an email to an address of your choice. In addition, ADD can send heartbeat messages.

Installation:
Create a new scene, copy the Lua code into the 'Luup' tab, adjust the user adjustable variables in the Lua code (you have to modify the SMTP server settings), 'Save lua', setup 'Timers', SAVE

Download:
https://docs.google.com/leaf?id=0Bz4omZm4gYcsNTVlYTlhOTItODM1ZS00NmRkLWJiM2MtNjU3ZTgxMjJhMjI0&hl=en_US&authkey=CICPpuwJ

Sample output:

Code: [Select]
Vera's Z-Wave routing matrix

2011-02-07 15:56:43           1  36  83  84  89  91  94 111 125 129 131 134 135 139 140 142 144 146 151 154 157 162 167 171 174 181 183 184 185
-----------------------------------------------------------------------------------------------------------------------------------------------
  1 Scene Controller      |      36  83  84  89  91  94 111 125         134 135 139 140 142 144 146 151     157             174 181           
 36 B  Wandspiegellampe   |          83  84      91  94     125                                             157             174 181           
 83 AZ Deckenlampe        |              84      91  94 111 125 129                         144     151     157             174 181           
 84 AZ Schreibtischlampe  |                      91  94                                     144                             174 181           
 89 WZ Stehlampe West     |                                                                 144     151 154                 174               
 91 FL Bewegungsmelder    |                             111 125                             144     151 154 157             174               
 94 AZ Tuerkontakt        |                             111 125                             144     151 154 157             174               
111 AR Abstellraumlampe   |                                 125                             144     151 154 157             174 181           
125 K  USL                |                                                                 144     151 154                     181           
129 K  3-in-1             |                                                                                                                   
131 WZ Rollladen S        |                                                                             154                 174               
134 WZ Danfoss O          |                                                                 144     151 154                 174               
135 AZ 3-in-1             |                                                                                                                   
139 WZ Danfoss N          |                                                                                                                   
140 SZ 3-in-1             |                                                                                                                   
142 B  Danfoss            |                                                                                                                   
144 K  Deckenlampe Kueche |                                                                                 157             174 181           
146 B  3-in-1             |                                                                                                                   
151 WZ Stehlampe Ost      |                                                                                                     181           
154 WZ Rollladen W        |                                                                                                 174 181           
157 SZ Deckenlampe        |                                                                                                 174 181           
162 AZ Taster 2f          |                                                                                                                   
167 TR Scene Controller   |                                                                                                                   
171 AR Motion Sensor      |                                                                                                                   
174 SZ Window Covering    |                                                                                                     181           
181 WZ 3-in-1             |                                                                                                                   
183 AZ 2f Mar             |                                                                                                                   
184 Taster 2f             |                                                                                                                   
185 Remotec Z-URC 550EU   |                                                                                                                   

dot:
https://chart.googleapis.com/chart?...

neato:
https://chart.googleapis.com/chart?...

twopi:
https://chart.googleapis.com/chart?...

circo:
https://chart.googleapis.com/chart?...

fdp:
https://chart.googleapis.com/chart?...

 91 FL Bewegungsmelder                      : Last wakeup   562 WakeupInterval(s) ago (WakeupInterval:   1800 seconds, BatteryLevel:    1)

139 WZ Danfoss N                            : Battery level    8, last battery report     0 hour(s) ago
 91 FL Bewegungsmelder                      : Battery level    1, last battery report    50 hour(s) ago


LastUpdate          : 1297088640 (2011-02-07 15:24:00)
LastDongleBackup    : 1297026447 (2011-02-06 22:07:27)
AutoConfigure       : nil
NetStatusID         : 1
NetStatusText       : #131: Getting the name
ComPort             : /dev/usb/tts/0
NodeID              : XXX
VersionInfo         : 2.78 L:1
HomeID              : House: XXXXX Node 1 Suc 1
Role                : Suc SIS:YES PRI:YES
ResetMode           : nil
InclusionMode       : nil
NodeType            : nil
Timeout             : nil
Multiple            : nil
SimulateIncomingData: nil
PollingEnabled      : 1
PollDelayInitial    : 20
PollDelayDeadTime   : 10
PollMinDelay        : 10
PollFrequency       : 60
LastError           : Node 139 failed
DelayProcessing     : nil

Signal quality (PollOk / PollNoReply / PollTxFail / failure rate)

 36 B  Wandspiegellampe                        14020     12    nil   0 %
 83 AZ Deckenlampe                             13006    816    nil   6 %
167 TR Scene Controller                          nil    nil    nil   0 %
 84 AZ Schreibtischlampe                       13940     23    nil   0 %
125 K  USL                                      7878   5013    nil  39 %
134 WZ Danfoss O                                   2    nil    nil   0 %
135 AZ 3-in-1                                   1337      3      1   0 %
171 AR Motion Sensor                             nil    nil    nil   0 %
174 SZ Window Covering                          7803   4602    nil  37 %
140 SZ 3-in-1                                   1377      1      2   0 %
142 B  Danfoss                                   nil    nil    nil   0 %
144 K  Deckenlampe Kueche                      11945   1453    nil  11 %
183 AZ 2f Mar                                    nil    nil    nil   0 %
184 Taster 2f                                    nil    nil    nil   0 %
185 Remotec Z-URC 550EU                          nil    nil    nil   0 %
151 WZ Stehlampe Ost                            9948   2445    nil  20 %
154 WZ Rollladen W                              6085    661    nil  10 %
157 SZ Deckenlampe                              9446   3372    nil  26 %
162 AZ Taster 2f                                 nil    nil    nil   0 %
146 B  3-in-1                                   1379      5      1   0 %
 89 WZ Stehlampe West                           9086    602    nil   6 %
131 WZ Rollladen S                                 1  10225    nil 100 %
139 WZ Danfoss N                                 nil    nil    nil   0 %
181 WZ 3-in-1                                   1091     17      2   2 %
129 K  3-in-1                                    888     18    nil   2 %
111 AR Abstellraumlampe                        10627   2609    nil  20 %
 91 FL Bewegungsmelder                          1007      6      1   1 %
 94 AZ Tuerkontakt                              1794    nil    nil   0 %

ADD 2.4, running time: 1 second(s)

History:
V1.1  adds support for battery level reporting.
V1.2  adds support for Z-Wave routing matrix.
V1.3  adds support for timestamp of Z-Wave routing matrix.
V1.4  fixes a bug if 'Capabilities' does not exist - thanks to dcowan
V1.5  fixes a bug if 'Capabilities' is an empty string - thanks to dcowan
V1.6  checks if a neighbor does exist - thanks to mda
V1.7  adds more checks for neighbor consistency - thanks to mda
V1.7a cosmetic changes
V1.8  renumbered devices fixed
V1.9  adds information about Z-Wave network, version number, running time - thanks to guessed
V2.0  adds compliance with RFC 2821 - thanks to Les F
V2.1  adds battery level report - thanks to Les F
V2.2  adds visualisation of neighbors - thanks to guessed
V2.3  adds the user adjustable variable include_routing_matrix_visualisation
V2.4  adds information about Z-Wave signal quality
V2.5  adds internal device ID to signal quality table
V2.6  updates variables for urn:micasaverde-com:serviceId:ZWaveNetwork1
« Last Edit: May 08, 2012, 12:52:07 pm by Ap15e »

Offline akashk

  • Full Member
  • ***
  • Posts: 123
  • Karma: +0/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #1 on: December 26, 2010, 10:45:06 am »
Thanks for the code Ap15e. I will test this out with my hotmail account.

Offline dcowan

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #2 on: December 27, 2010, 05:13:46 pm »
I had to make a change to the Capabilities check

local capabilities = tonumber(string.match(Capabilities,'([%d]*),'))
   if (capabilities ~= nil) and (capabilities< 128)

to stop a nil error.  This made it run.  Then when I run it I get no devices are dead but I know I have one that is.

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #3 on: December 27, 2010, 05:39:12 pm »
@dcowan

Thanks for pointing out the 'Capabilities' bug. Fixed in version V1.4.

I would like to find out why your dead device doesn't get listed by ADD:

  • Is your dead device a battery operated one (first value in 'Capabilities' < 128 or 'Capabilities' empty)?
  • Is it a physical Z-Wave device?
  • Are 'WakeupInterval' and 'LastWakeup' set?
  • How do you define 'dead'?

renato

  • Guest
Re: Alerter for Drowsy Devices (ADD)
« Reply #4 on: December 27, 2010, 06:32:38 pm »
this is too complicated for me but i am saving it anyway and apply it once i become familiar with lua code (when is a big ?). thanks.

Offline denix

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1088
  • Karma: +1/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #5 on: December 27, 2010, 07:11:45 pm »
Thanks! Seems to work... :)

I just had to remove "user = SMTP_AUTH_USER" and "password = SMTP_AUTH_PW" lines from smtp.send() call, as my local mail server doesn't require authentication for local senders... :)
Veras (1, 2, 3, Lite, Plus), lots of different Z-Wave modules, Luup plugins and theater/security integration.

Offline mda

  • Sr. Member
  • ****
  • Posts: 464
  • Karma: +9/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #6 on: December 28, 2010, 01:34:34 am »
Thanks for the great code Ap15e !

if you have a moment, could you explain 'sensitivity' a bit?

thanks.

Offline mda

  • Sr. Member
  • ****
  • Posts: 464
  • Karma: +9/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #7 on: December 28, 2010, 02:32:14 am »
...and one more question if i may:

the routing matrix generated shows:

   36 Breakfast Light        |                                                                              37

but that device in UI4 shows the following neighbors: 1,3,4,9,11,12,13,14,15,16,29,35,

if i understand correctly, i would have expected the emailed routing matrix to show 1,3,4,9,11,12,13,14,15,16,29, and 35 for device 36. several other devices have similar discrepancies. what am i missing?

thanks

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #8 on: December 28, 2010, 04:53:58 am »
sensitivity explained:

Code: [Select]
WakeupInterval = 1800 seconds
LastWakeup     = 11:00
time now       = 11:31

age of last wakeup = time now - LastWakeup = 1860 seconds

For sensitivity = 1:
ADD generates a report for this device, because 'age of last wakeup' > sensitivity * WakeupInterval

For sensitivity = 2:
ADD does not generate a report for the device, because 'age of last wakeup' < sensitivity * WakeupInterval
ADD would generated a report for the device, if 'age of last wakeup' > 2 * 1800 seconds = 1 hour

The precision of the timer of the battery operated devices is limited. Therefore, a device configured with WakeupInterval 1800 seconds could send reports every 1820 seconds. In order to avoid false alerts, sensitivity should be > 1.

For critical applications (we all know that we mustn't use Vera for such applications ...) I would suggest setting sensitivity to 1.2. This allows for a timer deviation of 20%.
« Last Edit: December 28, 2010, 08:59:09 am by Ap15e »

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #9 on: December 28, 2010, 05:00:35 am »
Quote
the routing matrix generated shows:

   36 Breakfast Light        |                                                                              37

but that device in UI4 shows the following neighbors: 1,3,4,9,11,12,13,14,15,16,29,35,

if i understand correctly, i would have expected the emailed routing matrix to show 1,3,4,9,11,12,13,14,15,16,29, and 35 for device 36. several other devices have similar discrepancies. what am i missing?

The neighbors are listed in the columns, not in the rows. If this does not answer your question, would you mind posting your matrix?

Offline dcowan

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #10 on: December 28, 2010, 08:13:30 am »
I still get

LuaInterface::CallFunction-3 Scene  12 failed [string "function scene_8()..."]:102: attempt to compare nil with number <0x2c0c>

unless I add a nil check before the tonumber call

Offline dcowan

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #11 on: December 28, 2010, 08:44:54 am »
I put a log statement in to test Capabilities and I get this from one device

50      12/28/10 7:42:25.840    luup_log:0: Capabilities= <0x340e>
50      12/28/10 7:42:25.841    luup_log:0: Capabilities=210,156,0,4,8,6|49,64,66,67,68,69,112,114,118,129,133,134, <0x340e>
10      12/28/10 7:42:26.440    LuaInterface::CallFunction-3 Scene 12 didn't return anything <0x340e>


I think the ,0x340e is the problem

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #12 on: December 28, 2010, 09:24:30 am »
The 'Capabilities' of at least one of your devices must be strange (non-nil and not beginning with a number followed by a comma). Of course, we could fix it by checking for non-nil, but I'd like to understand what's going on.

Quote
Capabilities= <0x340e>
looks strange (empty string?)

Could you log the Capabilities of all your devices, please?

Code: [Select]
luup.log( v.description .. ' *'..tostring(Capabilities)..'*')

I would suggest discussing this issue via personal messages and returning to the thread with a final solution.

Just for reference:
http://wiki.micasaverde.com/index.php/ZWave_Command_Classes
« Last Edit: December 28, 2010, 09:31:12 am by Ap15e »

Offline FIST

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +0/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #13 on: December 28, 2010, 11:39:18 am »
Thanks for the code! I've edited to use my ISP's SMTP server, but when I run the scene I don't get any emails (heartbeat  = 1 ). I also don't get any errors, but my understanding is that I should still get an email with heartbeat = 1.

Any suggestions??
Thanks!
Vera2 UI4 (1.1.1186), 3xVRI06, 1xVRI10, 4xVRS05, 3xVRS15, 2x VRF01, 5xVRP03, 2xTrane Therm, 2xAeon Labs Door/Window Sensor, 1xHSM100, 2xACT ZIR000, 1xForrezZ WWA-01, 2xGE 45613, 5x GE45606, 4xGE 45605, 2xGE 45604, 5xGE 45603, 4xGE 45602, 2xKwikset Deadbolts..

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Alerter for Drowsy Devices (ADD)
« Reply #14 on: December 28, 2010, 04:08:46 pm »
@dcowan

V1.5 should work now.

For whatever reason the value of the 'Capabilities' variable for your 'Door Sensor'  is an empty string.