The Vera Community forums have moved!

General => General => Topic started by: FlyBoyBob on April 04, 2011, 01:10:57 pm

Title: Battery Low notifications
Post by: FlyBoyBob on April 04, 2011, 01:10:57 pm
I have several battery-operated devices and have attempted in several ways to get email notifications on a low battery - nothing seems to work.

First of all - the same sensor (a 3-in-1 in this example) triggers events for light level and motion that send emails to me - every day right now as test.

I have a battery that is failing quickly in a 3-in-1 and have set several ways for it to notify me. For instance it was 47% this morning so I set notification events in the Notification tab of the _Light Sensor, _Motion Sensor, and _Temperature Sensor devices for "battery level goes below 46%". I also set up a scene for this device, exactly the same as other aspects (ie light, temp, motion) which work. The battery level is now 45% and no emails, no nothing.

Also - the "Fire warning event when battery is below:" field on the Settings tab of the main device does nothing for me = entering a value does not cause a red Save notice on the Dashboard, and returning to the tab shows a blank field again.

Any pointers/advise/sympathy appreciated
bob
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 05, 2011, 10:59:59 am
Bumping this back to the top of the list....

Has *anyone* gotten low battery notifications of any kind working on *any* device(s)?

I did a Search, no results that helped. This seems to me to be a very basic HA requirement(?)

Thanks in advance for any help,
bob
Title: Re: Battery Low notifications
Post by: FIST on April 05, 2011, 11:55:24 am
Look at Ap15e's great addition, ADD:
Alerter for Drowsy Devices

http://forum.micasaverde.com/index.php?topic=5130.0

It works great.
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 05, 2011, 01:58:02 pm
Look at Ap15e's great addition, ADD:
Alerter for Drowsy Devices

http://forum.micasaverde.com/index.php?topic=5130.0

Thank you "FIST" for your reply, but I don't think it applies to my situation. I have a number of battery operated Zwave devices, as I'm sure everyone does, and they are all very responsive to the wake-up intervals I set for them, and they all report accurate and timely data.

My problem is that I can set Notifications for lighting, temperature, humidity, etc readings going above or below a specified value. I get emails when I request them in the Event, everything works fine (most of the time). But I have never gotten a Low Battery notification even when set up the exact same way, on any device. The battery levels displayed on my Mios screen are accurate and timely, but NEVER trigger an event.

I was simply asking if anyone has ever made battery low notifications, or events, work.

bob
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 05, 2011, 04:18:35 pm
Here is a test on a 3-in-1 sensor. I set 2 Notifications on the _Temperature Sensor device:

Notification Battery level goes below
Name Upstairs Temperature Sensor battery low
undefined 47
Notify  ME

Notification Temperature goes below
Name Upstairs Temperature sensor below 67
temperature:  67
Notify  ME

...when the battery level was 48% and the temperature was 68F. The temperature dropped to 66 and I got an email. The battery level is now 40% and NO email.

Anyone have any ideas? Anyone?  :-\

 
Title: Re: Battery Low notifications
Post by: JOD on April 05, 2011, 09:00:51 pm
"Fire warning event when battery is below:" is broken.

http://bugs.micasaverde.com/view.php?id=1303

JOD.
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 05, 2011, 09:09:00 pm
"Fire warning event when battery is below:" is broken.

http://bugs.micasaverde.com/view.php?id=1303

JOD.

Thank you for replying JOD,

I noted that the ""Fire warning event when battery is below:" is broken" in my first post, it doesn't even Save a value.

My question is "does anyone have a battery low notification" by *any* means "working?". Even the notification event above that triggers on temperature levels or light levels every time does not work if it tests battery level.

Does anyone know why please?
bob
Title: Re: Battery Low notifications
Post by: JOD on April 05, 2011, 10:33:24 pm
Quote
I noted that the ""Fire warning event when battery is below:" is broken" in my first post, it doesn't even Save a value.
Actually you stated it did nothing for you; not that it was broken for everyone.
Quote
"Fire warning event when battery is below:" field on the Settings tab of the main device does nothing for me = entering a value does not cause a red Save notice on the Dashboard, and returning to the tab shows a blank field again.
Quote
My question is "does anyone have a battery low notification" by *any* means "working?"

FIST suggested you look at AP15e's ADD
Quote
Quote from: FIST on Today at 07:55:24 am
Look at Ap15e's great addition, ADD:
Alerter for Drowsy Devices
http://forum.micasaverde.com/index.php?topic=5130.0

Quote
Thank you "FIST" for your reply, but I don't think it applies to my situation.
I'm not sure what else applies to your situation then. AP15e's ADD is the only other battery reporting available that I know of and the only one that works.
Good luck.

JOD.
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 07, 2011, 07:59:06 am
Actually you stated it did nothing for you; not that it was broken for everyone.
Quote
My question is "does anyone have a battery low notification" by *any* means "working?"

FIST suggested you look at AP15e's ADD

I'm not sure what else applies to your situation then. AP15e's ADD is the only other battery reporting available that I know of and the only one that works.
Good luck.

JOD.

It does nothing for me, it is broken for me, it is broken for everyone. Thanks for clearing that up!

My "situation" is that I would like to (actually I need to) get a notification when a battery operated device's battery level is low. The battery level information is accurate, timely, and available through several means. Getting it to trigger an event seems impossible.

The "Fire warning event when battery is below:" box on the devices doesn't work, we've cleared that up, it's well documented, and I see it is assigned to you JOD to fix, last year. How's that going? (with all due respect, I know you guy's are volunteering your time and we all appreciate it)

I tried using method #2 = the drop-down on the Notification tab - that works for any level except battery level.

I tried Luup code to test the battery level - the same code that tests light level and works fine - does not work with battery level.

I tried AP15's ADD code - it fails with the "bad Lua code" message if copied directly from the document. After fixing that - it froze my Vera for several minutes which is a bad thing since I am not anywhere near the reset switch. Even if it could work it is noted in the thread that it does not send to gmail addresses so it is not an option for me.

I acknowledge that some brave programmers without gmail smtp servers and a lot of extra time on their hands have got it working, but I was looking for something a bit more what-I-paid-for.  ::)

Just looking for some constructive ideas here, but thanks for the response. My quoted question above still waits for an answer...

bob
Title: Re: Battery Low notifications
Post by: JOD on April 07, 2011, 11:32:27 am
 
Quote
The "Fire warning event when battery is below:" box on the devices doesn't work, we've cleared that up, it's well documented, and I see it is assigned to you JOD to fix, last year. How's that going?
Did you get into the Kool-Aid ?
I'm your Huckleberry, I'll get working on it for you right after lunch. 

JOD.
Title: Re: Battery Low notifications
Post by: myhomeserver on April 07, 2011, 11:48:35 am

Quote
The "Fire warning event when battery is below:" box on the devices doesn't work, we've cleared that up, it's well documented, and I see it is assigned to you JOD to fix, last year. How's that going?
Did you get into the Kool-Aid ?
I'm your Huckleberry, I'll get working on it for you right after lunch. 

JOD.

Slacker :)  While you're at it, can you fix my event issues with one of my schlage deadbolts :)
Title: Re: Battery Low notifications
Post by: JOD on April 07, 2011, 11:59:58 am
@myhomeserver,

Your Schlage lock event issue is on the event horizon to be fixed. Maybe I'll get to it after a few beers tonight.  ;D
Slacker indeed...  ;)

JOD.
Title: Re: Battery Low notifications
Post by: pgrover516 on April 07, 2011, 12:45:09 pm

Quote
The "Fire warning event when battery is below:" box on the devices doesn't work, we've cleared that up, it's well documented, and I see it is assigned to you JOD to fix, last year. How's that going?
Did you get into the Kool-Aid ?
I'm your Huckleberry, I'll get working on it for you right after lunch. 

JOD.
hahaha, I told you a while back that you should be on the payroll John! and when you finish those beers figure out why the only usefull battery info comes from my locks, the rest of the sensors read either 90 or 50 and never change, then after dinner you can start working on world peace     8)
Title: Re: Battery Low notifications
Post by: JOD on April 07, 2011, 01:16:08 pm
Oh no, my cover is blown!!
Ok, after dinner and those beers, I'll talk to my buddies over in Congress and discuss the possibilities of World peace.
Dont be surprised if Government is closed tomorrow while we work on this for you!!  :P

JOD.
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 07, 2011, 02:06:19 pm
Since I seem to have stirred the muddy waters of the genius pool and two gurus have popped to the surface....
I have two specific questions on this topic I hope can be answered:

1. If I use Luup code in a Scene to fetch a light level:
          local SS_SID   = "urn:micasaverde-com:serviceId:LightSensor1"
          local current_level = luup.variable_get(SS_SID, "CurrentLevel", deviceNo) or "0"
I can compare that to <  trigger_level and trigger an event.
Yet if I substitute "BatteryLevel" (and yes the deviceNo has both) it does not work.
Getting data via "data_request?id=lu_status" shows both values are accurate and up-to-date.
So.... shouldn't this work??
It's just 2 available values, or is the internal code doing something silly with battery level?
And if the answer is "something silly" are there other values that are treated silly or even more silly?  ::)

2. The ADD code:
Does the Vera send email notifications via a Mios SMTP server or does it send data that the Mios server formats into an email at the server?
If the limitation on the ADD code is that the SMTP server I have access to (gmail) won't work because of Auth or whatever - can I use the Mios SMTP?

Ok, I know that's several questions rolled into two topics, I cheated...

Thanks in advance for any help,
bob
Title: Re: Battery Low notifications
Post by: pgrover516 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!
Title: Re: Battery Low notifications
Post by: FlyBoyBob 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
Title: Re: Battery Low notifications
Post by: wscannell 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.
Title: Re: Battery Low notifications
Post by: pgrover516 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
Title: Re: Battery Low notifications
Post by: FlyBoyBob 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
Title: Re: Battery Low notifications
Post by: pgrover516 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
Title: Re: Battery Low notifications
Post by: FlyBoyBob 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
Title: Re: Battery Low notifications
Post by: CMRancho on April 14, 2011, 11:16:14 am
Yes, please post your code! The ADD doesn't work for me, either. Thanks!
Title: Re: Battery Low notifications
Post by: Intrepid 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.

Title: Re: detecting Battery Low
Post by: FlyBoyBob 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
Title: Re: eMailing a Battery Low notification
Post by: FlyBoyBob 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
Title: Re: Battery Low notifications
Post by: michaelk on April 14, 2011, 01:46:15 pm
I'm going to vote fluboybob= genius!

thanks for the code.

...off to cut and paste....
Title: Re: Battery Low notifications
Post by: FlyBoyBob 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  ;)
Title: Re: Battery Low notifications
Post by: pgrover516 on April 14, 2011, 02:03:42 pm
nice work Bob!
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 14, 2011, 02:05:56 pm
nice work Bob!

Got it working?

PS pgrover "516" = Long gIsland, I shudda guessed...  ;)
Title: Re: Battery Low notifications
Post by: rlmalisz on April 14, 2011, 02:08:26 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  ;)

So this is cool.  But just for clarity, this is going to send your username/password to the SMTP server in the clear, right?  Vera hasn't the capability to do ESMTP, so you really have no choice, right?

--Richard
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 14, 2011, 02:31:45 pm
So this is cool.  But just for clarity, this is going to send your username/password to the SMTP server in the clear, right?  Vera hasn't the capability to do ESMTP, so you really have no choice, right?
It will be sent from your Vera, through your router, and through your provider's servers just like your PC would. SMTP (Simple Mail Transfer Protocol) was originally designed to be interactive text from a dumb terminal, modern programs just emulate that. Someone could "sniff" it if they could tap into your wires yes, I know I could, but I could do that with many programs.

I prefer to let the Vera post the email directly than through the MCV servers, I think they would be a more likely target than my little old farmhouse in south central PA. (Oh no! I've posted my location!! I'm bound to be hacked now!!!)  :-X  ;)
Title: Re: Battery Low notifications
Post by: CMRancho on April 14, 2011, 03:06:37 pm
I've tried a couple of dozen combinations of email variables, etc., and have had no luck. Maybe it won't work with a mobileme mail account. Maybe I simply don't know what I"m doing. I'll leave it for those of you who don't require any luck to figure this out.

Sorry I don't have a success story to post, but thanks for sharing your code.

edit: I went back to my ADD and tried some of the variations I tried on this, and low and behold, it worked for the first time. So now I'm going back to try your BLN once more...
Title: Re: Battery Low notifications
Post by: pgrover516 on April 14, 2011, 03:09:45 pm
nice work Bob!

Got it working?

PS pgrover "516" = Long gIsland, I shudda guessed...  ;)
check, lol
Title: Re: Email notifications that work for everybody - guaranteed!
Post by: FlyBoyBob on April 14, 2011, 03:34:57 pm
This will work for everybody:
Code: [Select]
local myEmail     = "your valid email (they check)"

local message_out = "OMG WTF it works!!"
local send_to     = myEmail
local sender      = myEmail
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   = "smtp2go.com",
      port     = "2525",
      user     = myEmail,
      password = "verasmtp"}

It uses a "free" SMTP server, "free" as in 10 emails/day limit but how many batteries go dead in one day at your house? There are also minimal fee higher plans.

Go to http://www.smtp2go.com/ to create a free account, use "verasmtp" as the password or change it in the code above. Your normal email address will be your user name which you also enter into the top line above.

Copy and paste the above code into a new scene, enter your email address after having signed up to smtp2go.com, save Luup code, save changes, click "Run Scene", and it WILL WORK  ;D

Change things to suit, it's always easier to break code than make code...

Glad to help,
bob
Title: Re: Battery Low notifications
Post by: rlmalisz on April 14, 2011, 03:48:53 pm
I've tried a couple of dozen combinations of email variables, etc., and have had no luck. Maybe it won't work with a mobileme mail account. Maybe I simply don't know what I"m doing. I'll leave it for those of you who don't require any luck to figure this out.

Sorry I don't have a success story to post, but thanks for sharing your code.

smtp.mac.com appears to be running ESMTP, and is probably blocking what it perceives as relaying from an untrusted host...your Vera.  There's likely nothing you can do about this.  Bob's suggestion of using an intermediate account somewhere where things aren't buttoned down as well is your best bet.  It also means you're no longer sending your Mobileme username and password around in the clear--just the one for the relayer.  Mobileme may even have plaintext authentication blocked, and that's all you can do from Vera.

I administer our own mail servers at home, and they're all running ESMTP--it's really the only way you can prevent spammers from using your hosts (and your bandwidth) for polluting the universe.  We're locked down tight enough that I had specifically to enable relaying from machines in the house, since the mail servers are in the DMZ and on a different subnet.

ESMTP can be annoying, but they're doing it for good reason.

--Richard
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 15, 2011, 08:27:00 am
Ever the tinkerer...

I added a tiny bit of code to the battery-low detection code in my previous post (modified) to get a bit more information in the notification = the actual level in the device that triggered the notification in the first place.
Here's what it looks like now:

Quote
myVera@mi-server.net to me
The battery in the Garage 3-in-1 is now at 29%

Feel free to add an "OMG!" to personalise the message for yourself. Or a "Dear xxx" if you are a true geek (like me)  ::)

Hope that helps...
bob
Title: Re: Battery Low notifications
Post by: ballroller on April 27, 2011, 02:38:13 am
First of all, thanks for the great code!

My email is working beautifully. I have mine set up to check 5 different battery powered units. The test run ignored the first 4 units (which it should because they are
all over the 35% threshold that I set), but the email came back saying "The battery in the closet motion is now at 0%"  This particular motion is at 91% in reality.

Any idea why this is happening? Does it have to do with the test level?
Title: Re: detecting Battery Low
Post by: Intrepid on April 27, 2011, 07:49:06 am
Code: [Select]
local low_level  = ""

local low_test  = 30

What is the purpose of low-test?  what is '30' used for?  it appears to be the low value threshold.  But you say...

Quote
Change low_level for the low level trigger value.

low level?  or low_test?  If I want my trigger value to be 98, I would use...

Code: [Select]
local low_level  = "98"

local low_test  = 30

or

Code: [Select]
local low_level  = ""

local low_test  = 98

or what?
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 27, 2011, 08:12:29 am
... the email came back saying "The battery in the closet motion is now at 0%"  This particular motion is at 91% in reality.
Any idea why this is happening? Does it have to do with the test level?

The value of "0" is the diagnostic "or 0" in the line:
Code: [Select]
level = luup.variable_get(serviceId,variableId,44) or "0"
where if variable_get can't find the variable the code at least won't crash.

Also what it tells me is that you are probably using the deviceID for the Motion Sensor, rather than the "3-in-1". If you look in your Dashboard you will see that each 3-in-1 (I am assuming you are using HSM100s?) shows up as 4 devices = Light, Temperature, Motion, and 3-in-1. Only the 3-in-1 deviceID contains the BatteryLevel variable. Each of the other 3 devices will return a "0", as you have seen.

I would also recommend temporarily changing low_test to a value just above levels you are seeing on your Dashboard for each sensor. See that you get an email with the correct value, keeping in mind the code is not fancy and will only report the last detected low value.

Hope that helps!
bob
Title: Re: detecting Battery Low
Post by: FlyBoyBob on April 27, 2011, 08:44:19 am
What is the purpose of ...
...and several other excellent questions

Thanks "Intrepid" for pointing these things out - sometimes us programmers are not as explicit as we should be when it comes to code!

I have made several changes to my post that you are quoting from - post #24 on page 2 of this thread. I renamed the variables in question to make their purpose more obvious (I hope!) plus correcting the "trigger" variable name which I just plain got wrong in the explanation section.

Any further questions or confusions please post again - I appreciate the help!
bob
Title: Re: Battery Low notifications
Post by: ballroller on April 27, 2011, 11:15:52 am
I had the value for the HSM set wrong- I had the nodeID instead of the DeviceID. That last motion is now reporting fine, but I cant get the Schlage's to report. I set
 the low_test to 99, and those batteries are currently at 72% and 54%.

Also, I have 2 HSM's that are at 100%. Can I set the low_test to 101?

Here is the code used:

local room       = ""
local low_level  = "35"
local serviceId  = "urn:micasaverde-com:serviceId:HaDevice1"
local variableId = "BatteryLevel"
local warning    = "The battery in the "
local low_test  = 99
local level

level = luup.variable_get(serviceId, variableId, 22) or "0"
level = tonumber(level)
if (level<low_test) then
room = "Garage Entry-outside" low_level=level end

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

level = luup.variable_get(serviceId, variableId, 3) or "0"
level = tonumber(level)
if (level<low_test) then
room = "Garage Entry-inside" low_level=level end

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

level = luup.variable_get(serviceId, variableId, 60) or "0"
level = tonumber(level)
if (level<low_test) then
room = "JC Closet motion" low_level=level end

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

