Skip to content

Instantly share code, notes, and snippets.

@ryanmaxwell
Last active April 30, 2019 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmaxwell/2399942ff637b608d4798c1e01af7f25 to your computer and use it in GitHub Desktop.
Save ryanmaxwell/2399942ff637b608d4798c1e01af7f25 to your computer and use it in GitHub Desktop.
Fibaro HC2 Scene for dimmer S2 switch button to trigger open/close/pause of multiple blinds in a room
--[[
%% properties
378 sceneActivation
%% weather
%% events
%% globals
--]]
function anyBlindIsClosed(blindIDs)
for index, blindID in ipairs(blindIDs) do
if tonumber(fibaro:getValue(blindID, "value")) == 0 then
return true
end
end
return false
end
function allBlindsAreClosed(blindIDs)
for index, blindID in ipairs(blindIDs) do
if tonumber(fibaro:getValue(blindID, "value")) ~= 0 then
return false
end
end
return true
end
function allBlindsAreOpen(blindIDs)
for index, blindID in ipairs(blindIDs) do
if tonumber(fibaro:getValue(blindID, "value")) < 99 then
return false
end
end
return true
end
function callOnBlinds(blindIDs, command)
for index, blindID in ipairs(blindIDs) do
fibaro:call(blindID, command)
end
end
local startSource = fibaro:getSourceTrigger();
local blindIDs = {318, 279, 281};
local switchID = 378;
local stateName = "MasterBlindState";
if (
( tonumber(fibaro:getValue(switchID, "sceneActivation")) == 26 )
or
startSource["type"] == "other"
)
then
local blindState = fibaro:getGlobal(stateName);
fibaro:debug("blind state: " .. blindState);
for index, blindID in ipairs(blindIDs) do
local blindValue = tonumber(fibaro:getValue(blindID, "value"));
fibaro:debug("blind value: " .. blindValue);
end
if blindState == "opening" then
fibaro:debug("paused opening");
fibaro:setGlobal(stateName, 'paused_opening');
callOnBlinds(blindIDs, 'stop');
elseif blindState == "closing" then
fibaro:debug("paused closing");
fibaro:setGlobal(stateName, 'paused_closing');
callOnBlinds(blindIDs, 'stop');
else
if blindState == "paused_closing" or anyBlindIsClosed(blindIDs) then
fibaro:debug("opening");
fibaro:setGlobal(stateName, 'opening');
callOnBlinds(blindIDs, 'open');
while fibaro:getGlobal(stateName) == 'opening' and allBlindsAreOpen(blindIDs) == false do
fibaro:debug("opening all blinds...");
fibaro:sleep(1000);
end
if allBlindsAreOpen(blindIDs) then
fibaro:debug("now opened all blinds");
fibaro:setGlobal(stateName, 'opened');
end
else
-- paused opening or open
fibaro:debug("closing all blinds");
fibaro:setGlobal(stateName, 'closing');
callOnBlinds(blindIDs, 'close');
while fibaro:getGlobal(stateName) == 'closing' and allBlindsAreClosed(blindIDs) == false do
fibaro:debug("closing all blinds...");
fibaro:sleep(1000);
end
if allBlindsAreClosed(blindIDs) then
fibaro:debug("now closed all blinds");
fibaro:setGlobal(stateName, 'closed');
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment