We have moved at community.getvera.com

Author Topic: Battery Low notifications  (Read 37678 times)

Offline pgrover516

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1013
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #15 on: April 07, 2011, 02:30:22 pm »
Hey Bob,
Not sure who you are referencing but my guess is you are further up the genius chain than me. Jod on the other hand can rebuild a 100+ device network before I choke my coffee down in the morning. It is exactly because he is amazingly productive as a volunteer that I got a kick out the notion that he was "assigned" to correcting the code, no slight of you intended and glad you're here, just having a bit of sport. Being a non genius myself I dont know any code or would gladly respond to your questions, there are bonified geniuses here who I hope will soon respond, Cheers!
V1,V2,V3,VLite,Express Controls HSM-100,Intermatic HA20C, HA04C,HA02C,HA09, Leviton VRP15-1LW, VRS15-1LX,Home Manageables HM-TS001,Schlage FE599, Schlage BE369, Cooper RF9500, Aeon Labs Minimote, Schlage TZEMT400AB32MAA+more

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #16 on: April 07, 2011, 02:40:02 pm »
"Having a bit of sport" = that's me!

Hoping to incite any of those-in-the-know to rise to the challenge of feeding my ignorance as well, and maybe some others that have similar problems but didn't know how to ask.

You sound like a fellow Brit there "pgrover516", or is it a Brit Fellow?   ;)

bob

Offline wscannell

  • Full Member
  • ***
  • Posts: 157
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #17 on: April 07, 2011, 02:55:11 pm »
To answer your question about the email notifications.  Based on what I have seen, the notifications are sent to one of the Mios servers.  The server then sends any email or SMS messages that were requested.  You can see any of the notifications that you have occurred on the Mios server by clicking on the Events tab.

Offline pgrover516

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1013
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #18 on: April 07, 2011, 02:56:22 pm »
You sound like a fellow Brit there "pgrover516", or is it a Brit Fellow?   ;)

bob
Just stealing expressions, I'm a native New Yawker, welcome to the new world! <grinning>,
Paul
V1,V2,V3,VLite,Express Controls HSM-100,Intermatic HA20C, HA04C,HA02C,HA09, Leviton VRP15-1LW, VRS15-1LX,Home Manageables HM-TS001,Schlage FE599, Schlage BE369, Cooper RF9500, Aeon Labs Minimote, Schlage TZEMT400AB32MAA+more

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #19 on: April 07, 2011, 03:04:26 pm »
Just stealing expressions, I'm a native New Yawker, welcome to the new world! <grinning>,
Paul

I'm a native New Yawker as well, of the Long gIsland variety. Spent many years in Old Blighty (Cambridge, UK) however recently and miss some of the handy phraseology = bollocks, for instance, which I hope not to have to apply in this thread...  ;)

cheers, bob

Offline pgrover516

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1013
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #20 on: April 07, 2011, 03:54:32 pm »
I'm a native New Yawker as well, of the Long gIsland variety. Spent many years in Old Blighty (Cambridge, UK) however recently and miss some of the handy phraseology = bollocks, for instance, which I hope not to have to apply in this thread...  ;)

cheers, bob
Funny, small world, grew up in North Massapequa and now I have one foot on LI and the other upstate, hence the need for vera, .... I love the color of the Brit expressions, they can say mundane stuff and it sounds cool, also like the way they understate/overstate stuff, if your arm gets hacked off you're having "a bit of trouble" but if you're stuck in traffic it's "a bloody mess",  all we have to offer is dis,dat,deese,dem,and dose, lol
V1,V2,V3,VLite,Express Controls HSM-100,Intermatic HA20C, HA04C,HA02C,HA09, Leviton VRP15-1LW, VRS15-1LX,Home Manageables HM-TS001,Schlage FE599, Schlage BE369, Cooper RF9500, Aeon Labs Minimote, Schlage TZEMT400AB32MAA+more

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #21 on: April 14, 2011, 09:42:23 am »
Got battery low notification emails working - reliably, easily (once it worked!), and without guru help (sadly)  :P

To answer my own questions, using a Scene and some noddy Luup code:

1. I read the BatteryLevel of each battery device, if it is below a defined value I fill in a string with the name of the device.

2. After reading all battery devices - if the name string is empty I exit.

3. Otherwise I use the SMTP function to send myself an email, which is surprisingly instantaneous compared to notifications that go through the MCV servers.

4. I set a timer to execute the code once a day at 6am.

Simple.
I can post actual code if anyone is interested.

Hope this helps somebody,
bob

Offline CMRancho

  • Hero Member
  • *****
  • Posts: 1008
  • Karma: +1/-0
Re: Battery Low notifications
« Reply #22 on: April 14, 2011, 11:16:14 am »
Yes, please post your code! The ADD doesn't work for me, either. Thanks!
Vera123beta; Schlage, Kwikset, TZEMT400; Linksys cams, Smarteye cams, HSM100; Aeon, Everspring, Cooper, Leviton, Intermatic, FortrezZ, Global Caché, USB-UIRT, Somfy, etc.

Offline Intrepid

  • Hero Member
  • *****
  • Posts: 536
  • Karma: +4/-0
Re: Battery Low notifications
« Reply #23 on: April 14, 2011, 11:18:36 am »
yes please.  And smtp function?  can you elaborate?  is it a luup command?

