Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Reduce Ztraffic - fibaro_call 1.0

   (0 reviews)

About This File

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:

  1. fibaro_call ( devID, "trunOn" ) or  fibaro_call ( devID, "turnOff" ) -  verify device status and send "turnOn" if neccessary.
  2. 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

 Share



User Feedback

Recommended Comments

There are no comments to display.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...