level = luup.variable_get(serviceId, variableId, 36) or "0"
level = tonumber(level)
if (level<low_test) then
room = "Pantry motion" low_level=level end

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

level = luup.variable_get(serviceId, variableId, 61) or "0"
level = tonumber(level)
if (level<low_test) then
room = "closet motion" low_level=level end

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


... the email came back saying "The battery in the closet motion is now at 0%"  This particular motion is at 91% in reality.
Any idea why this is happening? Does it have to do with the test level?

The value of "0" is the diagnostic "or 0" in the line:
Code: [Select]
level = luup.variable_get(serviceId,variableId,44) or "0"
where if variable_get can't find the variable the code at least won't crash.

Also what it tells me is that you are probably using the deviceID for the Motion Sensor, rather than the "3-in-1". If you look in your Dashboard you will see that each 3-in-1 (I am assuming you are using HSM100s?) shows up as 4 devices = Light, Temperature, Motion, and 3-in-1. Only the 3-in-1 deviceID contains the BatteryLevel variable. Each of the other 3 devices will return a "0", as you have seen.

I would also recommend temporarily changing low_test to a value just above levels you are seeing on your Dashboard for each sensor. See that you get an email with the correct value, keeping in mind the code is not fancy and will only report the last detected low value.

Hope that helps!
bob
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 27, 2011, 12:17:48 pm
Quote
Also, I have 2 HSM's that are at 100%. Can I set the low_test to 101?
Yes, you can set it to 101 and then 100% will trigger. However you might want to try the debug code below instead:

Quote
That last motion is now reporting fine, but I cant get the Schlage's to report.
I have a Schlage Deadbolt and can confirm that the serviceId and variableId work as is.

Here's what I do for debugging:
1. Copy your code into 2 text editors - 1 for preserving the original code and 1 for editing.

2. In your edit-for-test code delete all tested devices and use this one code group instead:
Code: [Select]
level = luup.variable_get(serviceId,variableId,3) or "0"
level = tonumber(level)
room = "Device Name" low_level=level

3. Copy and paste into your Scene.

4. Run it for each device, substituting deviceID and Device Name each time.

This debug code will read and email the BatteryLevel value for each device unconditionally. If you get a "0" the only thing that can be wrong is the deviceID.

Hope that does the trick,
bob
Title: Re: Battery Low notifications
Post by: Intrepid on April 27, 2011, 12:33:32 pm
FlyBoy, thanks for the awesome explanation.  I'll dig back into this soon.

Instead of email, I've been using prowl for notifications:

http://forum.micasaverde.com/index.php?topic=4508.0

I'm not sure if I can pass detailed variable in this though. 
Title: Re: Battery Low notifications
Post by: ballroller on April 27, 2011, 12:57:44 pm
Thanks Bob. I will try that tonight.
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 27, 2011, 01:12:29 pm
FlyBoy, thanks for the awesome explanation.  I'll dig back into this soon.
Instead of email, I've been using prowl for notifications:
http://forum.micasaverde.com/index.php?topic=4508.0
I'm not sure if I can pass detailed variable in this though. 

I have never used Prowl myself (BlackBerry user ::)) but I would think that if you used the "&description" variable and set it equal to my "message_out" you could send whatever text you want.

Just guessing  ???
bob
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 27, 2011, 01:16:32 pm
Thanks Bob. I will try that tonight.

One more thing: you only need
Code: [Select]
local message_out = warning..room.." is now at "..low_level.."%"

once - after all devices have been tested.

Or you could get clever and make them message_out1, 2, 3 etc and create a multiline report that shows all devices with low batteries in one email. I just didn't want to make the code too complicated for non-programmers.

bob
Title: Re: Battery Low notifications
Post by: ballroller on April 27, 2011, 01:34:29 pm
I'm "that guy" !!!


I just didn't want to make the code too complicated for non-programmers.

bob
Title: Re: Battery Low notifications
Post by: ballroller on April 28, 2011, 12:56:01 am
Well, I ended up writing a new scene for each battery to test. I am having problems saving my work with this UI4. It does strange things...

When I tried to edit the LUUP code and save it, when it was done saving it would revert back to the old code (everything I had done was gone!) , and sometimes it would create a whole new scene with the old code. So I would have 2 scenes that were wrong! So I deleted all of the scenes and used the wizard. That seems to work so I made a scene for every battery and added LUUP code to it. It didnt have any problem saving that for some reason.

I am going to let it run for a few days and then change the code to the low level test you originally did.

Thanks again!
Title: Re: Battery Low notifications
Post by: Intrepid on April 28, 2011, 07:00:41 am
OK, I tried the new code from post 24.  All my wireless devices are less than a week old, so the batteries may be 100%.  I let the trigger at 100 to test.

I get no email.

I see this in the log:
Quote
Scene::RunScene running 80 battery check <0x2c0c>

LuaInterface::CallFunction-3 Scene  80 failed [string "function scene_13()..."]:205: attempt to concatenate global 'low_level' (a nil value) <0x2c0c>

What does this mean?

edit: my battery icons in UI appear full, and I assume they show less full as battery life goes down, so this may be a case of me having full power right now.  I can try some used batteries on the weekend and see what happens.  Or is there a way to print the battery level to the screen, log?
Title: Re: Battery Low notifications
Post by: FlyBoyBob on April 28, 2011, 08:14:21 am
OK, I tried the new code from post 24.  All my wireless devices are less than a week old, so the batteries may be 100%.  I let the trigger at 100 to test.

I get no email.
You need to set the trigger to *more* than the current value, so as test you can set the trigger to 101 for your 100% batteries. No need to put stale batteries in.

Try the suggestions I put in reply#42 to test each device to give yourself a warm fuzzy feeling that it is working for all devices. Be sure to use the main device number for 3-in-1's = the one that shows "Battery Level" in your Dashboard.

Also test email as I describe in reply#24 independently of the battery level test code. Forum users have been having trouble getting good email notifications for a long time - make sure you can get that working by itself first. I have found it invaluable for testing other things = I can email myself variable values that are difficult to see any other way, for instance.

I see this in the log:
Scene::RunScene running 80 battery check <0x2c0c>
LuaInterface::CallFunction-3 Scene  80 failed [string "function scene_13()..."]:205: attempt to concatenate global 'low_level' (a nil value) <0x2c0c>

What does this mean?
It means you found an error in my sloppy posting. The reporting string should be the variable "level_to_report", which I have now fixed in #24. Thanks for finding that!

Hope that helps,
bob
Title: Re: Battery Low notifications
Post by: Intrepid on April 30, 2011, 08:16:45 am
Here is my combined code to test one device.  I took your post #24 and the smtptogo info.

This seems to work.  If I set the test level to 101, I get an email:

The battery in the Garage 3-in-1 is now at 100%

But when I change it back to a lower test limit of 30, I still get an email with blank battery status:

The battery in the  is now at %

Shouldn't the script terminate if it does not pass the test of actual status being greater than the test limit?  What am I missing to make it do nothing if the battery is greater than the test limit?

Thanks.

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, 8) 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

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

local myEmail     = "myemailgoeshere"

-- local message_out = "OMG WTF it works!!"
local send_to     = myEmail
local sender      = myEmail
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   = "smtp2go.com",
      port     = "2525",
      user     = myEmail,
      password = "smtptogopasswordgoeshere"}
Title: Re: Battery Low notifications
Post by: umtauscher on May 01, 2011, 12:49:47 pm
Hi Flybob,

thank you very much for your work. I am very much interrested in sending a battery low notification from my 3in1 sensor as well. Unfortuately the battery level is always reported 100% on the dashboard. Is there something wrong with my sensor, with vera's display or is there a trick to make it show a correct level?
TIA
Umtauscher
Title: Re: Battery Low notifications
Post by: wscannell on May 01, 2011, 04:39:13 pm
The HSM100 battery level seems to drop very quickly once the batteries get weak.  It seems to go from 100% to well under 50% in a week or so.  The batteries seem to last about 4 months when the unit is installed where there is a lot of motion (whether the sensor is armed or not).
Title: Re: Battery Low notifications
Post by: kaldoon on May 01, 2011, 04:51:01 pm
The Battery level on the HSM100 Sensors is a little flakey have 6 of them in my system and the level doesn't really seem to change - any place between 96 and 100% with brand new batteries and then 10 to 12 weeks later  the sensor stops transmitting motion - wake up the sensor and the battery level has dropped significantly.  Brand new batteries then everything is good again - keep 48 AAA batteries on hand   :-\
Title: Re: Battery Low notifications
Post by: FlyBoyBob on May 02, 2011, 01:37:50 pm
Intrepid:

You are missing code to exit if there is no message to send:
Code: [Select]
if (room=="") then
  return false
end
Place it just before the line that builds "local message_out". It will exit if the variable "room" is never filled in with text.

I put the code in as a single line myself but made it 3 lines here to make it clear to non-programmers. I probably dropped that out of my code examples because it is "between" the two jobs that they do - I will go back to my original posts again and see if I can put it in a logical place.

Thanks for pointing that out!
bob
Title: Re: Battery Low notifications
Post by: umtauscher on May 02, 2011, 01:42:15 pm
The Battery level on the HSM100 Sensors is a little flakey have 6 of them in my system and the level doesn't really seem to change - any place between 96 and 100% with brand new batteries and then 10 to 12 weeks later  the sensor stops transmitting motion - wake up the sensor and the battery level has dropped significantly.  Brand new batteries then everything is good again - keep 48 AAA batteries on hand   :-\
Thanks for that information. Mine reports still 100% after having changed the batteries about 4 weeks ago.
Cheers
Umtauscher
Title: Re: Battery Low notifications
Post by: FlyBoyBob on May 02, 2011, 01:48:14 pm
The HSM100 battery level seems to drop very quickly once the batteries get weak.  It seems to go from 100% to well under 50% in a week or so.  The batteries seem to last about 4 months when the unit is installed where there is a lot of motion (whether the sensor is armed or not).
This is a characteristic of alkaline batteries fortunately or unfortunately, not the HSM100s or the Vera. They stay at or near 100% for most of their usable life, then drop off rapidly. That's why I need the emails!

I have tried cheap generic-brand alkalines, and name brands other than Duracell, and all give me problems and much shorter life than the Duracells. I own my own airplane and the FAA prohibits the use of anything other than Duracells in my ELT (Emergency Locator Transmitter), which kind of convinced me to stick with the brand whenever I see battery problems. Just an opinion - not an endorsement!

Hope that helps,
bob
Title: Re: Battery Low notifications
Post by: pgrover516 on May 02, 2011, 02:57:33 pm
I have seven 3-in-1 sensors, 2 schlage locks, and three HM-TS001's and am using NiMH batteries, the only useful battery info seems to come from the locks, the 3-in-1's either read 100 or 90 and never change, the HM-TS001's read either 100 or 50 regardless if the batteries are fresh charged though they may fall lower eventually (sometimes on a unit with fresher batteries), only the locks fall off in the way one would expect, without usable info from the device reporting becomes a secondary issue
Title: Re: Battery Low notifications
Post by: FlyBoyBob on May 02, 2011, 04:23:01 pm
... am using NiMH batteries... regardless if the batteries are fresh charged though they may fall lower eventually (sometimes on a unit with fresher batteries)...
As reference regarding NiMH rechargeable batteries:

NiMH batteries only put out 1.2vdc vs 1.5vdc for alkaline, so with the 3 in these units you get 3.6v vs 4.5v. A device that takes 4 normal cells to make 6v needs 5 rechargeables to get the same supply voltage.

NiMh batteries lose 25% of their charge per month sitting on the shelf, alkaline batteries have a typical 100% charge shelf life of 5 years. In a device where we would like the batteries to last 6 months 25%/month is significant.

From topic http://forum.mios.com/index.php?topic=629.0:
One more thing to watch for, be careful when using rechargeable batteries with these motion sensors the voltage is a little lower and I found that the reliability of the sensor was not to be trusted.
Title: Re: Battery Low notifications
Post by: pgrover516 on May 02, 2011, 06:52:43 pm
I'm aware of the voltage differences involved but have had equal reliability with either type (alkaline or NiMH), the shelf life of Nimh batteries varies greatly from the older types to the newest which have much improved self discharge characteristics, and far superior cold weather performace (to alkalines) which I need as I am monitoring cold areas, in any case the battery readings of my sensors worked just the same with alkalines, "a little flaky" as pointed out by another, I love the work you've done here, just saying some of my sensors dont give useful reports
Title: Re: Battery Low notifications
Post by: FlyBoyBob on May 02, 2011, 07:13:08 pm
... just saying some of my sensors dont give useful reports
I appreciate the feedback and the report on using rechargeable batteries with these devices.

