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

IF/THEN Scenes - what am I getting wrong?


jshannon

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

 

 

Please login or register to see this link.

Link to comment
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 comment
Share on other sites

  • 0
  • Inquirer
  • 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 comment
    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 comment
    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

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 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 comment
    Share on other sites

    • 0

    remove this part:

    Please login or register to see this code.

    Some "cleaner" code:

    Please login or register to see this code.

    Link to comment
    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...