Motion driven light control, but only when it is dark

Yes, I know this can easily be done with PLEG or LUUP, but I wanted to see if it could be done without resorting to either.


PROBLEM: I want the hallway light to go on if someone walks down the hallway, but only if the hallway is dark.

SOLUTION: The AEON 4-in-1 sensor has motion sensing, humidity, and temperature sensing, and light sensing.

Turning on the Hue light bulb if motion is sensed is pretty easy. But how to do it it the light level is below 100?

Here is how I did it with scenes;

Setup a scene that will ARM the hallway motion sensor if the light falls below your threshold.
Setup a scene that will DISARM the hallway motion sensor if the light is above the threshold.
Setup a scene to turn ON the hallway light if the motion sensor senses movement, and is ARMED.
Setup a scene to turn OFF the hallway light if the motion sensor no longer senses movement regardless of ARMED or DISARMED state.

I’m looking at something similar, and was going to use Combination Switch (from App store).

I looked at that too; I guess I wanted to keep things as simple and OOTB as possible. It appears you have to re-work things often with Vera and upgrades tend to break a lot of stuff that is custom :-).

Simple answer I’m afraid, you can’t.

Sadly, even if you could with the light sensors built in logic built in to some light meters, they are typically not smart enough to realize that when the lights are on, the light brightness will always be high and your light won’t turn on again until it’s dark for 15+ minutes. Your better bet is to do time of day based on sunset (or an offset if using day/night plugin).

That is why you would want LUUP/PLEG code to get you data from an independent light sensor (outside)…and tying in the state of other devices always needs PLEG/LUUP.

Personally, I don’t use an light sensor. I use PLEG + Weather Plugin to activate ‘dark mode’ whenever it’s raining or cloudy or Night (defined in day/night as 30 minutes before sunset). I also have a bedtime, bright (daytime and not cloudy), and wakeup modes to have different levels in those time period.

[quote=“AgileHumor, post:4, topic:182529”]Simple answer I’m afraid, you can’t.

Sadly, even if you could with the light sensors built in logic built in to some light meters, they are typically not smart enough to realize that when the lights are on, the light brightness will always be high and your light won’t turn on again until it’s dark for 15+ minutes. Your better bet is to do time of day based on sunset (or an offset if using day/night plugin).

That is why you would want LUUP/PLEG code to get you data from an independent light sensor (outside)…and tying in the state of other devices always needs PLEG/LUUP.

Personally, I don’t use an light sensor. I use PLEG + Weather Plugin to activate ‘dark mode’ whenever it’s raining or cloudy or Night (defined in day/night as 30 minutes before sunset). I also have a bedtime, bright (daytime and not cloudy), and wakeup modes to have different levels in those time period.[/quote]

My light/motion sensor is at the end of the hallway and out of the hallway light enough that I’m hoping it will still work. I have the Day/Night plugin but then you need the logic to say If motion is detected and it is night time, then turn on the light…

I tried to get the Combination app to work, but the docs say you can only configure it using Firefox … and I’m still trying even with Firefox (no go). I would use PLEG, paid for it, but can’t enter the registration code (another error);

Error executing function J_ProgramLogicC.js.plc_Register(): req is not defined

This is fun; I had no idea I could find so many walls in such a short period of time ;-).

I do this for my ‘nightlight’.

I have the trigger as motion sensed.
I have LUA code int he trigger than then checks:

  1. If the light is already on any level (its dimmable). (returns false)
  2. If the lightsensor is above I think 20. (returns false)
    Action turn on the light to 30% and start a countdowntimer app

I have another scene which simply turns off the light with the trigger being the countdowntimer reaches zero.

The returns false blocks the scene from running. I have both conditions which are somewhat redundant because the light sensor is only polled on an interval so it has happened where I turn on the lights, than the motion detector sees me, than turns the lights to 30% and off in 2 minutes (which aggravates me because I just turned them on manually).

I figured this out in the scene scripting sticky. It has 99% of the LUA needed.

EDIT: Reading comprehension… I didn’t see you don’t want to use LUUP. Opps. Well hopefully my post helps someone.

[quote=“hmspain, post:5, topic:182529”]I would use PLEG, paid for it, but can’t enter the registration code (another error);

Error executing function J_ProgramLogicC.js.plc_Register(): req is not defined[/quote]
This sounds like you have not installed the Program Logic Core app, a prerequisite of PLEG and others. If you have installed the PLC app, then contact @RichardTSchaefer on this forum. He’d help you, even if you hadn’t paid for it.

