Page 1 of 1

Battery Level checker

Posted: Thursday 29 July 2021 9:12
by akamming
Hi,

just 2 share: made a small script which will notify me if battery powered devices are running low on battery

Code: Select all

return {
	on = { 
		devices = {
			'test'    -- put in any manual trigger you want to do for the dives
		},
		timer = {
		    'at 20:00', -- when you want 2 run the script
		}
		
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'Battery',
	},
	execute = function(domoticz, item)
	    domoticz.log("Started",domoticz.LOG_DEBUG)
        domoticz.devices().forEach(function(device)
            if (device.batteryLevel) then
                domoticz.log("device "..device.name.." has batterylevel "..device.batteryLevel.."%",domoticz.LOG_DEBUG) 
                if (device.batteryLevel < 15) then   -- set to whatever treshold you like
                    domoticz.log("Device "..device.name.." has low batterylevel ("..device.batteryLevel.."%)",domoticz.LOG_INFO) -- change notification logline to suit your needs
                    domoticz.notify(device.name,"Batterij moet vervangen worden ("..device.batteryLevel.."%)",domoticz.PRIORITY_NORMAL) -- change notification message to suit your needs
                end
            end
        end)	

	end
}
Confirmed to work with OpenZWave battery levels.

Re: Battery Level checker

Posted: Friday 05 November 2021 3:57
by user4563
Thank you for this!!

I did change line:

Code: Select all

if (device.batteryLevel < 15) then
to

Code: Select all

if (device.batteryLevel <= 40 and device.batteryLevel > 0 and device.batteryLevel ~= nil)
just to filter out those devices that report 0 or nil