Easy LUA scripts part 1: battery check
From time to time we will present you some short, but useful LUA scripts within these new series.
Here you get to know more.
In the first episode of our new series, we want to present a short script to you, with it you will be able to check all battery driven devices in regard of their status. The script will show you the battery status and if it is necessary to change the batteries or not. The variety of status will be shown in different colors. These colors are green (battery is in best order) and red (battery runs lower than 25%). In the following picture you can see this in detail.
The LUA script
local minBatteryLevel = 25
local maxID = 1000
Debug = function ( color, message )
fibaro:debug(string.format('<%s style="color:%s;">%s', "span", color, message, "span"))
for id = 1, maxID do
local batteryLevel = fibaro:get(id, 'batteryLevel')
if batteryLevel ~= nil
local name = fibaro:getName(id)
local room = fibaro:getRoomNameByDeviceID(id)
if not(room == "unassigned") then
local deviceType = fibaro:getType(id)
if (deviceType == 'com.fibaro.FGFS101' or deviceType == 'com.fibaro.remoteSwitch' or deviceType == 'com.fibaro.doorLock' or deviceType == 'com.fibaro.FGMS001' or deviceType == 'com.fibaro.windowSensor' or deviceType == 'com.fibaro.doorSensor' or deviceType == 'com.fibaro.binarySwitch' or deviceType == 'com.fibaro.FGSS001') then
if tonumber(batteryLevel) <= minBatteryLevel then
Debug( 'red', "ACHTUNG! " ..name.." ("..room..")/Batterie: "..batteryLevel.." %")
Debug( 'green', name.." ("..room..")/Batterie: "..batteryLevel.." %")
The LUA script checks all devices, which are implemented in your FIBARO HomeCenter2 and is assigned to a room, in a loop and recognizes, if a device is battery driven or stationary. To prevent for example the LUX and temperature values of a MotionSensor will be displayed also, the script inquires which kind of device is present.
Following kinds of devices are supported at the moment:
- fibaro.remoteSwitch (z.B. Wall-C)
- fibaro.doorLock (z.B. RFID-Sensor, danalock)
- fibaro.FGMS001 (Motion Sensor)
- fibaro.windowSensor (door sensor)
- fibaro.doorSensor (door sensor)
- fibaro.binarySwitch (e.g. battery driven sirene)
- fibaro.FGSS001 (smoke sensor v1 & v2)
- fibaro.FGFS101 (flood sensor)
While testing you may recognize some more kinds of devices, which are not covered by the list above, if this happens, please take a look in the API for the device type. This apparent via the URL http://IP-HC2/api/devices?=ID_des_devices . There you search for the ID, which does not appear in the script. Please copy the tab „type“ in the following display.
lua battery check new typ
We would be pleased, if you can provide us with the „traced“ types of devices in the comment section, so we will be able to update this script now and then.
Thank you for your participation and have fun with this script.