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


  • 0

ok - where am I going wrong?


Question

Posted

Can you help me understand what I'm doing wrong with my Fibaro Scene? I want to define a scene that triggers the light in a room when someone enters. There are conditions, which I'm using the AND clause for in my HC2 Scenes. Right now the Scene is built, but everytime I walk into the room, the light turns on! It's driving me nuts because I don't understand what I'm doing wrong. I want to build the following:

 

Trigger is 20mins before Sunset, on any day of the week.

  AND the House is Occupied (Global Variable set from the Alarm System being disarmed)

  AND This Scene has not been triggered before (another Global Variable)

 

If these trigger conditions are met - THEN

  TURN ON Room Light

  AND Set Global Variable for this Scene to having been triggered.

 

The idea is that I might already be in a room, with the lights off watching a movie. I don't want the lights to come back on every time I switch them off because this Scene gets triggered again. So I have another Scene that fires at 6am and resets the Global Variable "xxxAutoLightRun" back to "No".

 

Below is the LUA Code, can you help me understand what I'm doing wrong?

 

--[[
%% autostart
%% properties
498 value
%% weather
%% events
%% globals
HouseOccupied
OfficeAutoLightRun
--]]
 
local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc()
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and os.date("%H:%M", os.time()+20*60) == fibaro:getValue(1, "sunsetHour")) and tonumber(fibaro:getValue(498, "value")) > 0 )
and
( fibaro:getGlobalValue("HouseOccupied") == "Yes" and fibaro:getGlobalValue("OfficeAutoLightRun") == "No" )
)
then
    fibaro:call(228, "turnOn");
    fibaro:setGlobal("OfficeAutoLightRun", "Yes");
end
 
setTimeout(tempFunc, 60*1000)
end
if (sourceTrigger["type"] == "autostart") then
tempFunc()
else
 
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
( (currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and tonumber(fibaro:getValue(498, "value")) > 0 )
and
( fibaro:getGlobalValue("HouseOccupied") == "Yes" and fibaro:getGlobalValue("OfficeAutoLightRun") == "No" )
or
startSource["type"] == "other"
)
then
    fibaro:call(228, "turnOn");
    fibaro:setGlobal("OfficeAutoLightRun", "Yes");
end
 
end

 

 

The visual blocks for this LUA are below:

 

Please login or register to see this image.

/monthly_2019_06/image.png.4d6765e688e5370171e7ccc360ebf6ad.png" alt="image.png.4d6765e688e5370171e7ccc360ebf6ad.png" />

 

1 answer to this question

Recommended Posts

  • 0
Posted (edited)

Hei  

Please login or register to see this link.

@Chrisjcbt ,

here is a very basic setup with a few colors to show progress.

I assume you have another scene to reset OfficeAutoLightRun to no ?

 

 

 

--[[
%% autostart
%% properties
769 value  
%% events
%% globals
HouseOccupied
OfficeAutoLightRun
--]]


Debug = function ( color, message )
  fibaro:debug(string.format('<%s style="color:%s;">%s', "span", color, message, "span"))
end


local startSource = fibaro:getSourceTrigger();
local currentDate = os.date("*t");

if (
 ( tonumber(fibaro:getValue(769, "value")) > 0  ----youe sensor id / set in headers also
      and ( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and os.date("%H:%M", os.time()+20*60) == fibaro:getValue(1, "sunsetHour")) )
      and  fibaro:getGlobalValue("HouseOccupied") == "Yes"  
      and  fibaro:getGlobalValue("OfficeAutoLightRun") == "No" )

)
then
    fibaro:call(162, "turnOn");----your light id
    fibaro:setGlobal("OfficeAutoLightRun", "Yes");
    Debug('green', "HouseOccupied =Yes")
    Debug('green', "OfficeAutoLightRun =Yes")
else

Debug('white', os.date('%c'))
Debug('red', "Waiting for Sunset + offset :OfficeAutoLightRun =No")
  end

Edited by MARCUSP.I.L

Join the conversation

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

Guest
Answer this question...

×   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...