<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.domoticz.com/index.php?action=history&amp;feed=atom&amp;title=Battery_level_check</id>
	<title>Battery level check - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.domoticz.com/index.php?action=history&amp;feed=atom&amp;title=Battery_level_check"/>
	<link rel="alternate" type="text/html" href="https://wiki.domoticz.com/index.php?title=Battery_level_check&amp;action=history"/>
	<updated>2026-09-18T23:00:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.domoticz.com/index.php?title=Battery_level_check&amp;diff=18889&amp;oldid=prev</id>
		<title>Walter vl: /* Script 1 - DZevents */</title>
		<link rel="alternate" type="text/html" href="https://wiki.domoticz.com/index.php?title=Battery_level_check&amp;diff=18889&amp;oldid=prev"/>
		<updated>2025-05-20T17:14:03Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Script 1 - DZevents&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 17:14, 20 May 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l7&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Script 1 - DZevents==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Script 1 - DZevents==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The forumTopic of this script is here : https://www.domoticz.com/forum/viewtopic.php?f=59&amp;amp;t=18542&amp;amp;p=142962&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The forumTopic of this script is here : &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[https://forum.domoticz.com/viewtopic.php?f=59&amp;amp;t=18542&amp;amp;p=142962 &lt;/ins&gt;https://www.domoticz.com/forum/viewtopic.php?f=59&amp;amp;t=18542&amp;amp;p=142962&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key pkjv172828_mw1-mw_:diff:1.41:old-18888:rev-18889:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Walter vl</name></author>
	</entry>
	<entry>
		<id>https://wiki.domoticz.com/index.php?title=Battery_level_check&amp;diff=18888&amp;oldid=prev</id>
		<title>Walter vl: /* Purpose */</title>
		<link rel="alternate" type="text/html" href="https://wiki.domoticz.com/index.php?title=Battery_level_check&amp;diff=18888&amp;oldid=prev"/>
		<updated>2025-05-20T17:10:46Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Purpose&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 17:10, 20 May 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l2&quot;&gt;Line 2:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 2:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;These scripts are used to check battery level.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;These scripts are used to check battery level.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Be aware that there is also a general [[Application Settings|Application setting for battery Level notifications]] so only use and modify these scripts if you need other functionality than the standard one.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Be aware that there is also a general [[Application Settings&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;#Battery Low Level&lt;/ins&gt;|Application setting for battery Level notifications]] so only use and modify these scripts if you need other functionality than the standard one.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br /&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br /&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key pkjv172828_mw1-mw_:diff:1.41:old-16450:rev-18888:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Walter vl</name></author>
	</entry>
	<entry>
		<id>https://wiki.domoticz.com/index.php?title=Battery_level_check&amp;diff=16450&amp;oldid=prev</id>
		<title>Walter vl at 11:11, 9 September 2021</title>
		<link rel="alternate" type="text/html" href="https://wiki.domoticz.com/index.php?title=Battery_level_check&amp;diff=16450&amp;oldid=prev"/>
		<updated>2021-09-09T11:11:24Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Purpose==&lt;br /&gt;
These scripts are used to check battery level.&lt;br /&gt;
&lt;br /&gt;
Be aware that there is also a general [[Application Settings|Application setting for battery Level notifications]] so only use and modify these scripts if you need other functionality than the standard one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Script 1 - DZevents==&lt;br /&gt;
The forumTopic of this script is here : https://www.domoticz.com/forum/viewtopic.php?f=59&amp;amp;t=18542&amp;amp;p=142962&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This script check all devices that have a device.batterylevel attribute. &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
local BATTERY_THRESHOLD = 10&lt;br /&gt;
return {&lt;br /&gt;
	active = true,&lt;br /&gt;
	on = {&lt;br /&gt;
--	    devices = {&lt;br /&gt;
--		  &amp;#039;testSwitch&amp;#039;,&lt;br /&gt;
--		},&lt;br /&gt;
		timer = {&lt;br /&gt;
			&amp;#039;at 18:00 on fri,sat,mon,wed&amp;#039;,   -- sun,mon,tue,wed,thu,fri,sat&lt;br /&gt;
		}&lt;br /&gt;
	},&lt;br /&gt;
	execute = function(domoticz)&lt;br /&gt;
&lt;br /&gt;
		local message = &amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
		-- first filter on low battery level&lt;br /&gt;
		local lowOnBat = domoticz.devices().filter(function(device)&lt;br /&gt;
&lt;br /&gt;
			local level = device.batteryLevel -- level is 0-100&lt;br /&gt;
			return (level ~= nil and -- not all devices have this attribute&lt;br /&gt;
					level &amp;lt;= BATTERY_THRESHOLD)&lt;br /&gt;
		end)&lt;br /&gt;
&lt;br /&gt;
		-- then loop over the results&lt;br /&gt;
		lowOnBat.forEach(function(lowDevice)&lt;br /&gt;
			message = message .. &amp;#039;&amp;#039; ..&lt;br /&gt;
				lowDevice.name .. &amp;#039; : &amp;#039; .. tostring(lowDevice.batteryLevel) .. &amp;#039;% left\n&amp;#039;&lt;br /&gt;
		end)&lt;br /&gt;
&lt;br /&gt;
        if (message ~= &amp;#039;&amp;#039;) then&lt;br /&gt;
			message = &amp;#039;-- Low battery warning ------\n&amp;#039; .. message&lt;br /&gt;
			domoticz.notify(&amp;#039;Low battery warning&amp;#039;, message, domoticz.PRIORITY_NORMAL)&lt;br /&gt;
--			domoticz.log(&amp;#039;Low battery warning: &amp;#039; .. message, domoticz.LOG_ERROR)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Script 2 - Lua==&lt;br /&gt;
&lt;br /&gt;
===Dependencies - hardware / software / operating system===&lt;br /&gt;
This script will work on Linux systems and needs jq installed.&lt;br /&gt;
You can install jq using the following instructions:&lt;br /&gt;
 wget https://github.com/stedolan/jq/releases/download/jq-1.4/jq-1.4.tar.gz&lt;br /&gt;
 tar -zxvf jq-1.4.tar.gz&lt;br /&gt;
 rm jq-1.4.tar.gz&lt;br /&gt;
 cd jq-1.4&lt;br /&gt;
 ./configure&lt;br /&gt;
 make&lt;br /&gt;
 sudo make install&lt;br /&gt;
Before you can use jq it needs it needs to be compiled. If you never configure or make a installation before.&lt;br /&gt;
You probably won&amp;#039;t have the development tools needed.&lt;br /&gt;
Follow the instructions to install the development tools and continue with the jq installation.&lt;br /&gt;
 sudo apt-get update&lt;br /&gt;
 &lt;br /&gt;
 sudo apt-get install build-essential&lt;br /&gt;
&lt;br /&gt;
====Domoticz Setup - switches, variables, version====&lt;br /&gt;
&lt;br /&gt;
The single user variable DevicesWithBatteries set in Domoticz with the name of each device seperated by a | i.e. stored as &amp;quot;name one|name 2|name 3|name Forty one&amp;quot; with correct case and spacing.&lt;br /&gt;
&lt;br /&gt;
===Installation instructions===&lt;br /&gt;
Copy this script in your &amp;#039;&amp;#039;&amp;#039;domoticz\scripts\lua\&amp;#039;&amp;#039;&amp;#039; folder.&lt;br /&gt;
&lt;br /&gt;
===Script with comments===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
--~/domoticz/scripts/lua/script_time_battery.lua&lt;br /&gt;
commandArray = {}&lt;br /&gt;
&lt;br /&gt;
-- ==============================&lt;br /&gt;
-- Check battery level of devices&lt;br /&gt;
-- ==============================&lt;br /&gt;
 &lt;br /&gt;
--Uservariables&lt;br /&gt;
BatteryLevelSetPoint=99&lt;br /&gt;
EmailTo=&amp;quot;abcde@gmail.com&amp;quot;&lt;br /&gt;
ReportHour=20&lt;br /&gt;
ReportMinute=01&lt;br /&gt;
DomoticzIP=&amp;quot;192.168.5.70&amp;quot;&lt;br /&gt;
DomoticzPort=&amp;quot;8080&amp;quot;&lt;br /&gt;
Message = &amp;#039;Batterijchecker&amp;#039;&lt;br /&gt;
DeviceFileName = &amp;quot;/var/tmp/JsonAllDevData.tmp&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
-- Time to run?&lt;br /&gt;
time = os.date(&amp;quot;*t&amp;quot;)&lt;br /&gt;
if time.hour == ReportHour and time.min == ReportMinute then&lt;br /&gt;
 &lt;br /&gt;
    -- Update the list of device names and ids to be checked later&lt;br /&gt;
    os.execute(&amp;quot;curl &amp;#039;http://&amp;quot; .. DomoticzIP .. &amp;quot;:&amp;quot; .. DomoticzPort .. &amp;quot;/json.htm?type=devices&amp;amp;order=name&amp;#039; 2&amp;gt;/dev/null| /usr/local/bin/jq -r &amp;#039;.result[]|{(.Name): .idx}&amp;#039; &amp;gt;&amp;quot; .. DeviceFileName)&lt;br /&gt;
    BattToReplace = false&lt;br /&gt;
&lt;br /&gt;
    -- Retrieve the battery device names from the user variable - stored as name one|name 2|name 3|name forty one&lt;br /&gt;
    DevicesWithBatteries = uservariables[&amp;quot;DevicesWithBatteries&amp;quot;]&lt;br /&gt;
    DeviceNames = {}&lt;br /&gt;
    for DeviceName in string.gmatch(DevicesWithBatteries, &amp;quot;[^|]+&amp;quot;) do&lt;br /&gt;
       DeviceNames[#DeviceNames + 1] = DeviceName&lt;br /&gt;
    end&lt;br /&gt;
        &lt;br /&gt;
    -- Loop round each of the devices with batteries&lt;br /&gt;
    for i,DeviceName in ipairs(DeviceNames) do&lt;br /&gt;
&lt;br /&gt;
       --Determine device id&lt;br /&gt;
       local handle = io.popen(&amp;quot;/usr/local/bin/jq -r &amp;#039;.\&amp;quot;&amp;quot; .. DeviceName .. &amp;quot;\&amp;quot; | values&amp;#039; &amp;quot; .. DeviceFileName)&lt;br /&gt;
       local DeviceIDToCheckBatteryLevel = handle:read(&amp;quot;*n&amp;quot;)&lt;br /&gt;
       handle:close()&lt;br /&gt;
 &lt;br /&gt;
       --Determine battery level&lt;br /&gt;
       local handle = io.popen(&amp;quot;curl &amp;#039;http://&amp;quot; .. DomoticzIP .. &amp;quot;:&amp;quot; .. DomoticzPort .. &amp;quot;/json.htm?type=devices&amp;amp;rid=&amp;quot; .. DeviceIDToCheckBatteryLevel .. &amp;quot;&amp;#039; 2&amp;gt;/dev/null | /usr/local/bin/jq -r .result[].BatteryLevel&amp;quot;)&lt;br /&gt;
       local BattLevel = string.gsub(handle:read(&amp;quot;*a&amp;quot;), &amp;quot;\n&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
       handle:close()&lt;br /&gt;
       print(DeviceName .. &amp;#039; batterylevel is &amp;#039; .. BattLevel .. &amp;quot;%&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
       -- Check batterylevel against setpoint&lt;br /&gt;
       if tonumber(BattLevel) &amp;lt; BatteryLevelSetPoint then&lt;br /&gt;
          BattToReplace = true&lt;br /&gt;
          print(&amp;quot;!!!&amp;quot; .. DeviceName .. &amp;quot; batterylevel below &amp;quot; .. BatteryLevelSetPoint .. &amp;quot;%, current &amp;quot; .. BattLevel .. &amp;quot;%&amp;quot;)&lt;br /&gt;
          Message = Message .. &amp;#039;\n *** &amp;#039; .. DeviceName .. &amp;#039; battery level is &amp;#039; .. BattLevel .. &amp;#039;%&amp;#039;&lt;br /&gt;
       end&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    -- Only send an email if at least one battery fails the test&lt;br /&gt;
    if(BattToReplace) then&lt;br /&gt;
       commandArray[&amp;#039;SendEmail&amp;#039;]=&amp;#039;Domoticz Battery Levels#&amp;#039;.. Message .. &amp;#039;#&amp;#039; .. EmailTo&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
--LUA default&lt;br /&gt;
return commandArray&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Script 3 - Alternate LUA script==&lt;br /&gt;
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.  &lt;br /&gt;
&lt;br /&gt;
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&amp;#039;t need to write any temporary json files to disk.&lt;br /&gt;
&lt;br /&gt;
===Instructions===&lt;br /&gt;
Under Setup..More Options..Events add a new LUA script named battery_check to execute on &amp;#039;time&amp;#039; and overwrite the sample code with the below script.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-- =========================================&lt;br /&gt;
-- Check battery level for all used devices&lt;br /&gt;
-- =========================================&lt;br /&gt;
&lt;br /&gt;
-- User Configuration&lt;br /&gt;
BatteryThreshold = 40&lt;br /&gt;
WeeklySummary = true&lt;br /&gt;
SummaryDay = 1 -- Sunday is 1&lt;br /&gt;
EmailTo = &amp;quot;email@example.com&amp;quot;&lt;br /&gt;
ReportHour = 9&lt;br /&gt;
ReportMinute = 01&lt;br /&gt;
Domoticz = &amp;quot;localhost&amp;quot;&lt;br /&gt;
DomoticzPort = &amp;quot;8080&amp;quot;&lt;br /&gt;
Message = &amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
json = (loadfile &amp;quot;/home/pi/domoticz/scripts/lua/JSON.lua&amp;quot;)() -- linux&lt;br /&gt;
--json = (loadfile &amp;quot;C:\\Domoticz\\scripts\\lua\\json.lua&amp;quot;)() -- windows&lt;br /&gt;
commandArray = {}&lt;br /&gt;
time = os.date(&amp;quot;*t&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Weekly Device Battery Summary&lt;br /&gt;
if WeeklySummary == true and time.wday == SummaryDay and time.hour == ReportHour and time.min == ReportMinute then&lt;br /&gt;
 &lt;br /&gt;
    -- Get a list of all devices&lt;br /&gt;
    handle = io.popen(&amp;quot;curl &amp;#039;http://&amp;quot; .. Domoticz .. &amp;quot;:&amp;quot; .. DomoticzPort .. &amp;quot;/json.htm?type=devices&amp;amp;order=name&amp;#039;&amp;quot;)&lt;br /&gt;
    devicesJson = handle:read(&amp;#039;*all&amp;#039;)&lt;br /&gt;
    handle:close()&lt;br /&gt;
    devices = json:decode(devicesJson)&lt;br /&gt;
    BattToReplace = false&lt;br /&gt;
    for i,device in ipairs(devices.result) do&lt;br /&gt;
        if device.BatteryLevel &amp;lt; 100 and device.Used == 1 then&lt;br /&gt;
            Message = Message .. device.Name .. &amp;#039; battery level is &amp;#039; .. device.BatteryLevel .. &amp;#039;%&amp;lt;br&amp;gt;&amp;#039;&lt;br /&gt;
            print(device.Name .. &amp;#039; battery level is &amp;#039; .. device.BatteryLevel .. &amp;#039;%&amp;#039;)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    commandArray[&amp;#039;SendEmail&amp;#039;]=&amp;#039;Domoticz Battery Levels#&amp;#039;.. Message .. &amp;#039;#&amp;#039; .. EmailTo&lt;br /&gt;
&lt;br /&gt;
-- Daily Low Battery Report&lt;br /&gt;
elseif time.hour == ReportHour and time.min == ReportMinute then&lt;br /&gt;
 &lt;br /&gt;
    -- Get a list of all devices&lt;br /&gt;
    handle = io.popen(&amp;quot;curl &amp;#039;http://&amp;quot; .. Domoticz .. &amp;quot;:&amp;quot; .. DomoticzPort .. &amp;quot;/json.htm?type=devices&amp;amp;order=name&amp;#039;&amp;quot;)&lt;br /&gt;
    devicesJson = handle:read(&amp;#039;*all&amp;#039;)&lt;br /&gt;
    handle:close()&lt;br /&gt;
    devices = json:decode(devicesJson)&lt;br /&gt;
    BattToReplace = false&lt;br /&gt;
    for i,device in ipairs(devices.result) do&lt;br /&gt;
        if device.BatteryLevel &amp;lt; BatteryThreshold and device.Used == 1 then&lt;br /&gt;
            Message = Message .. device.Name .. &amp;#039; battery level is &amp;#039; .. device.BatteryLevel .. &amp;#039;%&amp;lt;br&amp;gt;&amp;#039;&lt;br /&gt;
            print(device.Name .. &amp;#039; battery level is &amp;#039; .. device.BatteryLevel .. &amp;#039;%&amp;#039;)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    commandArray[&amp;#039;SendEmail&amp;#039;]=&amp;#039;Domoticz Battery Levels#&amp;#039;.. Message .. &amp;#039;#&amp;#039; .. EmailTo&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return commandArray&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Script 4 - Alternative script using PHP, Pushover and CRONTAB==&lt;br /&gt;
For people that have already PHP installed and want to use Pushover for alerts there is an alternative script that can be used using PHP instead of LUA.&lt;br /&gt;
Create the following &amp;#039;&amp;#039;&amp;#039;batt.php&amp;#039;&amp;#039;&amp;#039; file in /home/pi/domoticz/scripts (fill in your Domoticz IP and port number for your_ip and your_port )&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
nano /home/pi/domoticz/scripts/batt.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
contents:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Test if Battery level from sensors is still within range.&lt;br /&gt;
// If below, send pushover alert&lt;br /&gt;
// Called every 4 hours from crontab&lt;br /&gt;
&lt;br /&gt;
$json = json_decode(file_get_contents(&amp;#039;http://your_ip:your_port/json.htm?type=devices&amp;amp;order=name&amp;#039;));&lt;br /&gt;
$threshold = 65;&lt;br /&gt;
$hst = &amp;quot;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
foreach  ($json-&amp;gt;result as $r) {&lt;br /&gt;
        if ($r-&amp;gt;BatteryLevel &amp;gt; 0 &amp;amp;&amp;amp; $r-&amp;gt;BatteryLevel&amp;lt;$threshold) {&lt;br /&gt;
                $hst = $hst . $r-&amp;gt;Name.&amp;quot;: &amp;quot;.$r-&amp;gt;BatteryLevel.&amp;quot;%\n&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if ($hst) {&lt;br /&gt;
        $hst = &amp;quot;Batt Low:\n&amp;quot;.$hst;&lt;br /&gt;
        echo $hst;&lt;br /&gt;
        $url = &amp;quot;https://api.pushover.net/1/messages.json&amp;quot;;&lt;br /&gt;
        $data = array(&lt;br /&gt;
            &amp;quot;token&amp;quot; =&amp;gt; &amp;quot;[ your pushover application token ]&amp;quot;,&lt;br /&gt;
            &amp;quot;user&amp;quot; =&amp;gt; &amp;quot;[ your pushover user token ]&amp;quot;,&lt;br /&gt;
            &amp;quot;message&amp;quot; =&amp;gt; $hst,&lt;br /&gt;
        );&lt;br /&gt;
        $options = array(&lt;br /&gt;
                &amp;#039;http&amp;#039; =&amp;gt; array(&lt;br /&gt;
                        &amp;#039;header&amp;#039;  =&amp;gt; &amp;quot;Content-type: application/x-www-form-urlencoded\r\n&amp;quot;,&lt;br /&gt;
                        &amp;#039;method&amp;#039;  =&amp;gt; &amp;#039;POST&amp;#039;,&lt;br /&gt;
                        &amp;#039;content&amp;#039; =&amp;gt; http_build_query($data),&lt;br /&gt;
                )&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        $context  = stream_context_create($options);&lt;br /&gt;
        $result = file_get_contents($url, false, $context);&lt;br /&gt;
        var_dump($result);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
We do not use a varable called DevicesWithBatteries as with the LUA script. We simply loop through all devices and select the devices that have a battery level &amp;gt;0. Devices without a battery typically show a value of 0 or 255.&lt;br /&gt;
&lt;br /&gt;
We then create a crontab file with root priviledges in /etc/cron.d&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
sudo nano /etc/cron.d/domoticzbatt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
contents:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# Battery check run ever 6 hours at a few minutes past the hour&lt;br /&gt;
2 0,6,12,18     * * *   root    php /home/pi/domoticz/scripts/batt.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Lua]]&lt;/div&gt;</summary>
		<author><name>Walter vl</name></author>
	</entry>
</feed>