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

Overrule Pir sensor / manual switch lights


Question

Guest imparator
Posted

Hi, can some one give me a example to next one :

i have a pir sensor, that turns lights on and off after 3 minutes.

when i click the lights on with one click and i walk in the room , the sensor see movement, it turns the lights off after 3 minutes.

What i will is :

that the manual click overrule the sensor, when i put the lights on, with a click, the lights stay on

till i click it off.

so the sensor don't put the lights off automatic .

Lua:

--[[

%% autostart

%% properties

200 value

200 armed

%% globals

kleedkamer_sensor

--]]

local startSource = fibaro:getSourceTrigger();

if (

( fibaro:getGlobalValue("kleedkamer_sensor") == "Aan" )

and

( (tonumber(fibaro:getValue(200, "value")) > 0 and tonumber(fibaro:getValue(200, "armed")) == 0) )

or

startSource["type"] == "other"

)

then

fibaro:call(188, "setValue", "20");

setTimeout(function()

fibaro:call(188, "turnOff");

end, 240000)

end

14 answers to this question

Recommended Posts

  • 0
Posted

You would need to create global variable for overriding automatic light control.

Let say that variable would be called LightManualControl.

When lights are switched on, give value 1 for variable LightManualControl.

When lights are switched off, give value 0 for variable LightManualControl.

On automatic light control add one more "if", so light will turn off only when sensor is safe AND LightManualControl = 0.

  • 0
Posted

Try this:

Please login or register to see this code.

This will only allow this scene to turn the light on if you haven't turned the light on first. If the light is already turned on, the PIR will do nothing.

  • 0
Posted

I made this in living room with two block scenes.

In normal situation lights will turn on if there is motion and dark.

And after 20 minutes of not breaching the sensor (there is another delay on sensor) they will turn off.

