How can I use LUUP to check if a device is battery powered?
I want to write a LUUP function that will check the battery level, but only on battery powered devices. luup.devices does not list BatteryLevel or BatteryDate, so I can’t use that.
Yes, that works for battery devices, but if you try it on non-battery devices (i.e. the attribute does not exist), the code fails and the function bombs out.
That is my problem, I need to know if a device is battery powered before I try that. I want to generate a report on battery conditions without knowing, in advance, which devices are battery powered.
local niv_bat = luup.variable.get("urn:micasaverde-com:serviceId:HaDevice1","BatteryLevel", Id)
if not niv_bat then
-- Device is not battery powered
else
-- Device is battery powered
end
If you are looking for information on battery operated devices you can also use the “event watcher” plugin. It gives a simple but usefull report on battery operated devices: