My first PLEG timer script just turned off lights after they had been on for 30 minutes. What I want now is a PLEG script which will replace a standard Occupancy detector just like the one in a bathroom. If any light in the room, there are several, is turn on, even remotely, and there is no motion in the room for x minutes I want to turn off all of the lights.
This seems to be harder that I though it would be. I tried taking the script from the PLEG Basics manual which turn on a light when you enter the room but I’ve not yet been able to make a modified version that will work. I think the basic problem is detecting when any lights turns on but you can’t use the light status since it stays on and thus looks the script up.
I was hoping someone has written one that I might learn from. In the mean time I’ll keep hacking away at it.
Still working on this. The problem is getting the timer to start. Right now I’m working with just one light and a virtual motion detector. Since I’m turning on the lights from within UI5 motion will always be off for now.
While I was writing this I see another post came in. One thing I see that I don’t think will work is the combination switch only that it won’t change states when a second light comes on. If I don’t want other lights turning to to retrigger it might work fine.
So here is my ON sequence sequence requirements:
[ul][li]When any light turns ON trigger a Self ReTrigger timer set for 10 seconds. This way any scene controller can trigger any light and the sequence starts.[/li]
[li]If there is motion while any light is ON then retrigger the timer. [/li]
[li]Motion during the first 30 seconds after all lights OFF will trigger the timer and the lights will turn back ON. After 30 seconds motion will not trigger the lights.[/li][/ul]
I tried this code which is only set for one light just to get started. (tMrBathMain and tMrBathMotion) or (!tMrBathMain; tMrBathMain < 30) I thought this would trigger the timer if the light went from OFF to ON.
If the timer has been OFF for more than “n” minutes then turn OFF all lights. I thought this function (only set for one light currently) would turn OFF the lights but it doesn’t.
cMrBathOff uses this code tMrBathMain and !stMrBathTimer and (tMrBathMain; !stMrBathTimer > 10:00)
Which I though meant if the lights are ON and the timer is OFF and the timer has been OFF for at least 10 minutes then turn the light OFF.
I’ll look at what resq93 posted and try some more.
I’ve been thinking some more about how this should work so here is my latest.
The concept is based on California’s Title 24 requirements for lights in Bathrooms. Could be used in other rooms as well. The idea is that you have to manually turn on the lights and the Occupancy detector will turn them off in the time you set but never longer than 30 minutes. It is permissible to have the Occupancy sensor turn the lights on if they have been off for less than 30 seconds. This way if you’ve been in the shower and the lights go off you can open the door and wave your hand and the lights will come back on.
So how do we emulate this plus handle more than one dimmer in the bath room?
Here is the logic that I’ve worked out. It assumes a re-triggerable timer and three dimmers. In my case the three dimmers control two vanities plus a ceiling light. The act of any dimmers moving from a off to on state starts the sequence. Since the entire sequence is triggered from the lights themselves any other scene or other automated function can start the sequence just by turning on any of the lights. If the timer out and there is motion within 30 seconds then the lights should be returned to the same state they were when they timed out.
I think this sums of the various conditions needed to preform this function.
if (any light changing state from off to on or dimming level of any light changes) then {(re)trigger the timer} /*This need to detect any (on) state change of any light, if another light is already on */
if (timer times out) then {capture current state of the lights and then turn them off} /* The captured state will be use to turn the lights back on if motion is detected*/
if (motion and (!timer < 30 seconds) then {return lights to previous state} /* This only turns the light back on if the timer has been off for less than 30 seconds */
if (timer and no lights on) then {reset timer} /* no reason to keep the timer running if the lights were turned off manually */
I use a door sensor on my bathrooms to keep me from waiving my hand.
If any of the lights were on and the door was closed, then opened back up turn them off after a timer expires.
Anyone in the shower or on the john in my house would have had the door closed. After they opened the door I figure they are leaving or left the bathroom.
@integlikewhoa could you be so kind and share your associated PLEG report as to how you particular situation has been solved? Helps greatly for the PLEG challenged folks like myself ;D. Mike
[quote=“integlikewhoa, post:5, topic:189942”]I use a door sensor on my bathrooms to keep me from waiving my hand.
If any of the lights were on and the door was closed, then opened back up turn them off after a timer expires.
Anyone in the shower or on the john in my house would have had the door closed. After they opened the door I figure they are leaving or left the bathroom.[/quote]In a master suite bathroom door sensors don’t work. The door could be open or closed so you can still be in the shower when the lights go out so you still need the retrigger.
[quote=“Timon, post:7, topic:189942”][quote=“integlikewhoa, post:5, topic:189942”]I use a door sensor on my bathrooms to keep me from waiving my hand.
If any of the lights were on and the door was closed, then opened back up turn them off after a timer expires.
Anyone in the shower or on the john in my house would have had the door closed. After they opened the door I figure they are leaving or left the bathroom.[/quote]In a master suite bathroom door sensors don’t work. The door could be open or closed so you can still be in the shower when the lights go out so you still need the retrigger.[/quote]
Yup everyone has different setup and needs. My suggestion was mostly started for the guest bathroom circulation fan. I was having problems with guest steaming up the room (its small) without turing on the fan. That’s when the door sensor came into play. After door was closed and light was on for more then 2 min fan kicked on. That room is small and has only one small window with no skylight. So the light is usually turned on when in use. But others might have a bright bathroom and not get a light on during the day.
So of-course mileage varies depending on your setup. But its an option that may work for some.
I don’t have a good understand of PLEG yet some of the issues I see are:
How to tell when each light turns on or changes states when another is already on.
How to setup a global array containing the lights settings when they turn off.
It may be that I’ll have to access luup code or just write the whole thing in luup.
I would think this would be a nice plugin. You would select the motion detector and the lights to use, what the timeout period you want and how long after there is no motion you want the lights to come on and the plugin does the rest. One added feature is if you didn’t have a motion detector then the lights would turn off after none were touched after a defined period of time. That’s also a backup if the motion detector failed.
Surely this can not be a new problem and someone out there has developed a working PLEG solution? When it comes to developing a new PLEG solution, users seem to pose their problem set(s) with little to no examples and/or working solutions provided. I’ve noticed that the LUA threads provide a lot more working solutions (code snip-its) that users can study and modify to meet their situations. I know I’m bitching but a few more bread crumbs from those who have solved these HA problems would help. I keep reading these threads where multiple users are shying away from using PLEG citing that it seems be powerful but is difficult for the common user (non software type) to grasp, hence @wilme2 recommendation to use “Smart switch”. Any thoughts… Obviously this doesn’t solve @Timon problem, but I believe it’s time to re-emphasis to the advance useres that the medium to begining user need to be provide better examples than what is currently within the PLEG Basics… Mike
Examples are in this sub-forum, but I don’t disagree it takes a lot of work to find relevant examples that are readily understandable to those who are new or who have trouble with the logic constructs. PLEG keeps you from having to write mountains of code - but the logic of how to automate something so it seems natural isn’t trivial. I can post some of my PLEG - nearly all my lights are automated…
@wilme2 thanxs for the comeback, I’m not knocking PLEG nor that there are a number of works in progress (examples), I too think it (PLEG) is a much better way than having to write “mountains of code”, but in particular motion sensors (PIR vs Security) seem to be the majority of folks “Achilles heel”. Things the some take for grant has eluded the rest of us such as what is the difference between PIR vs Security sensors, how to properly setup ones sensor up (e.g. OnTime) that it might work properly with PLEG, what PLEG code logic that goes beyond simply triggering on the initial motion and then times out after the timer settings. I’ve yet to find a working example that stays alive (light or device stays On) with additional motion after the initial, most folks are using the PLEG basic example #1.
Yes please, I would greatly appreciate any posting of your automated lights routines. Mike
OK, due to the sensors I am using, true occupancy sensors that only send motion (they don’t send anything when motion stops) and the no motion is populated via
the EnOcean plug-in, most of my logic doesn’t do what you want - which is start/re-start a timer at each motion and use that timer to determine when to turn off the lights.
I do have a few lights that don’t operate on the default EnOcean plug-in no-motion timer, and two are in the attached status - my kitchen and my office lights. The office lights are the more straight-forward example. There are 4 conditions all grouped together - OfficeOccupiedCondition, OfficeFanLightsManualOperation, OfficeNeedsFanLightsOn, OfficeNeedsFanLightsOff. Note the first one, OfficeOccupiedCondition, starts the timer OfficeOccupiedWithin10M, and each time the occupancy sensor is re-triggered (condition repeat = Yes), the timer is re-started. Hence the lights turn off 10 minutes after the last motion is detected (OfficeOccupancy; !OfficeOccupiedWithin10M).
If you sensors stay on until motion stops (have their own internal restart timer), unlike mine which keep sending motion, then you will need to adjust and likely start the timer after motion stops instead of when motion is detected. In that scenario the logic would be something like the motion detector is not tripped, and the timer stopped after the motion detector went untripped. Ex: !Motion and (!Motion;!Timer)
@2wilme2 The “Smart Switch” plug-in really doesn’t work in a bathroom setting. It’s a Motion detector not a Occupancy detector. Most think they are the same but according to California Title 24 they are totally different. Motion detectors turn on lights as well as turn them off after no motion is detected. Occupancy detectors do not turn lights on, they only turn them off with one exception, if motion is detected within 30 seconds after the lights go out it will turn them back on. Basically California Title 24 wants you to always manually turn on lights. They don’t seem to care about safety. I use Motion in the garage since the laundry is in there and we could be going in with ones hands full so the lights must turn on them selves.
I was looking at your PLEG sheet. I need to get used to the idea that you don’t need a new PLEG for different rooms. Just pile all of them into a single PLEG or as I think you do one PLEG per level. Basically for me that would be first floor, second floor and outdoor and maybe one other just for testing.
Which motion detector are you using that will send multiple triggers as it sees motion? Might as well start with on that I know will do that.
I’m still trying to figure out triggers when used in conditions, can they be used as both current status and edge triggered? I though I read they are edge, i.e., only trigger when going from off to on. If so then (L1 or L2 or L3) would trigger three times as each light came on. If level then once one of the three came on you would not get any more triggers. At least for now I’m just trying to make it work the way I want with a single light. When that works I’ll try getting multiple lights working.
Bottom line is that PLEG seems to have a steep learning curve. Until I get used to it this would be much easier to write in C ;D
I have a three story townhome, and use 9 PLEGS. Lighting on each floor is a separate PLEG. Although I have another for the bathrooms lights and fans on all three levels and another for the lighting on stairs between levels. Climate is just one PLEG for all three floors and is my largest. I have another specific to my window blinds and another for my hot water re-circulation pump. The reason I have so many has to do with z-wave delays - in my experience you an build a PLEG so large that you get frequent Vera deadlock restarts due to multiple z-wave commands queuing with that PLEG. Even with 9 PLEGs I have to add in some logic in a few places to prevent two actions from firing at once in a single PLEG. I am deadlock free, but it took a lot of work.
I am using Leviton LevNet with the EnOcean plug-in and I while I like them a lot, I don’t recommend them - they are not a mesh network and repeaters are hard to find unless you want to start using EnOcean wall switches instead of z-wave which I really don’t recommend.
Essentially you can build conditions that function either way - as remain true after the action is performed, or which incorporate the action into the condition and hence are only true while the action is being executed. (So if you add in the state of the light being turned on, once it is on, the condition is no longer true.)
I really don’t think so - the issue here is that the logic of how to automate something as seemingly simple as a light is often quite complicated. Once you get the logic down is it simple to load it into PLEG - with a C# or LUA, you have to build the logic AND the code…
Interesting layout. I’m not trying to get too complex but I’ll watch closely not go get them too large.
Still having a problem getting the timer to trigger. Apparently I have not correctly started the timer due to bad LUA code. Here is the code I have in the action for trigger the timer. I copied it from something I found here but looks like it’s not right. BET, if I manually start the timer the lights get turn off so that code works if I can get the timer to trigger.
[quote=“Timon, post:17, topic:189942”]Interesting layout. I’m not trying to get too complex but I’ll watch closely not go get them too large.
Still having a problem getting the timer to trigger. Apparently I have not correctly started the timer due to bad LUA code. Here is the code I have in the action for trigger the timer. I copied it from something I found here but looks like it’s not right. BET, if I manually start the timer the lights get turn off so that code works if I can get the timer to trigger.
Code in the LUUA section of the Action tab.
PLEG StartTimer timerName=stMrBathTimer[/quote]
You don’t use LUUA code or that section to start a timer.
You select a device (PLEG would be your device) and in there the options will be to start a timer from the drop down, then enter the “stMrBathTimer”
Best Home Automation shopping experience. Shop at Ezlo!