€424.38
(tax excl.)
€679.00
LUA Script: Battery check - Fibaro Home Center 2
In this short but useful manual we will show you how to check the battery status in the interface of the Fibaro Home Center 2 control unit using a simple LUA script. You can create the script in a simple way in the Fibaro interface after clicking the section Scenes -> Add scene -> Add scene in LUA. Then insert the below-mentioned script into the advanced section and name the scene for example Battery status. Start the scene and then you can see the response to the running scene in the debug window, it means the status of the batteries.
Example of a script:
--[[
--[[
%% properties
%% globals
--]]
local minBatteryLevel = 25
local maxID = 1000
Debug = function ( color, message )
fibaro:debug(string.format('<%s style="color:%s;">%s', "span", color, message, "span"))
end
for id = 1, maxID do
local batteryLevel = fibaro:get(id, 'batteryLevel')
if batteryLevel ~= nil
then
local name = fibaro:getName(id)
local room = fibaro:getRoomNameByDeviceID(id)
if not(room == "unassigned") then
local deviceType = fibaro:getType(id)
if(deviceType == 'com.fibaro.FGMS001v2' or deviceType == 'com.fibaro.humiditySensor'
or 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.FGSS001' or deviceType == 'com.fibaro.binarySwitch') then
if tonumber(batteryLevel) <= minBatteryLevel then
Debug( 'red', "POZOR! " ..name.." ("..room..")/Batéria: "..batteryLevel.." %")
else
Debug( 'green', name.." ("..room..")/Batéria: "..batteryLevel.." %")
end
end
end
end
end
The following types of devices are supported:
- fibaro.humiditySensor (humidity sensors)
- fibaro.remoteSwitch (z.B. Wall-C)
- fibaro.doorLock (z.B. RFID-Sensor, danalock)
- fibaro.FGMS001 (movement sensor v1 and v2)
- fibaro.windowSensor (window sensors)
- fibaro.doorSensor (door sensors)
- fibaro.binarySwitch (e.g. battery siren)
- fibaro.FGSS001 (smoke sensor v1 and v2)
- fibaro.FGFS101 (flood sensor)
Note: If you miss any devices contact us on info@smarterhome.sk and we will update the LUA script.
Ja* 16.07.2018
If your devices are named logically, you could just get the name instead of checking the device type using:modulename = fibaro:getName(id) ;
fibaro:debug("deviceid "..id.." named "..modulename.." - battery level is at "..batteryLevel.."%");