TechGuy Posted November 2, 2010 Posted November 2, 2010 I've been reading some of the programming examples, but I'm not sure I've found the best solution for my situation. I've got one light I'd like to control with two motions sensors. I'd like it to activate only at night (easy to do based on sunrise/sunset). When either motion sensor triggers, I'd like the lights to turn on. When no sensor has seen motion for 5 minutes, I'd like the lights to turn off. If I set it up as a simple rule with If Sensor1 OR Sensor2 it would work, but I think it would then turn off the lights 5 minutes after the first sensor detecting motion... I hope that makes sense!
ergodic Posted November 2, 2010 Posted November 2, 2010 You're right, you can't do this with a single program. Try writing a separate program to track the state of each motion sensor. Then a third program to use that state to control the light's on/off status. So perhaps something like this (I'm inferring from your post the sensors aren't sending explicit off signals.) Program M1On If Control M1 is switched on Wait 5 minutes Run Program M1On (Else) Program M2On If Control M2 is switched on Wait 5 minutes Run Program M2On (Else) Program ControlTheLight If (Program M1On is True) or (Program M2On is True) Turn the light on Else Turn the light off M1On and M2On simply track the state of their respective motion sensor, going false (else) 5 minutes after being triggered on/true. ControlTheLight uses that program state (not the sensor triggers themselves) to manage the light. You'll also need to incorporate a little ISY bootup-time initialization to set the programs' state initially and make sure the light doesn't trigger when the ISY boots. While this is simple, the one problem with this kind of design is that you will be sending Insteon commands down the wire every time a motion sensor or timer triggers, and some of those will be redundant (ie turning the light on when it is already on). You can add more hair (programs) to track the state of the light and get around this. But with 5 minute timers and simple on/off I personally wouldn't worry about it. (If your motion sensors constantly chatter "on" commands like the X10s then that could be a different matter.)
oberkc Posted November 2, 2010 Posted November 2, 2010 There are a couple of things to note about your desired program. 1) I understand insteon sensors will send an on signal each time they sense motion, but that there is a reset time period, within which they will not. 2) If a program conditions are evaluated while the program is running (in a wait, for example), then the program will cease running and start again, based upon the evaluated condition (true or false). Regarding note 2 for example, a program can watch for motion and, if detected, turns a light on, waits five minutes, and turns a light off. If, during that five minute wait, further motion is detected, the five minute wait will be terminated and the program will start again from the beginning. This is also true for time constraints (dusk-to-dawn, for example). If you set up a program to run only from dusk-to-dawn, and the program is executing at dawn, execution will stop. It is for reasons such as this that it is sometimes useful to break out single programs into multiple programs. Ergodic's response is one of several ways to solve your problem. You would, of course, have to incorporate your time constraints. Another option (the one that I use) would be: Create a program folder with conditions: if from sunset to sunrise then run the programs in this folder in the folder create a program: if control "motion1" is set on or control "motion2" is set on then run timer program (then path) else outside the folder, create a "timer" pogram if then turn light on wait five minutes turn light off else The program folder will restrict the fist program from running after sunrise and before sunset. The second program will call the timer program (restarting the timer program if already executing) each and every time either of the two motion sensors sends a signal in response to motion. The timer program will incorporate the wait state and continue to run, even if sunrise occurs during the five-minute wait period.
TechGuy Posted November 2, 2010 Author Posted November 2, 2010 Wow, thanks for the quick replies, guys! I'm a little confused, though, but maybe that just means I need to do some testing tonight... oberkc: I understand the concept of using folders to add limitations, but I'm not sure why you have a separate "timer" program. Why couldn't this be part of the program in the folder? If a program conditions are evaluated while the program is running (in a wait, for example), then the program will cease running and start again, based upon the evaluated condition (true or false) If I'm reading that correctly, it seems to me that a simple (single) program will do what I want... other than the fact that it would turn off immediately at sunrise rather than waiting up to 5 minutes after motion. Is that right? For example: Program FrontMotion If Control M1 is switched on OR Control M2 is switched on Turn FrontLight On Wait 5 Minutes Turn FrontLight Off So, if I understand correctly, if M1 sees motion and then turns on the light and then M2 sees motion during the 5 minute wait, it will reset the program and thus the timer? (With the disadvantage of sending unnecessary On signals...) If that's the case, could I do: Program FrontMotion If (Control M1 is switched on OR Control M2 is switched on) AND (FrontLight is Off) AND (Dusk til Dawn) Turn FrontLight On Wait 5 Minutes Turn FrontLight Off And that would take care of everything? (Also, I'm not sure if I can do AND/ORs in that sort of combination.)
oberkc Posted November 2, 2010 Posted November 2, 2010 Why couldn't this be part of the program in the folder? For one, simple, reason....if it is part of the program in the folder, there is risk (perhaps small) that the program is in a wait state when the folder condition turns false at sunrise. If so, the program execution ceases and the light will never go off. So, if I understand correctly, if M1 sees motion and then turns on the light and then M2 sees motion during the 5 minute wait, it will reset the program and thus the timer? That is my understanding and experience.
Goose66 Posted November 2, 2010 Posted November 2, 2010 TechGuy, You are right. This seems most practical to implement as a single program. The second of your programs is the way I would implement it, and should work just fine, except for one catch: If the program is running, and sunrise occurs, then it will stop running, and you may miss the off. In other words, if motion triggers the light less than 5 minutes before sunrise, then the program will turn the light on. However, because you cannot differentiate between IF conditions and triggering events in the ISY programming model (a serious limitation, IMO), the program will be triggered again at sunrise, cancelling the current running program (which is waiting for 5 minutes to send the off) and executing the ELSE portion of your program. So you can do the three programs and folder conditions that oberk suggested, or simply have one additional program that cleans up your outdoor lighting at sunrise. Because this situation arises a lot in my outdoor lighting programs, I have one program that turns off all outside lighting at sunrise to account for this "boundary condition."
TechGuy Posted November 2, 2010 Author Posted November 2, 2010 I'll do some testing tonight. Thanks so much guys! I'm sure I'll be back with more questions soon.
ingeborgdot Posted November 5, 2010 Posted November 5, 2010 I just posted the same thing on my topic. I have the same question but I am clueless compared to you guys. I am so jealous that you guys know how to do this with as much ease as you do. I have one light with 2 sensors that I need to use to make it work right.
Sub-Routine Posted November 5, 2010 Posted November 5, 2010 Turning the lights on can be done with a single program: If Control 'Motion Sensor 1' is switched On Or Control 'Motion Sensor 2' is switched On Then Set Scene 'Motion' On Else - No Actions - (To add one, press 'Action') Turning the lights Off will require a program for each motion sensor: If ( Control 'Motion Sensor 1' is switched Off And Status 'Motion Sensor 2' is Off ) And Control 'Motion Sensor 1' is not switched On And Control 'Motion Sensor 2' is not switched On Then Wait 5 minutes Set Scene ' Motion' Off Else - No Actions - (To add one, press 'Action') If ( Control 'Motion Sensor 2' is switched Off And Status 'Motion Sensor 1' is Off ) And Control 'Motion Sensor 1' is not switched On And Control 'Motion Sensor 2' is not switched On Then Wait 5 minutes Set Scene ' Motion' Off Else - No Actions - (To add one, press 'Action')
ingeborgdot Posted November 5, 2010 Posted November 5, 2010 Hey Rand, how are you? Is this the way that you would do it? I don't care how many programs it takes to make it work right.
Goose66 Posted November 5, 2010 Posted November 5, 2010 Why would you need a seperate program to turn the light off? You want to turn it off 5 minutes after the last motion (the last "switched on"), right, regardless of what motion detector sent it? Rand's three programs allows the light to be turned off after the last Off is received from one of the motion detectors. This really doesn't make any sense, in that it would depend on the respective settings of the motion sensors and then add five minutes to it for the off. Simply jumper the motion sensors to send Ons only and set the pot for the timing all the way counter-clockwise. The motion sensors will send Ons every 30 seconds while motion is detected. With the single program suggested above, the light will turn On on first motion from either sensor, and then will turn off 5 minutes after last motion is detected by either detector.
oberkc Posted November 5, 2010 Posted November 5, 2010 You want to turn it off 5 minutes after the last motion (the last "switched on"), right, regardless of what motion detector sent it? I suggest that this is a case of understanding what one wants to do. It appears to me that Sub-routine's program would turn the lights off 5 minutes after the motion sensor sends and off command (and the other motion sensor is off). That constitues 5 minutes, plus whatever time is set on each of the motion sensors before an off command is sent. These are variations on the same theme. Both approaches will work. Both probably have merit. The important thing (in my mind) is to understand what it is you are trying to do. Unfortunately, this was in response to a request to make it "work right". We don't know if five minutes is the correct time, or five minutes plus motion sensor time, five minutes after motion sensor sends an off command, or whatever. Both will work. There are subtle differences in performance. Both require a specific configuration set up in your motion sensor.
ergodic Posted November 5, 2010 Posted November 5, 2010 There are kind of three general ways to deal with motion sensors in the ISY. You can create a scene and simply let the scene and the motion sensor programming control things going on and off. This is the pure-Insteon, non-ISY-program approach. The ISY is just used to create and manage the scene, but it will work even with the ISY turned off. The flexibility here is limited to whatever Insteon devices permit you to do. You can still write ancillary ISY programs to respond to the MS on/off commands in other ways if, for example, you want to send yourself an email or whatever. Second, you can set the MS to on-only and still link the scene, then let the ISY programs control the off side of your logic. The advantage is that you get the instant-on scene response, while still retaining a lot of program control. You also don't have to worry about setting or changing the off timer setting in the MS itself. The downside is that you usually have to write extra program hair to deal with getting "on" commands while your programs are waiting/running. The third way is to just write programs to handle both the on (and perhaps off) MS commands, and not bother with scenes at all. I've generally come to this place, mainly because I get tired of having to round up, open, and set motion sensors into link mode every time I need to adjust the scene or reprogram any device involved in the scene. The small program response delay is barely noticeable and in most cases not an issue. The extra flexibility is worth it to me.
ergodic Posted November 5, 2010 Posted November 5, 2010 ingeborgdot: I'm responding to your PM to me here in the public thread. The logic I posted above on 11/1 is what I'd personally use for the pure ISY program approach, only because it is easiest to understand and easiest to change (for me). YMMV and the other approaches are all perfectly fine. In the end pick whatever style makes the most sense to you. If you want to add the time-of-day to the logic you can do that in the program conditions, in the motion sensor dusk-dawn setting, as a separate enable/disable program, or as a folder condition on M1On/M2On. I prefer to just use programs for everything so I've added the 'enable/disable' approach here. Program M1On If Control M1 is switched on Wait 5 minutes Run Program M1On (Else) Program M2On If Control M2 is switched on Wait 5 minutes Run Program M2On (Else) Program ControlTheLight If (Program M1On is True) or (Program M2On is True) Turn the light on Else Turn the light off Program OnlyAtNight If time is between x and y (next day) disable program ControlTheLight run program ControlTheLight (else) run program M1On (else) run program M2On (else) enable program ControlTheLight Else disable program ControlTheLight run program ControlTheLight (else) run program M1On (else) run program M2On (else) Set OnlyAtNight to run at ISY boot to initialize. If you have the option of a coarse 'on' timing and disabling 'off' in your MSen then I'd recommend it as it will reduce network traffic here.
Goose66 Posted November 5, 2010 Posted November 5, 2010 One of the things to think about in picking an approach is the quirks in the event-driven programming model of the ISY (yes, the inability to differentiate between trigger events and IF conditions being an imporant one). Your programs need to be clear so you can figure out what you were trying to do six months from now when something starts misbehaving. For me, clarity comes from simplicity; that is why I favor the single program approach with all the conditions for triggering the program and appropriate responses right there in one place. The politically correct thing would be to say each approach has merits, but my aversion to political correctness (and the anonymity of this forum) oblige me to point out that the approach provided above, while I understand how it works, is anything but clear or simple. Further, doesn't the multi-layering of the programs exacerbate the slower response of the ISY program approach to motion sensors over Insteon linking?
ergodic Posted November 5, 2010 Posted November 5, 2010 I have not found internal program delays to be noticeable or even discernable. The delay seems to be the initial response of the ISY program system to the Insteon commands. Perhaps Chris or Michel can illuminate the question better.
Michel Kohanim Posted November 7, 2010 Posted November 7, 2010 Hello ergodic/kingwr, There should not be any discernable performance hit having multiple programs instead of one. ISY knows which programs should be evaluated before hand and thus having two or more programs instead of one will not make a difference in performance. With kind regards, Michel
ingeborgdot Posted November 7, 2010 Posted November 7, 2010 The problem I am having right now is that it turns on even in the daytime and it does not turn off for some reason.
oberkc Posted November 7, 2010 Posted November 7, 2010 The problem I am having right now is that it turns on even in the daytime and it does not turn off for some reason I suggest posting a copy of your program(s). Perhaps someone can spot why this is so.
jrainey Posted November 7, 2010 Posted November 7, 2010 Hello everyone, I am really new with this system (5 days), and have been following this thread with great interest. I would like to suggest a strategy to handle this particular problem. If there are any errors, or if the approach will not work, please let me know. At this point in time, my understanding of how the system and all of its components is limited, and I am in learning mode big time. First step - set the time outs on both MS's to 5 minutes. As I understand the devices, once triggered and an on is sent, the timer is reset with every motion detected. An off signal will only be sent if there has been no motion for the timeout period (five minutes in this case). Second step - write a program to turn the light on and off as desired: If Status 'MS1-Sensor' Is On Or Status 'MS2-Sensor' is On Then Set 'Backyard Light' On Else Set 'Backyard Light' Off If I am reading the event processing comments correctly, when either of these sensors comes on, an event will be produced that runs the then portion of the statement. Once either or both of them is on, and event will be produced when the last of the two turns off (5 minutes after the last motion in this case), which will turn off the light. At present, I only have one motion sensor, so couldn't test with two sensors. I substituted the status of one of my few lights, and it worled as planned. Third step - Write a program to handle the Sunset/Sunrise aspect. If From Sunset To Sunrise Then Enable Program BackyardMotion Else Disable Program BackyardMotion Assuming that the above program is named BackyardMotion. I would suggest that the SunsetSunrise program be used as the standard program for setting up standard day and night scenarios, with the backyard setup being just one entry. Hope this helps. Jack Rainey PS - Can someone please tell me how I can put the code into those nice looking inserts that everyone else is using - I put the indents in, but they disappear in the preview and the post.
oberkc Posted November 7, 2010 Posted November 7, 2010 If there are any errors, or if the approach will not work, please let me know. I am concerned that your approach will suffer the same problem with the so-called "boundary conditions". If your sunset/sunrise program disables your motion program (for example, when it turns to dawn) while the lights are on (in the five-minute period), then the lights will not turn off. Can someone please tell me how I can put the code into those nice looking inserts that everyone else is using - I put the indents in, but they disappear in the preview and the post. First, you cannot use the quick reply. In the full reply, select the text that you want listed as code, then select the "code" button in the reply window.
jrainey Posted November 7, 2010 Posted November 7, 2010 Thanks Oberkc You are correct. An oversight on my part. In the SunsetSunrise program an additional line needs to be added to the then and else to turn off the light. If From Sunset To Sunrise Then Set 'Backyard Light' Off Enable Program BackyardMotion Else Set 'Backyard Light' Off Disable Program BackyardMotion Assuming that you want the light off during the day, and assuming that you want to turn it off at the beginning of the eventing if someone inadvertently turned it on. The order of execution might have to be reversed... i.e the set off might have to be executed after the program is disabled or enabled - would have to test it to make sure. Thanks for the hint on the formatting - didn't notice that stuff up there Jack Rainey
oberkc Posted November 8, 2010 Posted November 8, 2010 Assuming that you want the light off during the day, and assuming that you want to turn it off at the beginning of the eventing if someone inadvertently turned it on. it seems to me that this would work. There are so many examples of how to do motion sensors. I think there is a pretty good explanation also in the wiki. Perhaps you want to consider coming up with a way to avoid having to make the assumptions above. What if you don't always want the light off during the day? What if you don't necessarily want it to turn off at sunset? What if you want to maintain manual control of a light, but motion sensor control when manual activation hasn't occurred? (These are all rhetorical questions unless you want to try to tackle this.) There are so many variations and it can all be done if you want to take the time to program it.
jrainey Posted November 8, 2010 Posted November 8, 2010 You are correct again Oberkc, but how it is to be programmed really depends on what you want to do. In the example suggested, manual control during the day is fully available if the light is activated by a switch. No change is required if you want to swtich it on and off at will. Remove the set to off line, and it will remain in whatever state it was set to when sunrise occurs. Between sunset and sunrise is a different story. Any action taken with the switch would be over written by the motion sensor program. The easiest way to address this (to my mind) would be to provide an easy method to enable or disable the MS program. An example: ManualEnableBackyardMS If Status 'Backyard Light' is Fast On Then Enable Program BackyardMotion Else Do nothing And it's partner: ManualDisableBackyardMS If Status 'Backyard Light' is Fast Off Then Disable Program BackyardMotion Else Do nothing Both of these programs would be enabled and disabled with the SunsetSunrise routine along with the BackyardMotion program. If then, during the evening, you want to go out in the backyard with your telescope, or just enjoy the stars with your significant other, and not be annoyed by the back yard light going on and off, you would hit the appropriate off switch twice, and you are ready to go. When you are done, you can hit the on switch twice and the MS is back in business. (You could also program this into a bedtime routine that you trigger every night just before you go to bed, along with whatever else you want to set up before getting some shuteye). As you said, there are many variations. As I am getting more into the capabilities of this system, I am getting more impressed, and more excited about the possibilities. I am aware of the point limitations, but I am curious about the programming limits. Can I tell how much memory a given program will use, and how much programming memory remains available? What is the per scan execution time? Can this be monitored? Looks like a load of interesting work coming up. Jack Rainey
Sub-Routine Posted November 8, 2010 Posted November 8, 2010 Hello jrainey, You do not have to worry about RAM a program uses. There is a firmware imposed limitation of 300 programs on the standard ISY and 1000 programs on the Pro upgrade. The most time consumptive limitation is the Insteon signals which usually take ~.25 seconds. You can check the Free RAM using Tools | Diagnostics | File System Status For more information concerning the processor and RAM please see our FAQs: ISY-99i/ISY-26_INSTEON:Frequently_Asked_Questions#Specifications Rand
Recommended Posts