If I use switch for turning lights on (if it's not dark enough), lights will stay on until the motion sensor is safe for 20 minutes, after that they will shut down and return operating normally via motion control.

If I want to shut down lights manually, they will be shutted down until there has been no motion for 10 minutes. After that they will return operating normally via motion control.

There is also 10 minutes delay on sensor that is not seen on block codes.

And there is also global variable for disabling motion control (turning on), mostly used by home / away -status.

Lux control is not working properly, because Fibaro Motion control does not report correct values. So, maybe in V4...

Please login or register to see this attachment.

Please login or register to see this attachment.

  • 0
Guest imparator
  • Inquirer
  • Posted

    Dalle1985,

    Your code works great, thanx

    But can you explain me the code please so i can learn about it

    Please login or register to see this image.

    /emoticons/default_icon_redface.gif" alt=":oops:" />

    • 0
    Posted

    Actually, we can simplify the code even further:

    Please login or register to see this code.

    So, the above code doesn't include the autostart property, that is because the autostart property will trigger the scene when the HC2 is booted up. That is unnecessary as the next property ("properties") will trigger the scene when the motion sensor 200 changes value. Thus making the autostart property redundant.

    I've also removed your wardrobe global from the properties section as again, this will just make the scene run when the global changes state. This is again redundant as the scene is triggered by your motion sensor.

    Next, we have a set of conditions which must all be correct for the light to switch on:

    Kleedkamer-sensor must have the value "Aan"

    And

    The sensor (id=200) value must be above 0 (0 means no motion, anything else means motion). You might think "but the scene only triggers when there is motion so why is this necessary", but actually, the scene triggers when the value changes, so it will also trigger when the sensor changes from motion to no motion.

    AND

    The sensor (id = 200) must not be armed (this is something to do with the alarm) because you only want the light to turn on, when there isn't a burglar in the house

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" /> . I personally don't use this, as I have another way to run my alarm setup, but I left it in there.

    AND

    The light you want to turn on (id=188) must not be on. This is really where the "magic" happens. Your previous code would trigger the light to switch off whenever motion was detected after 3 minutes, no matter if the light was switched on manually or not. By checking the light state first, we ensure that the body of the code is only executed if you didn't already turn the light on manually.

    THEN if all the above conditions are correct, it will execute the body which:

    - switch on the light 188

    - goes to sleep for 240000 milliseconds (3 minutes)

    - turns the light 188 off

    However, if all the above conditions are not true, the scene will simply stop again without doing anything and thereby let you control the light manually.

    I hope that made it a bit clearer what the code does?

    • 0
    Posted

    Dalle1985,

    bravo!

    A really nice gest to explain it concisely!

    • 0
    Posted

    Dalle1985 , good work , but i understood this code except the Kleedkamer-sensor ,is it a variable of lightstatus or what ? and what is Aan means?

    Please login or register to see this image.

    /emoticons/default_icon_redface.gif" alt=":oops:" />

    • 0
    Posted

    Yes, kleedkamer_sensor is the global variable that stores the operational status of the wardrobe motion sensor. "Aan" is dutch for "On".

    • 0
    Posted

    UrSv , thanks for quick responding, i tried the code which Dalle1985 explained , and i found that the lights turned off even there still was a motion in wardrobe , so i tried to write below code and get quotation from Dalle1985

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" /> , this code suppose to turns the lights on when motion is detected and begin the timer (4 minutes) , if there is a motion during 4 minutes it will reset the timer , and it also allows manual operation (on/off from normal switch) . what's your opinion Dalle1985 ,UrSv, and any friend here.

    Please login or register to see this code.

    • 0
    Posted

    Hi noor,

    Ahh yes... That looks like something I wrote once. That code is a bit smarter than the first sample - which was just a quick rewrite of what he already had. The code you have there is doing a bit more. This will basically turn on the light, and then every second check if someone switched off the light manually. If the light was switched off manually, the scene kills itself. If the lights are turned on manually, the scene will just kill itself without doing anything.

    Lets try and deconstruct it (I've cleaned it of comments to avoid confusion):

    This snippet of code defines the triggering devices, so when the id 200 property "value" changes, the scene will trigger (i.e. when motion is detected):

    Please login or register to see this code.

    This piece of code is missing from above code, but is actually pretty important (again, a very quick rewrite of the existing code). This ensures that the HC2 doesn't invoke 1.000.000.000 instances of the same scene in very quick succession. Without it, the HC2 is free to start as many instances as it pleases. What it does is to check the number of running instances of this scene. If more than 1 instance is running any new instances will abort (meaning only one scene actually executing code). Lua is sequential, so it will read the code as it is written. So because this comes before any of the main code, the "real" code won't be executed if an instance of the scene is already running. This is always a good idea to put in your code.

    Please login or register to see this code.

    This defines the IDs of the motion detector and the light you are operating, they are remnants of another piece of code which explains their naming:

    Please login or register to see this code.

    This is the triggering conditions which must hold true to allow the scene to operate the lights. It checks that the motion detector is actually showing motion. Remember, the scene triggers both when going from "no motion" -> "motion" and when "motion" -> "no motion" so we only want to turn on the lights when it is changing from "no motion" -> "motion" not vice versa. It also tests that the light is actually turned off. This is in order to ensure that the scene doesn't assume control of the light if it was turned on manually before registering motion:

    Please login or register to see this code.

    This defines how long the light should stay on before it is switched off. The "timer" is there to have both a working variable and a fixed one which defines the offtime, by doing it this way, the "timer" can always be reset to the "starttimer" throughout execution:

    Please login or register to see this code.

    Turn on the light at dimlevel 20:

    Please login or register to see this code.

    The next lump of code is a loop which repeats every second, everything inside the "repeat" and "until" tags will run every second.

    First, it sleeps for 1000 ms before executing the code:

    Please login or register to see this code.

    Then, it runs an if test, which checks if the light has been turned off (The value is less than 1). If that is the case, it will turn off the light, write this in the debug window, sleep for 10000 ms and then break the loop (it forces it to quit even though the until condition has not been met). The reason for sleeping for 10 seconds before moving on, is that the motion sensors have a default 10 second hold feature to avoid it reporting motion 47 times pr second:

    Please login or register to see this code.

    It then repeatedly turns on the light. Don't ask me why

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

    Next piece of interesting code is the algebra which counts down the timer by subtracting 1 from it every time the loop executes:

    Please login or register to see this code.

    This piece of code then checks the state of the motion sensor, so if motion is detected before the light is turned off, the timer is reset to 240 seconds - this way, light will be on for as long as you are present - and 4 minutes after:

    Please login or register to see this code.

    Then there is something of an error in the code. It subtracts 1 more from the timer. This means that the scene is actually only on for half the period it should be. Remove this second instance of:

    Please login or register to see this code.

    Now we've exited the loop (the timer runs out). This last piece of code turns off the light, writes it in the debug window and then kills itself. It shouldn't be necessary to have the "killScenes" line in there, but I've used it as I've experienced some issues with scenes hanging and therefore blocking new scenes executing (remember that first piece of code which only allowed one instance):

    Please login or register to see this code.

    The end!

    Please login or register to see this code.

    There is also an even more elaborate version floating around the forum which will turn on the light, wait a fixed amount of time and then start to dim it out slowly. This is good if you sometimes stay in the room but move out of sight of your motion detector, because it doesn't just kill the light, but gives you a warning to start moving, wave your arms or whatever is your preference when trying to invoke the attention of your motion detectors.

    [ Added: 2014-12-08, 11:19 ]

    This is the code I personally use for my dimmers. It has some additional functionality in it:

    - It will only turn on the light, if the measured light level is below a certain threshold. If you dont have a light sensor, just put the lux level to 10000 and set the id to the same as the motion sensor

    - It doesn't just switch off the lights, it instead dims them slowly (1 step pr second) before turning them off

    - If the motion sensor is retriggered before the light switches off, it will reset to full light level and start the timer over (the timer is default at 60 but can be changed)

    - If the light is turned off manually, the scene won't turn it back on but kill itself

    - It has two different On levels!

    Just beware, that this scene is created so that you can actually disable it by changing a global variable between 1 and 0. You need to create a global variable called "motionoverride" for this scene to work. When the global "motionoverride" is 0, it will turn on the lights at the level set by the variable "ondimnormal", when it is 1, the lights will turn on to the level set by the variable "ondimblock" (currently set at 0 = off). I use this to turn on the lights in our hallway to a lower light level at night when you need to go to the bathroom. If you set it at 0, the light won't come on when "motionoverride" is 1.

    Feel free to try it out - I think it makes for a nicer lighting experience:

    Please login or register to see this code.

    • 0
    Posted

    Thank you for responding ,i apperciate your experience my friend Dalle1985 , sorry for the delay in a reply :-> , i tried your final code , i am sure that code was the best one i saw , but did you mean by override for motion is e.g. to neglect or cancel motion sensor in daylight and to enable it in night .

    I created motionoverride in variable panel and i attached two scenes i did , is that what you meant or not?

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    • 0
    Posted
    Thank you for responding ,i apperciate your experience my friend Dalle1985 , sorry for the delay in a reply :-> , i tried your final code , i am sure that code was the best one i saw , but did you mean by override for motion is e.g. to neglect or cancel motion sensor in daylight and to enable it in night .

    I created motionoverride in variable panel and i attached two scenes i did , is that what you meant or not?

    That is more or less the purpose, however, it already has a daylight cut-out in the form of the lux sensor. As an example, this scene does the following in our dining room:

    At day, when lots of sunlight comes in and the light level in the room is above 50 Lux, the scene won't turn on the lights (it wouldn't make sense). If you are in the dining room at dusk (here in scandinavia, it comes crawling in over hours), the lights will automatically come on when the light level drops below 50 - I have found this to be the level where we would normally turn on the lights manually.

    Then, when we go to bed, because we have a dog, I don't want the lights to turn on with motion then (we have 200 W of lighting in there, and I don't want to let that burn just because of the dog). Therefore, I have a scene which switches the motionoverride value to 1 when we switch off both our bedlamps. This effectively disables the motion sensor at night, but without switching it off - therefore, it can still work as an alarm sensor.

    Another place where I use it is in the hallway between our bedroom and our bathroom. Here it does more or less then same, but with the exception that at night, after we go to bed, after motionoverride is set to 1, if motion is detected in the hallway, where I have 12 Hue GU10 spotlights, it will switch on a single hue bulb straight between the bedroom and the bathroom to provide a "nightlight" without blinding tired eyes. The scene looks a bit different because it is a hue and not a zwave bulb, but the principle is the same.

    So you can use the motionoverride as it fits in with your needs, but I use it to disable motion at night after we've gone to bed, or when we are out and I've enabled my custom alarm system.

    • 0
    Posted

    It really make sense , thank you for quick responding ..

    • 0
    Guest imparator
  • Inquirer
  • Posted

    Dalle1985, thanks for your code , it works great.

    but is this also possible with a on off switch with a pulse button. without the timer

    in de morning 80% light , in the evening 40 %?

    and can you help me with this also ?

    Please login or register to see this code.

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