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

Starting learning lua, some help please! ;)


Question

Posted

Hello people, as you know I'm not a programmer, so as I have the need to code my scenes I'm learning.

 

I get some code found in this forum and made some changes to understand what is going on.

So I trying to check if one of this two lights ( ID: 95 and 97) are ON, but with this code, only if the two lights are ON that 'lightsOff' equals to false, and I want to change that to If one of them is ON then lightsOff = false.

 

Here is the code:

Please login or register to see this code.

what do I have to change in checkLights function?

 

Thanks.

4 answers to this question

Recommended Posts

  • 0
Posted

it is a complex way to do something simple that you have picked up but lots of good techniques in there for when you have a more complex task

 

the problem is

 

status == "0" then lightsOff = false

 

 

is the reverse logic for you. Think you want to work out your test logic

   

 

just now

 

95 is off (status "0")            never test 97 (could be "0" or "1")                 lightsOff = false 

95 is on (status "1")            97 is off (status "0")                                       lightsOff = false 

95 is on (status "1")            97 is on(status "1")                                        lightsOff = true

  • 0
  • Inquirer
  • Posted

    Thanks robmac, I know this is a bit more complex code for what I want to do, but thats just the beginning and how we learn to code

    Please login or register to see this image.

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

     

    Now back to the problem, you are right, its a logic problem, It should be if status ~= 0 then lightsOff = false

    Please login or register to see this image.

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

     

    I'm going to learn, but I need some guidance from more experience people like you!

     

    Thanks once more,

    Morcegolas.

    Please login or register to see this image.

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

    • 0
  • Inquirer
  • Posted

    Now another step, I only want the scene to activate when the motion sensor == breached, and now it activate the scene anytime motion sensor value changes.

     

    This is the code of starting the scene:

    Please login or register to see this code.

    I know I should use something like this in the else if:

     

    if (tonumber(fibaro:getValue(98, "value")) > 0  ) then
    SceneTriggered();
     
     
    EDIT:
     
    I do it this way, its working, I just want to know if its the best way to do it?

    Please login or register to see this code.

    Thanks.

    • 0
  • Inquirer
  • Posted

    Ok, with your help I was able to remove ( disable for now, while you help me tuning this code ) 6 block scenes from my HC2, and do it all with just 1 lua scene.

     

    This is working, but with some 'BUGS'

    Please login or register to see this image.

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

     

    If the scene is first activated by sensor2 in Zone2 everything works as expected, I can go to Zone1 it activate the lights, timer and so on, I can go back to Zone2 even the lights are already Off because they will turn On.

     

    BUT :/ if the scene is first activated by sensor1 in Zone1, when I go to Zone2 it debugs: [DEBUG] 20:32:05: LightsOff Zone1 = false

    when it should check Zone2.
     
    I messed up some place, can you help me finding it out? This is my actual code:

    Please login or register to see this code.

    Thanks.

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