[_CODE_] ADD - Alerter for Drowsy Devices V2.6

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:
[tt]https://docs.google.com/leaf?id=0Bz4omZm4gYcsNTVlYTlhOTItODM1ZS00NmRkLWJiM2MtNjU3ZTgxMjJhMjI0&hl=en_US&authkey=CICPpuwJ[/tt]

Sample output:

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 [tt]urn:micasaverde-com:serviceId:ZWaveNetwork1[/tt]

Thanks for the code Ap15e. I will test this out with my hotmail account.

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.

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

[ul][li]Is your dead device a battery operated one (first value in ‘Capabilities’ < 128 or ‘Capabilities’ empty)?[/li]
[li]Is it a physical Z-Wave device?[/li]
[li]Are ‘WakeupInterval’ and ‘LastWakeup’ set?[/li]
[li]How do you define ‘dead’?[/li][/ul]

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.

Thanks! Seems to work… :slight_smile:

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… :slight_smile:

Thanks for the great code Ap15e !

if you have a moment, could you explain ‘sensitivity’ a bit?

thanks.

…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

sensitivity explained:

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

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?

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

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

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.

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

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

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

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!

@dcowan

V1.5 should work now.

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

@FIST

Yes, you should still get an email with ‘hearbeat = 1’ (in intervals as defined by the timer of your scene).

Please try the latest version (V1.5).

If V1.5 does not work from a scene, copy the code into the ‘MiOS developers’ → ‘Test Luup code (Lua)’ window.
If the code fails there, chances are that your mail settings are wrong.

Ap15e,

I copy/pasted exactly what you have - still wasn’t getting an email so I used the smtp code from guessed post (http://forum.micasaverde.com/index.php?topic=3584.msg17474#msg17474) which looks exactly like yours and it works great!

Quick question, though, it’s saying that one of my battery devices is malfunctioning:
15 Pantry Door : Last wakeup 2 WakeupInterval(s) ago (WakeupInterval: 1800 seconds, BatteryLevel: 80)

But the device is working just fine… ?

Again - thanks for the code!!

Well, the device doesn’t wake up as instructed (or Vera does not receive the wakeup notification).

Thanks. here is my matrix. am i reading this wrong or is it telling me, for example, that my #36 Breakfast Light has no neighbors?

2010-12-29 21:20:39 1 3 4 5 7 9 10 11 12 13 14 15 16 17 26 29 34 35 36 37

1 _Scene Controller | 3 4 4 5 7 7 9 11 12 12 13 13 14 14 15 16 17 17 26 26 29 34 34 35 36
3 Master Bed Light | 5 7 9 10 12 13 14 16 17 26 29 34 35 36
4 1st Floor Thermostat | 7 9 10 12 13 14 15 16 17 26 29 35 36
5 Living Room Lamp |
7 Entry Sensor | 9 11 13 14 15 16 29
9 Living Room Big Lamp | 10 12 14 16 26 29 34 35 36
10 Front Door Lock | 14 15 16 29
11 2nd Floor Thermostat | 12 13 14 16 17 26 34 35 36 37
12 Master Closet Light | 13 16 17 26 34 35 36
13 Den Light | 14 16 17 26 34 35 36
14 Entry Light Outside | 15 16 17 26 29 34 36
15 Dining Room Light | 26 29 36
16 1st Floor Hall Light | 17 26 35 36
17 Master Closet Sensor | 26
26 Master Bathroom Light | 29 34 35
29 Living Room Light | 36
34 Master Bathroom Sensor |
35 Kitchen Light | 36
36 Breakfast Light |
37 Kitchen sensor |

per Vera’s UI, that device #36 has the following neighbors: 1,3,4,9,11,12,13,14,15,16,29,35,

thanks.

If a device with id i has a a neighbor with device id j, you’ll find i at the row for device j and at the column for device i:

Just check column 36: There is a ‘36’ in the rows for all devices with device ids 1,3,4,9,11,12,13,14,15,16,29,35.

BTW, the row ‘1 _Scene Controller’ looks strange (duplicate device ids).