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

Need help with lua scene light on


harry.leung

Question

Hello Everyone.

I have a question.

 

I have one UV lamp in the toilet. I want...

 

1. Turn on the UV lamp at 4 am to 5am everyday.

2. For safety, when the person enter to the toilet in this period time. The motion sensor will Breached and the UV lamp will turn off.

3. When the person leave out the toilet. The motion sensor will Safe and the UV lamp will turn on again.

 

My question is how to count the UV lamp continue turn on one hour?

Link to comment
Share on other sites

Recommended Posts

  • 0

 eHi,

You can do it in two ways:

1. Use VD to turn on UV at 4am till 5am and scene to respond to motion sensor.

2. One scene (a little bit complicated) runs at the background to turn on at 4am and Off at 5am, and to react to motion sensor. The complicate side of the scene that you need to run it in a loop and to be able to be triggered by motion sensor and to make sure that instances which react to sensor won't end-up with another loop. But it could be done.

What scenario do you prefer (by the end you will need to maintain the code)?

I could help you to write the code. In order to write proper template please post device ID of the switch which controls the lamp and device ID of motion sensor.

 

 

To your question "how to count the UV lamp continue turn on one hour?", see below (scene example)

 

Please login or register to see this code.

 

Edited by cag014
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Hi Cag014,

     

    Thanks your reply! First please forgiveme for my english to make the question confuse. Hope following example to make the question clear.

     

    1. At 4:00am the UV lamp will turn on.

    2. At 4:30am the person enter to the toilet, motion sensor (Breached) then the UV lamp will turn off.

    3. At 4:45am the person leave out the toilet, motion sensor (Safe) then the UV lamp will turn on again.

    4. At 5:15am the UV lamp will turn off. 

     

    ... the UV lamp turn off time will be variable and depend on how many person enter to the toilet after 4am. The total turn on time of the UV lamp is one hour.

     

     

     

     

     

    Link to comment
    Share on other sites

    • 0

    I've understood your question, the example above is only to show you how to keep the UV turned ON for an hour.

    No motion sensors included there.

    As  I said, if you can post devices ID for UV lamp and sensor I could to write a scene (at least template to start with)

    Link to comment
    Share on other sites

    • 0

    OK, try it. DO not forget to set scene to automatic and to 3 instances:

    Please login or register to see this image.

    /monthly_2018_07/Capture.PNG.25026d57f47b6e4782d1911441bb29d6.PNG" style="width:400px;height:auto;" alt="Capture.PNG.25026d57f47b6e4782d1911441bb29d6.PNG" />

    The motion sensor will control UV lamp between 4am to 5am... only.

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • For my understand the first part of the code is control the UV lamp turn on at 4am and the will turn off at 5am. And the second part of the code is control the motion sensor  between 4am to 5am. Sorry if i make something wrong.

     

    In this case, if the person enter to the toilet at 4:30am and leave out at 4:45am. So the total turn on time of the UV lamp will less than one hour.

    Link to comment
    Share on other sites

    • 0
    1 minute ago, harry.leung said:

    For my understand the first part of the code is control the UV lamp turn on at 4am and the will turn off at 5am. And the second part of the code is control the motion sensor  between 4am to 5am. Sorry if i make something wrong.

     

    In this case, if the person enter to the toilet at 4:30am and leave out at 4:45am. So the total turn on time of the UV lamp will less than one hour.

    Correct.

    But please remember that the sensor must stay breached while the person is in toilet. What I mean if the person will seat there quietly and is not moving, the sensor will go to "safe" condition and lamp will turn ON.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • If i want maintain the total turn on time of the UV lamp not less than one hour. So how to change the Lua code ?

    Link to comment
    Share on other sites

    • 0

    Do you need exactly one hour? The compensation algorithm will require to use global variable, my suggestion is:

    Turn on the lamp half an hour earlier and  turn off half hour later (between 3:30am to 5:30am). In this case you'll cover any use of toilet during the these hours.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi cag014, I had the experience in using global variable with scenes. If possible please can you tell me how to do it. Thx!

    Link to comment
    Share on other sites

    • 0

    Before we continue further, could you tell me if the scene is working as is now?

    I don't want to continue to develop the code based on something that doesn't run properly

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  •  The first part of the code is work well, But the second part of the code had following error message.

     

    [DEBUG] 19:45:14 line 19: attempt to index global 'currentDate' (a nil value)

    Link to comment
    Share on other sites

    • 0

    try it now

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0

    OK,

    Try this... the compensation resolution of UV lamp time off is a half-minute. I mean if the lamp is off  less than 30 seconds, no changes on off time.

    Code below includes Global Variable named "testNum". Please define global variable by the same name or change it.

    I have added one condition before turning UV light ON at 4am, verify that no one in toilet. If yes, the time will be compensated.

    The code not tested... hope it works well

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi, i have test the code in two suitation.

     

    1. no person in the toilet before 4am, In this case all function work well.

     

    2. When the person in the toilet at 4am, In this case when the person leave out the toilet & the motion sensor become safe. The UV lamp still cannot turn on and the Global Variable is"0"

     

    Thanks!

    Link to comment
    Share on other sites

    • 0

    You mean, the person enter before 4 am and leaves after 4 am... this is the case?

    Link to comment
    Share on other sites

    • 0

    Looks strange, when sensor backs to safe it should turn light on always.

    Did you change the time slot for testing?

    Link to comment
    Share on other sites

    • 0

    Have changed the code that now you can set the time slot to any value

    sTime="04:00" -- start time

    eTime="05:00" --  end time

    I have added few debug lines, so in case of error please post the debug information.

    Please login or register to see this code.

     

    Edited by cag014
    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...