LUUP Beginner - Need Help

I must admit, if I could think of a word that indicates “less than a beginner”, I would’ve used that. I don’t know even know the basics. This leads me to my question. Where can I go (online) to learn how to begin to learn LUUP (or is it LUA? I’m confused)?

Here is my end goal:
My kids and girlfriend do not comprehend the fact that a light can actually be turned off. So, I’ve installed a ZWave switch and setup a scene with a scheduled trigger. At 10pm, the light will turn off. That works. However, if either my kids or my girlfriend turn ON the light after 10pm, it stays on until 10pm the following day.

My Goal:
I would like to setup logic that turns off the light at 10pm. Then, between the hours of 10pm and 6am, check every 20 minutes. If the light is on, turn it off.

This is starting to become a Moravec EasyHard problem for me.

Any help is greatly appreciated,

Perhaps “tyro” or “neophyte” ? … not to be pejorative.

What to do depends on what you’re interested in learning. The “Easy” solution is to install PLEG (a forum search will tell all.) The “Hard” one is to learn Lua (the language) and Luup (the UPnP extensions.)

HA is not so much EasyHard, but EasyDesperatelyTimeConsuming.

Internet points for mentioning the Moravec paradox.

One dirty solution is to schedule your Lights Off scene to run at 10 pm, 10.20, 10.40, 11 pm, … and 5.40 am. That will actually achieve exactly what you’ve asked for. (But I doubt it is what you want, because if you turn the lights on at 11.59 they are going to go off again at 12 midnight.)

So I am going to assume that what you really want is for turning the lights on to start a 20-minute timer, at the end of which the light will turn off. Turn the light on at 11.59 and it turns off at 12.19.

You can definitely do this with Lua code. It’s actually very tedious though because you have to do it with event-driven programming, and then you have to deal with the oddities of the luup.call_delay() function.

That’s why we recommend you get a plugin to do it. I can think of three.

PLEG is the all-singing all-dancing logic plugin that does combinations, timers, and lots more. I can’t write the code for you because (shame) I don’t use it or know its language. But go over to the Program Logic subforum and ask away. Someone will probably even write it for you.

The Countdown Timer plugin is a lightweight kitchen-timer device which can fire off an event when it hits zero. There’s a sample here which does almost what you want:,9425.msg62531.html#msg62531

The Smart Switch plugin may also bring you joy. I don’t use it so I don’t know if it works without security sensors. Here is the thread:

If you really really want to learn Lua then good (and we can help). But this might not be the thing to learn it on.

An easy way to do it would be to set up a scene based on the light being turned on. The action would be a 20 minute delay that turns the light off. In the trigger code area check the time. Here is a link to some generic code that will check the time. If the time is within the range, return true.,18679.msg141962.html#msg141962

This is the code of interest for you:

local pStart = “22:30” – Start of time period
local pEnd = “06:15” – End of time period
local allow = true – true runs scene during period, false blocks it
local hS, mS = string.match(pStart,“(%d+)%:(%d+)”)
local mStart = (hS * 60) + mS
local hE, mE = string.match(pEnd,“(%d+)%:(%d+)”)
local mEnd = (hE * 60) + mE
local tNow =“*t”)
local mNow = (tNow.hour * 60) + tNow.min
if mEnd >= mStart then
return (((mNow >= mStart) and (mNow <= mEnd)) == allow)
return (((mNow >= mStart) or (mNow <= mEnd)) == allow)

Paste that into the code area of the trigger. Change the pStart and PEnd to times that make sense to you. There are caveats to this as well. If the light is turned on and within the time frams, the delay will start. In 20 minutes the light will go off even if the light has been turned off and back on again. A more full proof thing to do would be to invest in a motion detector and use that as the timer. PLEG could handle this for you and there is a Smart Switch Plugin that has a timer and bypass options to it. Maybe you can combine that with the code above to get a solid solution.

Not the cheapest solution, but can you use a motion sensor where this light is located?

Then you don’t need to touch the switch at all. Just setup a delay to turn the light back off after 5 minutes or so.
I have a couple setup as “night lights” with dimmable lights. When armed and tripped, they turn on a couple of dimmable lights to 20%. After 5 minutes and no movement, they’ll turn themselves back off.

I set my delay to 5 minutes, because by default, my motion sensors reset after 4 minutes(you can adjust this at the cost of battery life). But 5 minutes works pretty good for me.

Could be done with a few scenes if you don’t mind having the lights stay on a little lonerg. You could add a couple of scenes to run after they normally quit for the night. (Say midnight and 2:00am?). My only concern would be if someone is up late or in the middle of the night, they could have the lights shut off on them at an inopportune time. You could run a dim mode to give fair warning of the impending lights off situation.

Sent from my iPad using Tapatalk