I would highly recommend though that anyone using anything other than Duracell batteries give them a try for at least a few days before looking for any other reasons for faulty operation. I have used both Energizer and store-branded batteries and also had trouble with these sensors. And there seems to be a period of time after putting in new or different batteries for them to "adjust", I'm not sure if it's the HSM100's themselves of the Vera, but sometimes good batteries and *time* fixes problems in these devices.

Thanks again for the feedback!
bob
Title: Re: Battery Low notifications
Post by: CMRancho on May 02, 2011, 08:32:34 pm
I switched over from Duracells to Eneloop rechargeables six or eight months ago. I use them in locks and 3-in-1s. The Eneloops give me far better reliability and far longer life than the Duracells ever did.
Title: Re: Battery Low notifications
Post by: Intrepid on May 03, 2011, 07:46:56 am
Intrepid:

You are missing code to exit if there is no message to send:
Code: [Select]
if (room=="") then
  return false
end
Place it just before the line that builds "local message_out". It will exit if the variable "room" is never filled in with text.

I put the code in as a single line myself but made it 3 lines here to make it clear to non-programmers. I probably dropped that out of my code examples because it is "between" the two jobs that they do - I will go back to my original posts again and see if I can put it in a logical place.

Thanks for pointing that out!
bob


Thanks, that seems to work.  Just curious, since I have 5 devices being tested in one scene, what will happen if more than one device is below the test limit?  I assume if will only format and send one message per run?  The first one?  then when that one is 'fixed' (batteries replaced), the next failing one would be reported?

Title: Re: Battery Low notifications
Post by: FlyBoyBob on May 03, 2011, 08:25:52 am
...what will happen if more than one device is below the test limit?  I assume if will only format and send one message per run?  The first one?  then when that one is 'fixed' (batteries replaced), the next failing one would be reported?
Actually since there is only one set of variables "room" and "level_to_report" they will be overwritten any time a level tests low, so it would be the last one that you get a report from.

I avoided getting fancy so the code would be minimal, but making separate variable sets, and testing each one, and adding end-of-line characters, and testing if none are set... would report all devices. But can you see why I tried not to complicate it?  :o

I would recommend you place the most important devices last in the code, like a door lock for instance, so it gets reported first.

