Battery Level checker

Moderator: leecollings

Post Reply
akamming
Posts: 343
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Battery Level checker

Post 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.
User avatar
user4563
Posts: 108
Joined: Tuesday 19 October 2021 17:24
Target OS: Linux
Domoticz version: 2024.7
Contact:

Re: Battery Level checker

Post 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
ODroid H4+ / Ubuntu server
Aeotec Z-Stick Gen5+
ZWave-JS-UI
Domoticz for Android
Domoticz Scenes add-on in Kodi
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests