Battery Notifications
Moderator: leecollings
-
- Posts: 19
- Joined: Friday 31 July 2015 0:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Contact:
Battery Notifications
Added a new script option for getting notifications for low battery status of devices.
https://www.domoticz.com/wiki/Battery_level_check
This script will execute once a day at the time that you specify. It will check all your used devices and send an email with a list of all devices below the battery threshold. Optionally you can also receive a weekly summary of all your battery devices and their current battery level regardless of the threshold.
This script will run on Linux or Windows and does not require an external json parsing library. It uses the json library provided with Domoticz. It also doesn't need to write any temporary json files to disk.
https://www.domoticz.com/wiki/Battery_level_check
This script will execute once a day at the time that you specify. It will check all your used devices and send an email with a list of all devices below the battery threshold. Optionally you can also receive a weekly summary of all your battery devices and their current battery level regardless of the threshold.
This script will run on Linux or Windows and does not require an external json parsing library. It uses the json library provided with Domoticz. It also doesn't need to write any temporary json files to disk.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Battery Notifications
@getSurreal,
I am using the dzVent LUA script supplied as an example of the ease of use of dzVents to check the battery status of all relevant devices. Would that be something to add to the wiki ?
I am using the dzVent LUA script supplied as an example of the ease of use of dzVents to check the battery status of all relevant devices. Would that be something to add to the wiki ?
Code: Select all
local BATTERY_THRESHOLD = 10
return {
active = true,
on = {
['timer'] = 'every hour'
},
execute = function(domoticz)
local message
-- first filter on low battery level
local lowOnBat = domoticz.devices.filter(function(device)
local level = device.batteryLevel
return (level ~= nil and -- not all devices have this attribute
level ~= 255 and -- probably means something like 'not applicable'
level <= BATTERY_THRESHOLD)
end)
-- then loop over the results
lowOnBat.forEach(function(lowDevice)
message = message .. 'Device ' ..
lowDevice.name .. ' is low on batteries (' .. lowDevice.batteryLevel .. '), '
end)
if (message) then
domoticz.notify('Low battery warning', message, domoticz.PRIORITY_NORMAL)
domoticz.log('Low battery warning: ' .. message, domoticz.LOG_ERROR)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 19
- Joined: Friday 31 July 2015 0:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Contact:
Re: Battery Notifications
Posting it there could help others in the future. I don't know if it needs to be run differently, but right now it doesn't work for me. I get the following error.
If it works, it could have saved me a lot of time vs rewriting the other example that's on the wiki.
Error: EventSystem: Lua script test did not return a commandArray
If it works, it could have saved me a lot of time vs rewriting the other example that's on the wiki.
-
- Posts: 19
- Joined: Friday 31 July 2015 0:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Contact:
Re: Battery Notifications
I didn't know what DZvents was at first. In this case I don't think that script should go in the same place on the wiki and just kept with DZvents.
I do need to look more into DZvents though. Looks nicer.
I do need to look more into DZvents though. Looks nicer.
-
- Posts: 21
- Joined: Sunday 05 February 2017 12:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Model 3
- Contact:
Re: Battery Notifications
I use 'Alternate LUA script' but get this message.
To require password, how insert this.
Error: Event System: In script_time_battery: /home/pi/domoticz/scripts/lua/JSON.lua:660: html passed two JSON: Decode ():
401 UNAUTHORIZED
Some suggestions
To require password, how insert this.
Error: Event System: In script_time_battery: /home/pi/domoticz/scripts/lua/JSON.lua:660: html passed two JSON: Decode ():
401 UNAUTHORIZED
Some suggestions
Translated with google
-
- Posts: 19
- Joined: Friday 31 July 2015 0:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Contact:
Re: Battery Notifications
Not sure how to pass username and password through the script and not typically good practice to add credentials into a script. I suggest adding an exception for your domoticz server to be able to connect to itself without a password. This is in the domoticz settings system tab.
-
- Posts: 1602
- Joined: Friday 18 October 2013 23:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Arnhem/Nijmegen Nederland
- Contact:
Re: Battery Notifications
Is this working for all sensors? Zwave include?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
-
- Posts: 19
- Joined: Sunday 29 November 2015 9:45
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Battery Notifications
The daily low battery report sends an empty e-mail every day (because all battery levels are above the threshold). Is there a way to prevent the e-mail from sending when all battery levels are above the threshold?
-
- Posts: 19
- Joined: Sunday 29 November 2015 9:45
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Battery Notifications
Think I fixed it by checking if the Message variable contains any data:L2v2P wrote:The daily low battery report sends an empty e-mail every day (because all battery levels are above the threshold). Is there a way to prevent the e-mail from sending when all battery levels are above the threshold?
Code: Select all
if Message ~= '' then
commandArray['SendEmail']='Domoticz Battery Levels#'.. Message .. '#' .. EmailTo
end
-
- Posts: 36
- Joined: Friday 26 January 2018 9:18
- Target OS: Windows
- Domoticz version: BETA
- Location: Brussels
- Contact:
Re: Battery Notifications
Hi,getSurreal wrote: ↑Friday 03 March 2017 21:02 This script will run on Linux or Windows and does not require an external json parsing library. It uses the json library provided with Domoticz. It also doesn't need to write any temporary json files to disk.
I'm running this script under windows but I get an error :
EventSystem: in Battery_check: [string "-- ========================================= ..."]:49: attempt to index global 'devices' (a nil value)
-
- Posts: 36
- Joined: Friday 26 January 2018 9:18
- Target OS: Windows
- Domoticz version: BETA
- Location: Brussels
- Contact:
Re: Battery Notifications
I found the problem, it was a bad copy of quotes in the io.popen command but now, i get this error:
Error: EventSystem: in Battery_check: [string "-- ========================================= ..."]:49: attempt to index global 'devices' (a nil value)
That's at the line :
for i,device in ipairs(devices.result) do ....
This time, I don't find the issue. 
Error: EventSystem: in Battery_check: [string "-- ========================================= ..."]:49: attempt to index global 'devices' (a nil value)
That's at the line :
for i,device in ipairs(devices.result) do ....
Code: Select all
handle = io.popen("curl 'http://" .. Domoticz .. ":" .. DomoticzPort .. "/json.htm?type=devices&order=name'")
devicesJson = handle:read('*all')
handle:close()
devices = json:decode(devicesJson)
BattToReplace = false
for i,device in ipairs(devices.result) do
if device.BatteryLevel < BatteryThreshold and device.Used == 1 then
Message = Message .. device.Name .. ' battery level is ' .. device.BatteryLevel .. '%<br>'
print(device.Name .. ' battery level is ' .. device.BatteryLevel .. '%')
end
end

-
- Posts: 36
- Joined: Friday 26 January 2018 9:18
- Target OS: Windows
- Domoticz version: BETA
- Location: Brussels
- Contact:
Re: Battery Notifications
I just found that the option to a send message when battery low level is low is already implemented in Domoticz.
Just go to settings/Other tab and change the Battery low level value.
Definitively, great product ..

Just go to settings/Other tab and change the Battery low level value.
Definitively, great product ..

Who is online
Users browsing this forum: No registered users and 1 guest