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

LUA if always starts even if condition is not true


Question

Posted

Hey Guys,

 

I can't seem to figure this out. I really need some help. I've tried Fibaro support but that didn't help unfortunately.

 

So the idea is that this script runs only when Time=Night. I fire the script as part of scene. Problem is it always fire without checking the variable when the trigger is another scene. When i trigger it manually it works like i want it to... What am i missing?

 

local Time
Time = fibaro:getGlobalValue("Time")

if (Time == 'Night') then

    fibaro:call(134, "turnOn");
    fibaro:call(120, "pressButton", "1");
    fibaro:call(137, "pressButton", "1");
   fibaro:debug('I turned the lights on because its ' .. Time)

else
   fibaro:debug('It didnt turn the lights on because its ' .. Time)

end

12 answers to this question

Recommended Posts

  • 0
Posted

what method you use to call this scene from another one?

if the global variable is change one line before?

 

please add the scene with first lines --[[ ]]-- used for definition of triggers

  • 0
  • Inquirer
  • Posted
    34 minutes ago, drboss said:

    what method you use to call this scene from another one?

    if the global variable is change one line before?

     

    please add the scene with first lines --[[ ]]-- used for definition of triggers

    I don’t have any scene triggers. It triggers ‘manually’ through a block scene starting this scene. So for example this scene is used when disarming the alarm. The idea is that it only turns on these lights when the alarm is disabled when Time = Night.

    but this same script is also so used to trigger the lights when at home and going downstairs when Time = Night. But it’s then triggered by a motion sensor. So logically it works like a ‘function’ sort off used in multiple scenario’s in different scenes.

    the Time variable is switched automatically.

    the trouble is that it looks like if you start it through another scene the if statement simply doesn’t anymore. That can not be the case in LUA right?

    • 0
    Posted

    I tested in my system and all wok fine

    Please login or register to see this code.

    I call this from block scene like this:

    Please login or register to see this image.

    /monthly_2020_02/image.png.e5fcc854a3a4cb2b7e545dd3328df35e.png" />

    and  if the CWU_comfort = "0" they give true /0, if CWU_comfort = '1' they give false/1

    all work fine

    • 0
  • Inquirer
  • Posted

    I tried again. Same result.

    When i test the scene manually all works fine.

    When i fire the scene from another scene like you did. It always passes the condition and turns the lights on even if the variable is Day.

    I will switch to HC3 and see how it goes. This thing is driving me crazy sometimes...

     

    Thanks for the help! Lets see if the HC3 solves these problems.

    • 0
    Posted (edited)

    Your problem defiantly in Time variable value. Looks like it doesn't equal to "Night".

    Since at the end of the scene you have debug info, what Time value shows when scene ran?

    fibaro:debug('I turned the lights on because its ' .. Time)

    else
       fibaro:debug('It didnt turn the lights on because its ' .. Time)

     

    2 minutes ago, pvo said:

    Thanks for the help! Lets see if the HC3 solves these problems.

    This is not a controller issue.

    Edited by cag014
    • 0
  • Inquirer
  • Posted

    Currently the right debug is shown based on the variable.

    So when variable = Day it looks like it skips the turn on lights code.

    Everything works fine when i start and debug manually. The problem lies when this scene is started as part of another scene. Then it always runs the lights code instead of checking the variable and running accordingly.

    • 0
    Posted (edited)

    So every time you run the scene from another scene it shows like:

    DEBUG: I turned the lights on because its Night

    Could you post a screen shot of debug info?

    Edited by cag014
    • 0
    Posted (edited)
    32 minutes ago, pvo said:

    So when variable = Day it looks like it skips the turn on lights code.

    It should skip turn on lights code

    Your code turns lights on only when Time=="Nignt", isn't?

    Please login or register to see this code.

     

    Edited by cag014
    • 0
  • Inquirer
  • Posted

    Yes that's correct. But when started from another scene it also turns on when Time='Day' and that should not be the case.

    Please login or register to see this attachment.

    • 0
    Posted (edited)

    Are you sure... may be the problem is the timing when you change the Time value from Night to Day. Is it done in same block scene that run this one?

    Just add a line before IF statement.

    fibaro:debug("Current Time = "..Time)

    Let's see what the value is?

     

    Another idea to test it, add fibaro:sleep(2000) at the beginning of the scene to make sure Time has been updated.

    Edited by cag014
    • 0
  • Inquirer
  • Posted

    HI,

     

    No the Time variable is set in another scene changing it every 12 hours or so based on sun up/down.

     

    No really think it's because of starting the scene from another scene. Manually the works just fine based on the variable.

     

    Even when i switch manually all works fine. But when i fire the other scene it just doesn't work. It's driving me nuts to be honest.

    • 0
    Posted
    23 hours ago, cag014 said:

    Just add a line before IF statement.

    fibaro:debug("Current Time = "..Time)

    Did you add this line? It's interesting to see the value before IF statement when executed by other scene and manually

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