Jump to content
Guides for the Forum Read more... ×
Poradniki na Forum Read more... ×
  • 0
harry.leung

Need help with lua scene light on

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?

Share this post


Link to post
Share on other sites

Recommended Posts

  • 0
Posted (edited)

 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

Share this post


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

     

     

     

     

     

    Share this post


    Link to post
    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)

    Share this post


    Link to post
    Share on other sites
    • 0
  • Inquirer
  • Hi Cag014,

     

    The UV lamp ID : 70

    The Motion sensor ID : 40

     

    Thanks !

    Share this post


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

     

    Share this post


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

    Share this post


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

    Share this post


    Link to post
    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 ?

    Share this post


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

     

    Share this post


    Link to post
    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!

    Share this post


    Link to post
    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

    Share this post


    Link to post
    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)

    Share this post


    Link to post
    Share on other sites
    • 0

    try it now

    Please login or register to see this code.

     

    Share this post


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

     

    Share this post


    Link to post
    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!

    Share this post


    Link to post
    Share on other sites
    • 0

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

    Share this post


    Link to post
    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?

    Share this post


    Link to post
    Share on other sites
    • 0
    Posted (edited)

    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

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    ×