Jump to content
  • 0

IF/THEN Scenes - what am I getting wrong?


Question

I'm a new HC2 user and having some trouble getting scenes to work.  Can someone take a look at the attached image and provide some feedback?  Thanks in advance for your help.

 

It seems like the IF/THEN logic of scenes is completely broken.  Time-based scenes don't run when the "IF" condition is TRUE.  Then, when I manually "RUN" a scene, it runs even if the "IF" condition is FALSE.  What the heck am I doing wrong??

 

 

Scene.tiff

Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

syntax looks fine, im using almost same.

Did you check the checkbox allways run at startup?

Link to post
Share on other sites
  • 0

Thanks, I'm having a little bit more success upon restart of the system, but not 100%.  

 

QUESTION:  When you "RUN" a scene from the scenes tab, is that supposed to bypass the condition of the IF statement?  That seems like weird behavior.  It seems like I should hit "RUN" and only get actions returned if the IF statement is TRUE.

Link to post
Share on other sites
  • 0

as far as i know: the button run, runs the scene

 

example

scene: only on monday 8 am turn light on

 

if you press run on saturday 9 pm, the light goes on

Link to post
Share on other sites
  • 0

Yes, that is normal in Block-scenes. But you can change the code to LUA, where you can remove that part :)

Link to post
Share on other sites
  • 0

So how do I force an "IF" statement in LUA, rather than the default block behavior?

 

MY CODE:

 

--[[
%% autostart
%% properties
2 Location
%% globals
--]]
 
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 string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "16:00")  and  (fibaro:calculateDistance(fibaro:getValue(2, "Location"), "33.73000312155248;-84.3495961278677") <= 200 and fibaro:calculateDistance(fibaro:getValue(2, "PreviousLocation"), "33.73000312155248;-84.3495961278677") > 200) )
)
then
fibaro:call(42, "setArmed", "0");
fibaro:call(32, "setArmed", "0");
fibaro:call(34, "setArmed", "0");
fibaro:call(36, "setArmed", "0");
fibaro:call(38, "setArmed", "0");
fibaro:call(7, "sendDefinedPushNotification", "12");
fibaro:call(2, "sendDefinedEmailNotification", "12");
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  (fibaro:calculateDistance(fibaro:getValue(2, "Location"), "33.73000312155248;-84.3495961278677") <= 200 and fibaro:calculateDistance(fibaro:getValue(2, "PreviousLocation"), "33.73000312155248;-84.3495961278677") > 200) )
or
startSource["type"] == "other"
)
then
fibaro:call(42, "setArmed", "0");
fibaro:call(32, "setArmed", "0");
fibaro:call(34, "setArmed", "0");
fibaro:call(36, "setArmed", "0");
fibaro:call(38, "setArmed", "0");
fibaro:call(7, "sendDefinedPushNotification", "12");
fibaro:call(2, "sendDefinedEmailNotification", "12");
end
 
end

 

Link to post
Share on other sites
  • 0

remove this part:

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  (fibaro:calculateDistance(fibaro:getValue(2, "Location"), "33.73000312155248;-84.3495961278677") <= 200 and fibaro:calculateDistance(fibaro:getValue(2, "PreviousLocation"), "33.73000312155248;-84.3495961278677") > 200) )
or
startSource["type"] == "other"
)
then
fibaro:call(42, "setArmed", "0");
fibaro:call(32, "setArmed", "0");
fibaro:call(34, "setArmed", "0");
fibaro:call(36, "setArmed", "0");
fibaro:call(38, "setArmed", "0");
fibaro:call(7, "sendDefinedPushNotification", "12");
fibaro:call(2, "sendDefinedEmailNotification", "12");
end

Some "cleaner" code:

--[[
%% autostart
%% properties
2 Location
%% globals
--]]
 
local sourceTrigger = fibaro:getSourceTrigger();

function tempFunc()
  local currentDate = os.date("*t");
  local currentTime = os.date("%H:%M");
  local startSource = fibaro:getSourceTrigger();
  if ( currentTime == "16:00" and  (fibaro:calculateDistance(fibaro:getValue(2, "Location"), "33.73000312155248;-84.3495961278677") <= 200 and fibaro:calculateDistance(fibaro:getValue(2, "PreviousLocation"), "33.73000312155248;-84.3495961278677") > 200) )
  then
    fibaro:call(42, "setArmed", "0");
    fibaro:call(32, "setArmed", "0");
    fibaro:call(34, "setArmed", "0");
    fibaro:call(36, "setArmed", "0");
    fibaro:call(38, "setArmed", "0");
    fibaro:call(7, "sendDefinedPushNotification", "12");
    fibaro:call(2, "sendDefinedEmailNotification", "12");
  end
  setTimeout(tempFunc, 60*1000)
end

if (sourceTrigger["type"] == "autostart") then
  tempFunc()
end
Link to post
Share on other sites

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