Low Battery Notifications
Domoticz

Low Battery Notifications

This script checks all devices for low battery levels every hour and sends notifications to the AWTRIX3 device for devices below 20%.
A flow by Galadril

Download flow

Flow Details

βš™οΈ Script Activation:

The script is active by default, as indicated by active = true.


⏰ Trigger:

The script runs every hour, as specified by the timer:
timer = { 'every 1 hours' }.


πŸ“ Logging:

Uses the logging level domoticz.LOG_INFO, with entries marked by "AWTRIX3_BATTERY" for easy identification.


πŸš€ Execution:

When triggered, the script performs the following actions:

πŸ” Condition Check:

  • Filters devices with a battery level below 20%.
  • Ignores devices without a battery attribute or those with invalid battery readings.

πŸ”„ Action:

  • Sends notifications for devices with low battery levels:
    • Battery < 20%: Uses a specific icon (ICON_BATTERY_20) and sends a warning.
    • Battery < 10%: Uses a critical icon (ICON_BATTERY_10) and sends a critical warning.
  • Formats the notification as a JSON payload containing the device name and icon.
  • Sends the payload to the "AWTRIX3 - Send Notification" device:
    • βœ… If the AWTRIX3 device is found: Sends the notification.
    • πŸ›‘ If the AWTRIX3 device is not found: Logs an error.

More information:

Domoticz: www.domoticz.com

Domoticz AWTRIX3 Plugin: https://github.com/galadril/Domoticz-AWTRIX3-Plugin

local BATTERY_THRESHOLD_1 = 20 -- First threshold for notification local BATTERY_THRESHOLD_2 = 10 -- Second threshold for critical notification local ICON_BATTERY_20 = 6355 -- Icon for battery level < 20% local ICON_BATTERY_10 = 6354 -- Icon for battery level < 10% return { active = true, on = { timer = { 'every 1 hours' } }, logging = { level = domoticz.LOG_INFO, marker = "AWTRIX3_BATTERY" }, execute = function(domoticz) -- Filter devices with low battery level local lowOnBattery = domoticz.devices().filter(function(device) local level = device.batteryLevel return ( level ~= nil and -- Ensure the device has a battery level attribute level ~= 255 and -- Ignore if no battery measurement is applicable level < BATTERY_THRESHOLD_1 -- Notify if below 20% ) end) -- Send individual notifications for each device with low battery lowOnBattery.forEach( function(lowDevice) local batteryLevel = lowDevice.batteryLevel local notificationIcon = nil -- Determine the appropriate icon based on battery level if batteryLevel < BATTERY_THRESHOLD_2 then notificationIcon = ICON_BATTERY_10 else notificationIcon = ICON_BATTERY_20 end local message = lowDevice.name .. " low" local payload = { text = message, icon = notificationIcon } local payloadJSON = domoticz.utils.toJSON(payload) domoticz.log('Low battery warning for: ' .. message, domoticz.LOG_INFO) domoticz.log("Sending to AWTRIX3: " .. payloadJSON, domoticz.LOG_INFO) -- Send the notification to AWTRIX3 local awtrixDevice = domoticz.devices('AWTRIX3 - Send Notification') if awtrixDevice then awtrixDevice.setDescription(payloadJSON) awtrixDevice.switchOn().afterSec(2) else domoticz.log("AWTRIX3 - Send Notification device not found", domoticz.LOG_ERROR) end end ) end }
-- Flow first published on January 9, 2025.