How to check if device is battery powered

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.

Any ideas?

There should be a device variable called BatteryLevel in the service

urn:micasaverde-com:serviceId:HaDevice1


Edit: apologies, I got the original serviceId incorrect. Thanks to @chrifabre for pointing this out.

1 Like

BatteryLevel - urn:micasaverde-com:serviceId:HaDevice1
BatteryDate - urn:micasaverde-com:serviceId:HaDevice1

local niv_bat = luup.variable.get("urn:micasaverde-com:serviceId:HaDevice1","BatteryLevel", Id)
1 Like

You’re absolutely right. I made a mistake in the serviceId. Apologies. I’ll edit my post so as not to confuse!

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
1 Like

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:

That worked perfectly!

Thanks rigpapa.


Pete

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.