Hope that helps,
bob
Title: Re: Battery Low notifications
Post by: Intrepid on May 03, 2011, 10:07:25 pm
is there a way to print the status message to the browser screen?
Title: Re: Battery Low notifications
Post by: Ap15e on May 04, 2011, 04:02:16 am
AFAIK, only a Luup plugin can display text on Vera's GUI. It wouldn't be too hard to implement using my minimal WAI plugin (http://forum.micasaverde.com/index.php?topic=6441.0) as a base.
Title: Re: Battery Low notifications
Post by: Intrepid on May 04, 2011, 10:18:11 am
If I'm reading correctly, the smtptogo service is only free for 7 days.  Am I missing something?
Title: Re: Battery Low notifications
Post by: FlyBoyBob on May 04, 2011, 01:21:08 pm
If I'm reading correctly, the smtptogo service is only free for 7 days.  Am I missing something?
"There's no such thing as a free lunch" ... or free SMTP service either!

I got many notices from smtptogo after about 2 weeks - all wanting me to sign up and pay money. I use my own smtp server and was only suggesting smtptogo as a valuable test site for anyone to see if they could get notifications working.

As I had mentioned early in this thread I had hoped someone would post a "free" webmail service (ie yahoo or hotmail or aol etc) that provides authentication compatible with the smtp code in the Vera, or that the Vera guys would improve the smtp code to work with better protected servers like gmail.

I also hope to win the lottery and be a millionaire...  ;D

Any/all postings on smtp server access appreciated here, I've already got my own which I pay $$ monthly for = sorry, not sharing  :P  (BTW I pay a LOT more/month than smtptogo charges, but I have websites)

It sure would be nice if MCV provided accounts on their smtp server for us wouldn't it?

bob
Title: Re: Battery Low notifications
Post by: ballroller on May 04, 2011, 01:27:45 pm
If you Google "free smtp" there are a number of services. I don't know if they're compatible with Vera, but at least there are some possibilities.
Title: Re: Battery Low notifications
Post by: FlyBoyBob on May 04, 2011, 01:34:09 pm
If you Google "free smtp" there are a number of services. I don't know if they're compatible with Vera, but at least there are some possibilities.
That's how I found smtptogo.com.

Most articles in that google pon-deficate about the evils of having open smtp servers, and spammers.

If you find something better post it here please!

Thanks for the anticipated help,
bob
Title: Re: Battery Low notifications
Post by: ballroller on May 04, 2011, 01:55:36 pm
I just signed up with jangosmtp using a mailinator email address, and it went smoothly. I have not tested it yet, though. They allow 200 emails/month. From their site:

SMTP Relay

    Relay your transactional emails through relay.jangosmtp.net. You can authenticate by IP Address or by SMTP Username/Password (SMTP AUTH).
    Our SMTP server analyzes your email, disassembles it, adds in open and click tracking mechanisms, and adds in DomainKeys/DKIM signatures.
    Our SMTP server then re-assembles your email and passes it to a high performance SMTP server for sending to your recipient.
    Login to your account to view statistics on emails sent, opens, and clicks. You can also view SMTP log files.

edit: corrected to 200 emails/month, not day
Title: Re: Battery Low notifications
Post by: harphaulingdad on May 11, 2011, 10:04:42 pm
Thanks for posting all this info! I tried the code out in a scene, using my back door open/close sensor as the device I want to check the battery level of. I get this error. Any help you can give me would be appreciated.

08   05/11/11 22:01:21.654   Scene::RunScene running 12 Back Door Sensor Battery Low <0x2c0c>
01   05/11/11 22:01:21.655   GetLuaInterface can't find device type: 3/0x8c4498 str: 4 <0x2c0c>
01   05/11/11 22:01:21.656   luup_variable_get interface 0x8c4cb0 args 3 <0x2c0c>

Title: Re: Battery Low notifications
Post by: FlyBoyBob on May 12, 2011, 08:19:20 am
Hi Newbie harphaulingdad,

Most likely the serviceID for your device is different from all of the battery devices I have so....

The only way I know to get your serviceID (unless someone smarter than me posts something else to help you) is the method I describe in my post:
http://forum.micasaverde.com/index.php?topic=5982.msg35708#msg35708

With the XML file you can find your device and the BatteryLevel "service" and "variable" names.

I also have a Windows-based program that will automate fetching the info for you and allow you to test the names directly. Read:
http://forum.micasaverde.com/index.php?topic=5870.0

When you get your info just substitute it into the lines:
Code: [Select]
local serviceId  = "urn:micasaverde-com:serviceId:HaDevice1"
local variableId = "BatteryLevel"

Hope that helps!
bob
Title: Re: Battery Low notifications
Post by: oTi@ on May 12, 2011, 08:38:38 am
The only way I know to get your serviceID [...]
For variables (luup.variable_get / luup.variable_set):
Go into the Advanced tab of the device. The variables are listed at the bottom. Hover over the name and you'll see the serviceId.

For actions (luup.call_action):
I have a scratch scene. Go to the Advanced tab of the scene. Add the device you're interested in and you'll get a drop-down of the actions supported, grouped by serviceId.
Title: Re: Battery Low notifications
Post by: FlyBoyBob on May 12, 2011, 09:14:53 am
The only way I know to get your serviceID [...]
For variables (luup.variable_get / luup.variable_set):
Go into the Advanced tab of the device. The variables are listed at the bottom. Hover over the name and you'll see the serviceId.

For actions (luup.call_action):
I have a scratch scene. Go to the Advanced tab of the scene. Add the device you're interested in and you'll get a drop-down of the actions supported, grouped by serviceId.


Great info, thanks! Learn something new every day. "hover" = who'd a thunk?

Thanks "oTi" for posting this,
bob
Title: Re: Battery Low notifications
Post by: oTi@ on May 12, 2011, 10:28:58 am
"hover" = who'd a thunk?
I guess you're not a helicopter pilot then. :P
Title: Re: Battery Low notifications
Post by: harphaulingdad on May 12, 2011, 02:36:09 pm
Sweet! It's ZWaveDevice1 as the service ID. I continue to learn something new every day!
Title: Re: Battery Low notifications
Post by: Intrepid on May 16, 2011, 07:17:10 am
Do the built-in battery notifications for locks, motion sensors, and door sensors work?  Why not just set those?

Also related, do the battery icons in the UI change as battery life goes down?  Or do they always look the same?

Title: Re: Battery Low notifications
Post by: wscannell on May 16, 2011, 07:56:56 am
Also related, do the battery icons in the UI change as battery life goes down?  Or do they always look the same?
The battery icons in the UI do change.  They go from green to yellow to red.  In addition, the amount of the battery that is filled in changes as the battery gets lower.  The filled in part of the battery is probably not too accurate - you would need to check the % reading for the device for a more accurate reading.

Typical of alkaline batteries, in the HSM100, there is a rapid decline from green to red in only a couple of weeks.
Title: Re: Battery Low notifications
Post by: FlyBoyBob on May 16, 2011, 08:09:00 am
Do the built-in battery notifications for locks, motion sensors, and door sensors work?  Why not just set those?
Built-in battery notifications don't work - that's what started this thread!  :-\

See:
"Fire warning event when battery is below:" is broken.

http://bugs.micasaverde.com/view.php?id=1303

JOD.

Andthe posts in the beginning of this thread.
bob
Title: Re: Battery Low notifications
Post by: axill on May 18, 2011, 02:59:23 pm
Let me share my work.

First of all the common functions to put into Startup Lua - will allow to use in any scene:

Quote
function my_escape (s)
    s = string.gsub(s, " ", "+")
    return s
end

function my_prowl (appl, event, description)
    local prowl_url      = "https://prowl.weks.net/publicapi/add?apikey="
        .. "your_key_is_here_generate_it_on_the_site"
        .. "&application=" .. my_escape(appl)
        .. "&event="         .. my_escape(event)
        .. "&description=" .. my_escape(description)
        .. "&priority=-1"
    luup.inet.wget(prowl_url)
end

local smtp = require("socket.smtp")

function my_email(USER_RECEIVING, subject_out, message_out)
  local SMTP_SERVER        = "smtp.mail.ru"
  local SMTP_AUTH_USER = "mymail@inbox.ru"
  local SMTP_AUTH_PW     = "password"        
  local SMTP_PORT             = "25"
  local USER_SENDING      = "mymail@inbox.ru"

  local mesgt = {
                  headers = {
                              to         = USER_RECEIVING,
                              from     = USER_SENDING,
                              subject = subject_out,
                              ["content-type"] = [[text/plain; charset="utf8"]]
                            },
                  body    = message_out
                }

  return smtp.send{
             from         = USER_SENDING,
             rcpt          = {USER_RECEIVING},
             source     = smtp.message(mesgt),
             server      = SMTP_SERVER,
             port          = SMTP_PORT,
             user         = SMTP_AUTH_USER,
             password = SMTP_AUTH_PW
        }
end

function my_emailme(subject_out, message_out)
    return my_email("my_predefined_email@gmail.com", subject_out, message_out)
end

Probably it can be hard for some of you because of Russian :) but mail.ru provides free and unlimited SMTP http based and working fine with Vera. I prefer prowl, you can change it to email. Function escape currently take care only about spaces, avoid =+&?% or add handle to escape function.
Prowl is delivering messages very quick to my iphone. For this I had to 1. register on the site prowl.weks.net 2. generate key 3. purchase application from apple store for $2,99.
I added content type to code which I got from Ap15e code (thanks). Without this email is showing up in email client incorrectly if you use not latin characters.

Secondly my Lua code from the battery monitoring scene:

Quote
local uri_motion    = "urn:micasaverde-com:serviceId:HaDevice1"

local type_motion = "urn:schemas-micasaverde-com:device:MotionSensor:1"
local type_smoke = "urn:schemas-micasaverde-com:device:SmokeSensor:1"
local type_remote= "urn:schemas-micasaverde-com:device:SceneController:1"
local type_combo= "urn:schemas-micasaverde-com:device:ComboDevice:1"

local report_level = 75
local report_age  = 1

local start_t = os.time()
local count_a = 0
local count_b = 0
local count_c = 0

for k,v in pairs(luup.devices) do
    count_a = count_a + 1
    if (v.device_type == type_motion or v.device_type == type_smoke
      or v.device_type == type_remote or v.device_type == type_combo)
      and (not v.invisible) and (v.device_num_parent == 1)
      and (tonumber(v.id) ~= 4) then
        count_b = count_b + 1
        local message       = 0
        local BatteryLevel  = luup.variable_get(uri_motion, "BatteryLevel", v.udn) or -1
        local BatteryDate   = luup.variable_get(uri_motion, "BatteryDate", v.udn) or -1

        if BatteryLevel ~= -1 and BatteryDate ~= -1 then
            local age_days = (os.time() - tonumber(BatteryDate)) / (60 * 60 * 24)
            if age_days > report_age then
                message = "Battery info was not updated for more than "
                    .. math.floor(age_days)
                    .. " days, level is " .. BatteryLevel .. "%"
            else
               if tonumber(BatteryLevel) < report_level then
                    message = "Battery level is " .. BatteryLevel .. "%"
               end
            end
        else
            message = "It is not possible to get device information ("
                .. BatteryLevel .. ", " .. BatteryDate .. ")"
        end
        if message ~= 0 then
            count_c = count_c + 1
            my_prowl("Battery monitoring", "(" .. v.id .. ") " .. v.description, message)
        end
    end
end

if count_c > 0 then
    local run_t = os.time() - start_t
    my_prowl("Battery monitoring", "Report", "total devices "
        .. count_a .. ", counted " .. count_b .. " from them " .. count_c
        .. "reported, run time " .. run_t .. " sec")
end


There is still something todo with scene controllers. My duwei battery operated scene controller (wall mounted button) is reporting battery but it seams it do not update it (no wake up and pool is not working). Remotec remote is not reporting battery at all - this why in my setup I avoid v.id = 4. You should change it or remove it.
I'm searching for battery operated devices refering to my setup, some device type can be missed.

Thanks to community - I found ready to work part of code and just order it in a structured way.
Title: Re: Battery Low notifications
Post by: Intrepid on May 18, 2011, 04:58:04 pm
Very nice, Axill.  Thank you!
Title: Re: Battery Low notifications
Post by: Intrepid on May 19, 2011, 06:44:10 am
I have partial success with Axill's code:

Code: [Select]
local uri_motion    = "urn:micasaverde-com:serviceId:HaDevice1"

local type_motion = "urn:schemas-micasaverde-com:device:MotionSensor:1"
local type_lock = "urn:schemas-micasaverde-com:device:DoorLock:1"

local report_level = 101
local report_age  = 1

local start_t = os.time()
local count_a = 0
local count_b = 0
local count_c = 0

for k,v in pairs(luup.devices) do
    count_a = count_a + 1
    if (v.device_type == type_motion or v.device_type == type_lock)
      and (not v.invisible) and (v.device_num_parent == 1) then
        count_b = count_b + 1
        local message       = 0
        local BatteryLevel  = luup.variable_get(uri_motion, "BatteryLevel", v.udn) or -1
        local BatteryDate   = luup.variable_get(uri_motion, "BatteryDate", v.udn) or -1

        if BatteryLevel ~= -1 and BatteryDate ~= -1 then
            local age_days = (os.time() - tonumber(BatteryDate)) / (60 * 60 * 24)
            if age_days > report_age then
                message = "Battery info was not updated for more than "
                    .. math.floor(age_days)
                    .. " days, level is " .. BatteryLevel .. "%"
            else
               if tonumber(BatteryLevel) < report_level then
                    message = "Battery level is " .. BatteryLevel .. "%"
               end
            end
        else
            message = "It is not possible to get device information ("
                .. BatteryLevel .. ", " .. BatteryDate .. ")"
        end
        if message ~= 0 then
            count_c = count_c + 1
            my_prowl("Battery monitoring", "(" .. v.id .. ") " .. v.description, message)
        end
    end
end

if count_c > 0 then
    local run_t = os.time() - start_t
    my_prowl("Battery monitoring", "Report", "total devices "
        .. count_a .. ", counted " .. count_b .. " from them " .. count_c
        .. " reported, run time " .. run_t .. " sec")
end

It works perfectly with the locks, but the HRDS1 door sensors and CA9000 motion sensors do not give battery status (picture below).  I think local type_motion = "urn:schemas-micasaverde-com:device:MotionSensor:1" is correct for both of these types (that's what shows in settings).

Any ideas?
Title: Re: Battery Low notifications
Post by: axill on May 19, 2011, 07:53:08 am
Look througth device_type of all of your battery operating devices and you will create a complete list of types to monitor

Title: Re: Battery Low notifications
Post by: Intrepid on May 19, 2011, 08:01:25 am
That's where I got the ones I used.  Both are the same:

HRDS1 door sensor:
urn:schemas-micasaverde-com:device:MotionSensor:1

CA9000 motion sensor:
urn:schemas-micasaverde-com:device:MotionSensor:1


They do not report the battery %.


Title: Re: Battery Low notifications
Post by: oTi@ on May 19, 2011, 08:08:22 am
They do not report the battery %.
But Vera is showing a value for them?
Title: Re: Battery Low notifications
Post by: Intrepid on May 19, 2011, 08:15:38 am
Under settings, they show Battery level: 100%.  But all 4 door sensors and 2 motion sensor all show 100%, so I wonder if it is reporting accurate battery levels.

 They're all less than a month old, so I guess it's possible for them to all be 100%.


And a couple of my locks show less than 100%, so they're working.
Title: Re: Battery Low notifications
Post by: oTi@ on May 19, 2011, 08:22:57 am
OK. Good. Just wanted to make sure the variables are populated with something.

Looking at that for the HSM100, it seems the battery stuff is part of the parent device (ComboDevice), not the motion sensor (MotionSensor).
Title: Re: Battery Low notifications
Post by: axill on May 19, 2011, 08:23:39 am
Under settings, they show Battery level: 100%
Some devices can only distinguish between 100% and some that very low level. So you will not see progress, but you will be informed to replace battery.

My script should report this devices as soon as they meet selection criteria by device_type.
The only reason that they not reported is Lua exception.
You need to play a litle bit by changing code or by adding luup.log calc and looking into logs.
Title: Re: Battery Low notifications
Post by: aecchalet on January 09, 2012, 01:25:08 pm
Is Axill's code the latest version of the BLN plugin?  Does it work with UI5?
Can someone provide some simple instructions for installing the smtp version?
For example, what do I need to load in the Startup Lua and how do I do that in UI5?
Then some guidance on the scene needed into which one loads the 2nd segment of Axill's Lua code would be greatly appreciated.  How often should that scene be scheduled to run?  Do I need to set any triggers?
Thanks