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

Why is my nested if not working in a scene?


Question

Posted

Hi Guys,

Getting the error: ERROR: Line 25: '=' expected near tonumber on my nested IF and I don't get what's up with it. Tried various things and get same error. Basically it's just a scene to check that two motion sensors are breached, check a global, set a timer, turn light on, wait five mins, turn off light and change global so that it can start again.

Why it's not working I don't know but it's bugging me big time! Obviuosly some intricacy I'm not aware of coding wise. Any help appreciated:

--[[

%% autostart

%% properties

84 value

55 value

69 value

%% globals

--]]

local startSource = fibaro:getSourceTrigger();

if (

( tonumber(fibaro:getValue(84, "value")) > 0 )

and

( tonumber(fibaro:getValue(55, "value")) > 0 )

and

( tonumber(fibaro:getValue(69, "value")) <= 100 )

or

startSource["type"] == "other"

)

then

local _mins = 5;

local _id = 89;

local _global = fibaro:getGlobalValue("bed5LightTimer");

IF tonumber(_global) == 1 THEN

fibaro:abort();

ELSE

-- set global to '1' to prevent firing again til 5mins up

fibaro:setGlobal("bed5LightTimer", 1);

-- turn bedside light on to 75%

fibaro:call (_id, "turnOn");

fibaro:call (_id, "setValue", 75);

-- set timer for 5 minutes

fibaro:sleep = 60*1000*(tonumber(_mins));

-- turn off light;

fibaro:call (_id, "turnOff");

-- set global to '0' to allow firing again next time motion breached

global:bed5LightTimer = 0;

END;

END;

8 answers to this question

Recommended Posts

  • 0
Posted

Firstly, how and where did you code your scene from?

I've amended your codes accordingly and I think it will work.

Please login or register to see this code.

  • 0
  • Inquirer
  • Posted

    Hi Malvin,

    I wrote it....except some of my comments werent complete code (ie comments to be made into code like last setting of global and the timer.

    It was just the error that I was getting was preventing it moving down anyway. From what I can see youve effectively terminated one IF statement before starting the next and thats obviously where I was going wrong (will test later when home) as, in what I used to code with, nested IFs were ok so I guess theyre not in LUA!

    Many thanks, simple things sometimes the annoying when youre stuck in another language in your head!

    KR, Dave;)

    • 0
    Posted

    dw89, No problem dave, anything do let me know.

    • 0
  • Inquirer
  • Posted

    Hi Malvin,

    Ran it but got this odd error (which I also don't understand):

    ERROR: Line LUAScript

    ??

    • 0
    Posted

    dw89, Sorry, please try this

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    Hi Malvin,

    Just had to change a small syntax error and an id no (I guess you changed some bits to kindly test yourself:)) but all works fine.

    Thanks very much, I see where I went wrong now. Certainly a bit different to what I'm used to so it's a bit difficult to get out of old habits!

    I assume that ~= means 'not equal to'? In PL/SQL I'm used to that being != so want to check.

    Thanks again mate

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

    Dave

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    • 0
    Posted

    Hi dw89, sorry for the late reply. Had a long weekend holiday over in Singapore.

    Yes I did some id no. changes to test myself. I'm a java programmer myself and all I've learnt was != (not equals to) but for lua case, it's ~= (not equals to). So I guess we have to adapt to changes.

    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" />

    No problem Dave, glad to have help you.

    • 0
  • Inquirer
  • Posted

    Hi Malvin,

    No probs at all mate, thanks for the help.

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    Anyone who can program Java gets my full respect...this must be easy for you. I'm not a natural programmer....I learnt various languages for my job but could never get the hang of Java....but then again that's only because it wasn't used as much then in what I did compared to now so I guess if I'd had more exposure to it I would have got it in the end!

    Speak to you around

    Dave

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

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