Low battery alerts
-
Moved from https://smarthome.community/topic/56/disable-vera-zwave-device-polling-at-the-device-level where you'll find the referenced code.
-
for k, v in pairs(luup.devices) do local var= luup.variable_get("urn:micasaverde-com:serviceId:ZWaveDevice1", "PollSettings",k) local bat = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel",k) if var ~= nil and v.device_num_parent== 1 and bat == nil then if var ~= 0 then luup.variable_set("urn:micasaverde-com:serviceId:ZWaveDevice1", "PollSettings", "0", k) luup.variable_set("urn:micasaverde-com:serviceId:ZWaveDevice1", "PollNoReply", "0", k) end end end
@rafale77 Can this be modified to send an alarm on low battery? This is something that I've been looking at since the OpenLuup migration.
Something like
for k, v in pairs(luup.devices) do local bat = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel",k) if var bat <= 20 then $do your alert thing here end end
Cheers
Sure that won't work as it is, but am I on the right track?
C
-
Right track, but crossing lanes, a bit. Three things not quite right:
- battery level variable may not exist
- even if it does, it's returned as a string
- you have a spurious 'var' that's been left in from the code you modelled this on
So...
for k, v in pairs(luup.devices) do local bat = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel",k) if bat and tonumber(bat) <= 20 then -- do your alert thing here end end
-
My routine to check for battery. I usually do it on first day of month, but if you pass currentday to the function, you'll get a complete report.
Just omit the parameter and it will notify you of low battery devices only. I usually run it a couple of times per day, unless it's the first day of month, of coursefunction checkBatteries(forceDay) local threshold = 20 local counter = 0 local deviceNames = "Low battery devices" -- override se primo del mese per report completo local currentTime = os.date("*t") if tonumber(currentTime.day) == tonumber(forceDay or 1) then threshold = 100 deviceNames = "Montly battery check" end for deviceNo, d in pairs(luup.devices) do local value = getVar(D_HA, "BatteryLevel", deviceNo) if value ~= nil and value ~= "" and tonumber(value) <= threshold then counter = counter + 1 local deviceName = (d ~= nil) and d.description or string.format("Device #%s", tostring(deviceNo)) deviceNames = string.format("%s\n - %s: %s%s", deviceNames, deviceName, tostring(value), "%") end end if counter > 0 then sendAlert(string.format("%s %s", emoji.batteries, deviceNames), nil, true) end end
-
Is there any way of 'actively' to notify when the battery level goes below a given value, without creating a low batter alert for every device? I guess just running this code above every hour or so would be close enough.
C
Depending on how frequently you want to check but... I have gone as far as creating a variable watch on the battery for that particular "k" device.
Add something like this in your startup lua:
luup.variable_watch("checkbat", "urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel",k)
and in that case I would use the function "checkbat" as follow
function checkbat() local bat = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel",k) if bat and tonumber(bat) <= 20 then -- do your alert thing here end end