Version 1.0
44 downloads
First of all, this is not scene or script. Just a function to use in scripts to avoid unnecessary Zwave traffic.
In many cases we send commands to devices without verifying the devices status, this function verifies device current status before sending command and in case the status of the device is not as required, command send.
This function supports "turnOn" and "turnOff" commands for switches and dimmers.
How to use?
Copy this function to your script and change all fibaro:call(...) to fibaro_call(...). Just replace the colon " : " by underscore " _ "
Function always returns Boolean variable true or false.
Two options to use the function:
fibaro_call ( devID, "trunOn" ) or fibaro_call ( devID, "turnOff" ) - verify device status and send "turnOn" if neccessary.
fibaro_call ( devID, "?turnOn" ) or fibaro_call ( devID, "?turnOff" ) - checks device status only. Returns true or false according to status. No command sent.
For example: Original scene which includes few scenarios of sending turnOff/turnOn .
--[[
%% properties
823 value
792 value
--]]
local devID = fibaro:getSourceTrigger()["deviceID"]
if devID == 823 then -- no status verification at all
fibaro:call(540,"turnOff")
end
if devID == 792 then -- including verification
if tonumber(fibaro:getValue(540,"value"))==0 then
fibaro:call(540,"turnOn")
end
end
if tonumber(fibaro:getValue(540,"value"))==1 then -- checkin device status
fibaro:setGlobal("test","lightOn")
else
fibaro:setGlobal("test","lightOff")
end
Now we add the function
--[[
%% properties
823 value
792 value
--]]
function fibaro_call(devId,param)
local fStatus,act=true,{["turnOn"]=1,["turnOff"]=0,["?turnOn"]=1,["?turnOff"]=0}
if not act[param] then fibaro:debug("fibaro_call.lua:\'<font color=firebrick><font size=2> "..param.." </font></font>\' not supported."); return false end
if math.min(1,tonumber(fibaro:getValue(devId,"value"))) ~= act[param] then fStatus=false end
if param:find("?") then return fStatus end
if not fStatus then fibaro:call(devId,param);fStatus=true end
return fStatus
end
local devID = fibaro:getSourceTrigger()["deviceID"]
if devID == 823 then --verification done by fibaro_call()
fibaro_call(540,"turnOff")
end
if devID == 792 then -- no need extra lines for verification
fibaro_call(540,"turnOn")
end
if fibaro_call(540,"?turnOn") then -- checking device status by fibaro_call().
fibaro:setGlobal("test","lightOn")
else
fibaro:setGlobal("test","lightOff")
end
That's all.
Please use this function as a template and change it according to your needs.
In order to observe how much your Zwave traffic is loaded by repeated commands, please download Zwave monitor version 3.0