We have moved at community.getvera.com

Author Topic: Battery Low notifications  (Read 39173 times)

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #75 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

Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Battery Low notifications
« Reply #76 on: May 12, 2011, 10:28:58 am »
"hover" = who'd a thunk?
I guess you're not a helicopter pilot then. :P
Dezwaved at the moment...

Offline harphaulingdad

  • Sr. Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #77 on: May 12, 2011, 02:36:09 pm »
Sweet! It's ZWaveDevice1 as the service ID. I continue to learn something new every day!

Offline Intrepid

  • Hero Member
  • *****
  • Posts: 536
  • Karma: +4/-0
Re: Battery Low notifications
« Reply #78 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?

« Last Edit: May 16, 2011, 07:30:20 am by Intrepid »

Offline wscannell

  • Full Member
  • ***
  • Posts: 157
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #79 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.

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Battery Low notifications
« Reply #80 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

Offline axill

  • Full Member
  • ***
  • Posts: 183
  • Karma: +3/-0
Re: Battery Low notifications
« Reply #81 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.
« Last Edit: May 18, 2011, 03:14:41 pm by axill »

Offline Intrepid

  • Hero Member
  • *****
  • Posts: 536
  • Karma: +4/-0
Re: Battery Low notifications
« Reply #82 on: May 18, 2011, 04:58:04 pm »
Very nice, Axill.  Thank you!

Offline Intrepid

  • Hero Member
  • *****
  • Posts: 536
  • Karma: +4/-0
Re: Battery Low notifications
« Reply #83 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?

Offline axill

  • Full Member
  • ***
  • Posts: 183
  • Karma: +3/-0
Re: Battery Low notifications
« Reply #84 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

« Last Edit: May 19, 2011, 07:55:00 am by axill »

Offline Intrepid

  • Hero Member
  • *****
  • Posts: 536
  • Karma: +4/-0
Re: Battery Low notifications
« Reply #85 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 %.



Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Battery Low notifications
« Reply #86 on: May 19, 2011, 08:08:22 am »
They do not report the battery %.
But Vera is showing a value for them?
Dezwaved at the moment...

Offline Intrepid

  • Hero Member
  • *****
  • Posts: 536
  • Karma: +4/-0
Re: Battery Low notifications
« Reply #87 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.

Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Battery Low notifications
« Reply #88 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).
« Last Edit: May 19, 2011, 08:25:34 am by oTi@ »
Dezwaved at the moment...

Offline axill

  • Full Member
  • ***
  • Posts: 183
  • Karma: +3/-0
Re: Battery Low notifications
« Reply #89 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.