Mustang65 Posted September 30, 2019 Posted September 30, 2019 I have a bunch of 2844-222 Motion Sensors. I have one just outside pointing toward one of my back doors. Installed the Motion Sensor and ISY sees it. All good so far. I decided to write some basic code to test the sensor. The below code works perfectly, but only works if I enter the "Set 'Lights - CarPort' Off" in the Else section of the code. When I had the line of code following the "Wait 15 Seconds" (If section) the light comes on when there is motion, but does not shut off. The 15 seconds, was tried with 1 minute and 2 minutes with the same results. I have no problem leaving the code this way, but just trying to understand why there is an issue with having that line of code in the "Then" section? Works the same way with or without the Sunset/Sunrise code. Your thoughts, CarPort Light - [ID 000D][Parent 0001] If 'MotionSensor - CarPort-Sensor' Status is On And From Sunset To Sunrise (next day) Then Set 'Lights - CarPort' On Wait 15 seconds Else Set 'Lights - CarPort' Off
Mustang65 Posted September 30, 2019 Author Posted September 30, 2019 I know there is a 30 second timer where the motion sensor status = "On", and I timed it watching the status change to "Off" before the code of 1 or 2 minutes passed.
dbuss Posted September 30, 2019 Posted September 30, 2019 Here are some programs I use with Motion Sensor. Bathroom Hallway Lights Night - [ID 0013][Parent 0001] If From 10:01:00PM To 6:00:00AM (next day) And 'Hallway MS-Sensor' Status is On Then Set 'Bathroom Light' On 30% Set 'Hallway Light' On 30% Wait 10 minutes Set 'Bathroom Light' Off Set 'Hallway Light' Off Else - No Actions - (To add one, press 'Action') Bathroom Lights On Day-Evening - [ID 0012][Parent 0001] If From 6:00:00AM To 10:00:00PM (same day) And 'Hallway MS-Sensor' Status is On Then Set 'Bathroom Light' On Else - No Actions - (To add one, press 'Action') Front Porch Light On - [ID 0025][Parent 0001] If From Sunset + 5 seconds To Sunrise + 5 seconds (next day) And 'Front Door MS-Sensor' is switched On Then Set 'Front Porch Light' On Wait 10 minutes Set 'Front Porch Light' Off Else - No Actions - (To add one, press 'Action') 1
kclenden Posted October 1, 2019 Posted October 1, 2019 (edited) 16 hours ago, Mustang65 said: I have no problem leaving the code this way, but just trying to understand why there is an issue with having that line of code in the "Then" section? When the ISY executes a WAIT, it does two things. First it starts counting down the time you specify and second it watches the conditions in the IF statement to see if any of them change. If its time countdown reaches 0 before any of the conditions in the IF change, then the ISY executes the statements following the WAIT. But if one of the conditions in the IF changes before the countdown reaches 0, then the ISY stops executing the code in the THEN and reevaluates the IF and based on the results of that reevaluation either executes the THEN from its first line or the ELSE from its first line. So when your WAIT was set to 1 minute or 2 minutes, the 'MotionSensor - CarPort-Sensor' Status is On condition changed before the countdown completed and the ISY quit executing the code in the THEN and reevaluated the IF which then caused it to execute the ELSE. When the ELSE was blank nothing happened and thus the light stayed on. Once you added the OFF statement to the ELSE, it's execution resulted in the light going OFF. I don't know why the 15 second WAIT doesn't work if the internal timer of the Motion Sensor is actually set to 30 seconds. If you change the condition in your IF from 'MotionSensor - CarPort-Sensor' Status is On to 'MotionSensor - CarPort-Sensor' is Switched On then it won't matter how the internal timer of the Motion Sensor is set. The reason for this that Status can be either ON or OFF and thus when it changes from one to the other the WAIT will be interrupted and the IF will be reevaluated. But Switched On is a discrete event totally separate from Switched Off. So when the Motion Sensor changes from ON to OFF and triggers a Switched Off event, your Switched On condition of your IF doesn't change which means your WAIT countdown won't be interrupted and will ultimately reach 0 and execute the lines that follow it. Edited October 1, 2019 by kclenden 1
Mustang65 Posted October 1, 2019 Author Posted October 1, 2019 Thanks, GREAT explanation, will give it a try
larryllix Posted October 1, 2019 Posted October 1, 2019 Careful....CarPort-Sensor' is Switched On never runs Else so your Off command must be in your Then section. Most users disable the MS Off signal to save batteries. 1
Recommended Posts