I'm running homeseer also, which i use smtp to gmail to xxx@att.xxx to get sms and email, and homeseer is very quick.   I'd like to do the same in vera.


Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: detecting Battery Low
« Reply #24 on: April 14, 2011, 12:32:52 pm »
Since I got 2 requests for "the code" and specifically "the email part" I will reply in two sections with appropriate Subjects for future searches.

Detecting a low battery level in any number of devices:
Code: [Select]
local test_for_below  = 30

local room       = ""
local level_to_report  = ""
local serviceId  = "urn:micasaverde-com:serviceId:HaDevice1"
local variableId = "BatteryLevel"
local warning    = "The battery in the "
local level

-- duplicate these lines for each device to test
level = luup.variable_get(serviceId, variableId, 44) or "0"
level = tonumber(level)
if (level <  test_for_below) then
  room = "Garage 3-in-1"
  level_to_report = level
end
-- end of duplicated lines

if (room=="") then return false end

local message_out = warning..room.." is now at "..level_to_report.."%"

The code gets a battery level from 3-in-1, temp/humidity sensor, and Shlage deadbolt devices for me, you might need to change serviceId for other devices but I doubt it.

For each device - change the device number, 44 in this example, and the descriptive text for the email. Check in the Dashboard to be sure that device shows a battery level on the Settings tab.

Change "test_for_below" to the % battery level you want to trigger when it goes below.

Put this code in a new Scene and set a timer to run it, mine is set for every day at 6am.

Copy the "to duplicate" lines for as many devices as you want to check, changing the device ID and text for each.

If you don't want to do an email notification (see my next post) you can change the room= "xxx" part to "return true" and put "return false" as the last line of the code, then assign commands to the Scene.

That's all the code you need to scan all of your battery devices and get a Low Battery in any device to execute some command(s), or set up to send an email.

Hope that helps,
bob
« Last Edit: May 02, 2011, 01:39:20 pm by FlyBoyBob »

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: eMailing a Battery Low notification
« Reply #25 on: April 14, 2011, 01:09:14 pm »
The email-sending part of the Low Battery Notification code:
Code: [Select]
if (room=="") then return false end

local send_to     = "email address to receive notification"
local sender      = "any valid email domain"
local subject_out = "Battery Low Notification"

local smtp = require("socket.smtp")

local mesgt    = {
      headers  = {
      to       = send_to,
      from     = sender,
      subject  = subject_out},
      body     = message_out}

local result   = smtp.send {
      from     = sender,
      rcpt     =  {send_to},
      source   =  smtp.message(mesgt),
      server   = "smtp.xxx.com",
      port     = "587",
      user     = "xxx",
      password = "xxx"}
(code copied and modified from several forum postings, credit due where appropriate)

Specific to my implementation:
1. If no battery was low - "room" is still blank, therefore quit for the day
2. The body of the email is message_out, which is the concatenation of the generic warning and the device that caused it.

Generic to sending emails:
1. Fill in "send_to" with your email address that will receive the notification.
2. "sender" with anything, and although "god@heaven.above" works it gets tossed into Spam  :o
3. "server" with any email account that allows you to use their smtp server, I have my own domains but I understand yahoo and hotmail are fairly loose with their servers(?). gmail is too secure for the current socket.smtp AFAIK.
4. smtp port = 587 or 25, get that info from your provider.
5. Your valid user name and password with your email provider.

Things to watch for:
1. Best to load the generic sending-emails part into a new Scene by itself, substituting message_out with "OMG WTF it WORKS!", for instance, and tweak the hard parts (your email account parameters) until it works. Just Run Scene and hold your breath...
2. My domain server checks the sender address against the account address for security, so don't get too creative with Reply addresses too quickly.
3. Maybe somebody could test and post which "free" servers have loose enough security to work. Set up an email account with them rather than banging your head against a gmail wall. Just a suggestion...

Hope that helps, and it would help a LOT if others could post "free" servers that they got it to work with,
bob
« Last Edit: April 15, 2011, 08:30:34 am by FlyBoyBob »

Offline michaelk

  • Hero Member
  • *****
  • Posts: 633
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #26 on: April 14, 2011, 01:46:15 pm »
I'm going to vote fluboybob= genius!

thanks for the code.

...off to cut and paste....

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #27 on: April 14, 2011, 02:02:27 pm »
thanks for the code.
...off to cut and paste....

I will accept at least the "thanks" once I've seen some posts about "Hey it works!!" and what servers and settings were used.

In the meantime - thanks for trying it and hope it works for ya  ;D

Post results asap please,
(hopefully not "flu" boy) bob  ;)

Offline pgrover516

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1013
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #28 on: April 14, 2011, 02:03:42 pm »
nice work Bob!
V1,V2,V3,VLite,Express Controls HSM-100,Intermatic HA20C, HA04C,HA02C,HA09, Leviton VRP15-1LW, VRS15-1LX,Home Manageables HM-TS001,Schlage FE599, Schlage BE369, Cooper RF9500, Aeon Labs Minimote, Schlage TZEMT400AB32MAA+more

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #29 on: April 14, 2011, 02:05:56 pm »
nice work Bob!

Got it working?

PS pgrover "516" = Long gIsland, I shudda guessed...  ;)