[quote=“Z-Waver, post:7, topic:182529”][quote=“hmspain, post:5, topic:182529”]I would use PLEG, paid for it, but can’t enter the registration code (another error);

Error executing function J_ProgramLogicC.js.plc_Register(): req is not defined[/quote]
This sounds like you have not installed the Program Logic Core app, a prerequisite of PLEG and others. If you have installed the PLC app, then contact @RichardTSchaefer on this forum. He’d help you, even if you hadn’t paid for it.[/quote]

The prerequisite was not clear; I (no doubt) missed it in the documentation (which is otherwise VERY complete) :-). I just installed the PLEG core and still get the same error. Perhaps a reboot is required :-).

Reboot and reload your browser.

Done (reboot both Vera and my browser). I have PLEG and PLC loaded. Still getting:

Error executing function J_ProgramLogicC.js.plc_Register(): req is not defined

Sorry, I know it’s something dumb I did, but can’t quite put my finger on it. I had PLEG (and PLC) loaded and registered a while back, but removed them (since I was not using them). I’m sure my back and forth has something to do with this. Uninstalls are rarely perfect :-).

[quote=“joer., post:6, topic:182529”]I do this for my ‘nightlight’.

I have the trigger as motion sensed.
I have LUA code int he trigger than then checks:

  1. If the light is already on any level (its dimmable). (returns false)
  2. If the lightsensor is above I think 20. (returns false)
    Action turn on the light to 30% and start a countdowntimer app

I have another scene which simply turns off the light with the trigger being the countdowntimer reaches zero.

The returns false blocks the scene from running. I have both conditions which are somewhat redundant because the light sensor is only polled on an interval so it has happened where I turn on the lights, than the motion detector sees me, than turns the lights to 30% and off in 2 minutes (which aggravates me because I just turned them on manually).

I figured this out in the scene scripting sticky. It has 99% of the LUA needed.

EDIT: Reading comprehension… I didn’t see you don’t want to use LUUP. Opps. Well hopefully my post helps someone.[/quote]

Well i’d like to see your luup code, as i’m going to do something like what you have done soon :slight_smile:

Stolen from the example scripting:

– Run this scene ONLY after sunset and before 6:00am
local pStart = 0 – Start of time period, minutes offset from sunset
local pEnd = “06:00” – End of time period
local allow = true – true runs scene during period, false blocks it
local mStart = math.floor( (luup.sunset() % 86400) / 60 ) + pStart
local hE, mE = string.match(pEnd,“(%d+)%:(%d+)”)
local mEnd = (hE * 60) + mE
local tNow = os.date(“*t”)
local mNow = (tNow.hour * 60) + tNow.min
if mEnd >= mStart then
return (((mNow >= mStart) and (mNow <= mEnd)) == allow)
else
return (((mNow >= mStart) or (mNow <= mEnd)) == allow)
end

As I understand things, the LUUP code will STOP the scene from executing during the day, but allow it to function “normally” from dusk to 6am.

I am looking something similar to this. Can yu share with me how you used weather condition to sense light or actually ‘dark’. Regards,

[quote=“AgileHumor, post:4, topic:182529”]Simple answer I’m afraid, you can’t.

Sadly, even if you could with the light sensors built in logic built in to some light meters, they are typically not smart enough to realize that when the lights are on, the light brightness will always be high and your light won’t turn on again until it’s dark for 15+ minutes. Your better bet is to do time of day based on sunset (or an offset if using day/night plugin).

That is why you would want LUUP/PLEG code to get you data from an independent light sensor (outside)…and tying in the state of other devices always needs PLEG/LUUP.

Personally, I don’t use an light sensor. I use PLEG + Weather Plugin to activate ‘dark mode’ whenever it’s raining or cloudy or Night (defined in day/night as 30 minutes before sunset). I also have a bedtime, bright (daytime and not cloudy), and wakeup modes to have different levels in those time period.[/quote]

Warning on that example: as far as I can tell, the calculation will only work if you are in GMT because it mixes UTC with local time. I think you are better off using PLEG, but if you want to use the example code, I suggest you change the mStart calculation to this:

local tStart = os.date(“*t”, luup.sunset())
local mStart = (tStart.hour * 60) + tStart.min + pStart

The original uses luup.sunset() directly which returns UTC; the above uses os.date to convert it to local time/date.