Yet another battery level checker

Moderator: leecollings

Post Reply
User avatar
user4563
Posts: 108
Joined: Tuesday 19 October 2021 17:24
Target OS: Linux
Domoticz version: 2024.7
Contact:

Yet another battery level checker

Post by user4563 »

Hi,

There are many great battery level checkers on here including the built-in one. However, most will loop through all of the devices with one preset threshold and notify all users.

Some devices also report "0" all the time for their battery level even though they might not even be battery powered or report 0 temporarily if it needs to be refreshed, so I filtered those out.

In my case, I only wanted to notify myself of low battery events (via FCM) and not other users and I wanted different battery threshold levels for different devices. Each manufacturer or device are considered low battery at different levels.

Code: Select all

return {
    
	on = { 
		timer = {
		    'at 19:00',
	        	}
	     },
	 
	execute = function(domoticz, item)
	                if (domoticz.devices('Garage side door').batteryLevel <= 40 and domoticz.devices('Garage side door').batteryLevel > 0 and domoticz.devices('Garage side door').batteryLevel ~= nil) then
                        domoticz.log('Garage side door low battery '..domoticz.devices('Garage side door').batteryLevel..'%',domoticz.LOG_INFO)
                        domoticz.notify('Garage side door','low battery '..domoticz.devices('Garage side door').batteryLevel..'%',domoticz.PRIORITY_NORMAL, 'midx_1', domoticz.NSS_FIREBASE)
                    end

                    if (domoticz.devices('1st floor Air Temp').batteryLevel <= 30 and domoticz.devices('1st floor Air Temp').batteryLevel > 0 and domoticz.devices('1st floor Air Temp').batteryLevel ~= nil) then
                        domoticz.log('1st floor thermostat low battery '..domoticz.devices('1st floor Air Temp').batteryLevel..'%',domoticz.LOG_INFO)
                        domoticz.notify('1st floor thermostat','low battery '..domoticz.devices('1st floor Air Temp').batteryLevel..'%',domoticz.PRIORITY_NORMAL, 'midx_1', domoticz.NSS_FIREBASE)
                    end

                    if (domoticz.devices('2nd floor Air Temp').batteryLevel <= 30 and domoticz.devices('2nd floor Air Temp').batteryLevel > 0 and domoticz.devices('2nd floor Air Temp').batteryLevel ~= nil) then
                        domoticz.log('2nd floor thermostat low battery '..domoticz.devices('2nd floor Air Temp').batteryLevel..'%',domoticz.LOG_INFO)
                        domoticz.notify('2nd floor thermostat','low battery '..domoticz.devices('2nd floor Air Temp').batteryLevel..'%',domoticz.PRIORITY_NORMAL, 'midx_1', domoticz.NSS_FIREBASE)
                    end

                    if (domoticz.devices('Media room Air Temp').batteryLevel <= 30 and domoticz.devices('Media room Air Temp').batteryLevel > 0 and domoticz.devices('Media room Air Temp').batteryLevel ~= nil) then
                        domoticz.log('Media room thermostat low battery '..domoticz.devices('Media room Air Temp').batteryLevel..'%',domoticz.LOG_INFO)
                        domoticz.notify('Media room thermostat','low battery '..domoticz.devices('Media room Air Temp').batteryLevel..'%',domoticz.PRIORITY_NORMAL, 'midx_1', domoticz.NSS_FIREBASE)
                    end

                    if (domoticz.devices('Garage center door').batteryLevel <= 30 and domoticz.devices('Garage center door').batteryLevel > 0 and domoticz.devices('Garage center door').batteryLevel ~= nil) then
                        domoticz.log('Garage center door '..domoticz.devices('Garage center door').batteryLevel..'%',domoticz.LOG_INFO)
                        domoticz.notify('Garage center door','low battery '..domoticz.devices('Garage center door').batteryLevel..'%',domoticz.PRIORITY_NORMAL, 'midx_1', domoticz.NSS_FIREBASE)
                    end

    end
}

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