I have partial success with Axill's code:
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?