This project is continued from Part 2.
I rewrote most of the original porch light automation code for the ISY-99i, taking advantage of support for variables and adding new features. My ISY-99i home automation controller is running the latest firmware version 3.2.6 (as of this writing).
The new porch light automation features are:
- Turn on the porch lights for 10 minutes when the 2420M motion sensor is activated from 30 minutes before sunset to 20 minutes after sunrise.
- A forgiving double-click OFF routine to disable the motion sensor and keep the lights off for 2 hours.
The porch lights are flashed once for confirmation. I wrote this routine because I couldn’t get the ToggleLinc Relay to send a Fast Off event when double-clicking the ToggleLinc switch, no matter how hard I tried.
This scene is nice when I want to sit on the porch and enjoy the stars or create a night scene for Halloween, etc.
- Turning ON the ToggleLinc switch disables the 2 hour off routine, if active.
- Have the ISY-99i send and e-mail to me if the 2420M battery needs to be replaced.
The high level ISY-99i, ToggleLinc Relay and 2420M motion sensor events and programs are illustrated in this diagram:
ISY-99i Porch Light Automation Programs
The following software programs and source code are entered in the ISY-99i Administrative Console in the Programs → Details tab as shown:
Front Porch Light Program Folder
Create a folder to organize the ISY-99i programs for the 2420M motion sensor automation.
Folder Conditions for 'Front Porch Light' Add conditions to limit when programs in this folder are allowed to run. If - No Conditions - (To add one, press 'Schedule' or 'Condition') Then Allow the programs in this folder to run.
Program: Porch Motion Sensed
Processes 2420M motion sensor events from dusk to dawn and turns on the porch lights if the lights are off and motion is detected.
If From Sunset - 30 minutes To Sunrise + 20 minutes (next day) And Control 'Porch Motion Sensor-Sensor' is switched On And ( Status 'Front Porch Light Switch' is not On And Program 'Porch Light On 10 Minutes' is False ) Then Run Program 'Porch Light On 10 Minutes' (Then Path) Else - No Actions - (To add one, press 'Action') If the 2420M senses motion, and the ToggleLinc Relay is switched ON, and the porch light motion sensor program is not already activated, then turn on the porch lights for 10 mins.
Program: Porch Light On 10 Minutes
Turns the porch lights on for 10 minutes when the 2420M motion sensor detects activity. This program acts as a True/False flag via the Then/Else execution paths for other programs to determine if the porch lights are on because of a motion event trigger.
If - No Conditions - (To add one, press 'Schedule' or 'Condition') Then Set 'Front Porch Light Switch' On Wait 10 minutes Set 'Front Porch Light Switch' Off Run Program 'Porch Light On 10 Minutes' (Else Path) Else - No Actions - (To add one, press 'Action') Turns the porch light on for 10 minutes. A separate program is used here with no IF conditions such that the 'Wait' isn't reinitialized by new events triggering a reevaluation of IF conditions had they been present. This program also serves as a Flag (semaphore): * True (then path was run) when the porch lights are ON. * False (else path was last executed) when the porch lights are OFF.
Program: Count Double Off Clicks
The ToggleLinc Relay switch should send a Fast Off INSTEON command when the switch is double-clicked OFF, similar to double-clicking a mouse button. No matter how hard I tried, I could only get the ToggleLinc to send a Fast Off maybe 1 time in 50 double-clicks. I tried double-clicking the switch fast, medium and slow and rarely succeeded in generating a Fast Off event.
I therefore wrote a simulated double-click routine using an Integer variable $Porch_Click_Cnt with a generous 4 second window to detect two consecutive ToggleLinc Relay OFF switch events. INSTEON communications have a certain amount of communications latency, so if 4 seconds doesn’t work reliably for you, try 5 or even 6 seconds to detect two consecutive OFF clicks.
If - No Conditions - (To add one, press 'Schedule' or 'Condition') Then $Porch_Click_Cnt += 1 Wait 4 seconds $Porch_Click_Cnt = 0 Else - No Actions - (To add one, press 'Action') Increment the Porch_Click_Cnt variable for each consecutive ToggleLink Relay OFF click within 4 seconds. The click counter is reset to zero after 4 seconds. A dedicated program is used to set the $Porch_Click_Cnt variable to avoid having a programs IF conditions reevaluated when the program contains a WAIT instruction.
Program: Porch Light Double Click Off
This program detects ToggleLinc Relay OFF switch events and if a simulated double-click has occurred, runs the ‘Porch Light Off 2 Hours’ program.
Note: Clicks can’t be counted in the ‘Porch Light Double Click Off’ program because changing the $Porch_Click_Cnt variable here would force a reevaluation of the ‘Porch Light Double Click Off’ IF condition, the click count would never exceed 1 and the else clause will never execute. This an oddity of the ISY-99i programming environment. The solution is to count clicks in the sub-program ‘Count Double Off Clicks’.
If Control 'Front Porch Light Switch' is switched Off And $Porch_Click_Cnt < 2 Then Run Program 'Count Double Off Clicks' (Then Path) Else Run Program 'Porch Light Off 2 Hours' (Then Path) If the ToggleLinc Relay is clicked OFF at least twice within 4 seconds, then the porch lights will be forced off for 2 hours by disabling the 2420M motion sensor program.
Program: Porch Light Off 2 Hours
When the ToggleLinc Relay switch is clicked OFF at least twice within 4 seconds, a simulated “double-click” is detected, the porch light is flashed once to confirm the command, and the porch motion sensor program is disabled for 2 hours to keep the lights off.
If - No Conditions - (To add one, press 'Schedule' or 'Condition') Then $Porch_Click_Cnt = 0 Stop program 'Porch Motion Sensed' Disable Program 'Porch Motion Sensed' Set Scene 'Front Porch Lights' On Wait 1 second Set Scene 'Front Porch Lights' Off Wait 2 hours Enable Program 'Porch Motion Sensed' Run Program 'Porch Motion Sensed' (Else Path) Else - No Actions - (To add one, press 'Action') Turns off the porch lights and disables the motion sensor program for 2 hours, and resets the motion sensor flag to 0 (False) in case the motion sensor program is aborted and unable to reset the flag. The porch lights are flashed ON for 1 second to indicate a double click confirmation.
Program: Porch Light Switched On Cancel 2 Hr Override
Disables the 2 Hour Off program if active and resets the 2420M motion event program when the ToggleLinc Relay is switched ON.
If Control 'Front Porch Light Switch' is switched On And Program 'Porch Light Off 2 Hours' is True Then Stop program 'Porch Light Off 2 Hours' Run Program 'Porch Light Off 2 Hours' (Else Path) Enable Program 'Porch Motion Sensed' Run Program 'Porch Motion Sensed' (Else Path) Else - No Actions - (To add one, press 'Action') When the porch light is manually switch on, stop the 1 hour Fast Off and 10 min motion sensor light programs should they be running, and reset the motion sensor status flag to false (else path). The 'Porch Motion Sensed' program is enabled as it could have been disabled by the 2 Hour OFF program.
Program: Porch Light Daily Reset
This is a housekeeping routine to turn off the lights at dawn and reset the program flags and variables.
If Time is Sunrise + 15 minutes Then Set 'Front Porch Light Switch' Off Enable Program 'Porch Motion Sensed' Run Program 'Porch Motion Sensed' (Else Path) $Porch_Click_Cnt = 0 Enable Program 'Porch Light Off 2 Hours' Run Program 'Porch Light Off 2 Hours' (Else Path) Else - No Actions - (To add one, press 'Action') Turns the porch lights off 15 minutes after dawn and resets the program flags in case the lights were manually overridden and left on all night.
Program: Porch Motion Sensor Low Battery
Have the ISY-99i send a low battery notification e-mail to me once every 24 hours so I’ll know to replace the 2420M motion sensor battery.
If Status 'Porch Motion Sensor-Low Bat' is On Then Repeat Every 24 hours Send Notification to 'BobJackson' content 'FrontPorchMotionLowBattery' Else - No Actions - (To add one, press 'Action') Send an e-mail to myself once every 24 hours when the front porch motion sensor battery needs replacing. The e-mail account and low battery message are setup in the ISY-99i Administrative Console 'Configuration' menu tab.
If you prefer different durations for turning the lights on or off, simply change the WAIT period parameter in the ‘Porch Light On 10 Minutes’ and ‘Porch Light Off 2 Hours’ programs.
ISY-99i Programming Test and Debug
The status of the programs and variables can be viewed and managed through the ISY-99i Administrative Console in the Programs → Summary and Programs → Variables tabs.
For example, the $Porch_Click_Cnt integer variable can be viewed in real time as the ToggleLinc Relay switch is clicked OFF. When the $Porch_Click_Cnt reaches 2, the ‘Porch Light Off 2 Hours’ program will execute and turn on the ToggleLinc Relay for 1 second to flash the porch lights for visual confirmation the double-click OFF was confirmed. The “System Busy” message pops up as the porch ToggleLinc Relay is turned ON under program control.
Clicking on the Programs → Summary tab, the ‘Porch Light Off 2 Hours’ is now Running as the WAIT command counts down.
Universal Devices ISY-99i/994i iPhone Web Interface
The porch lights can also be controlled with the FREE remote web management interface on the Universal Devices ISY-99i and ISY-994i home automation controller. I’ve setup my ISY-99i for remote access via my local WiFi LAN and any where in the world via my Internet WAN connection with a DDNS service. This is what the ISY-99i remote management interface looks like on my iPhone 4 using the Atomic Web Browser. The GUI will scroll with a finger swipe to show all of your devices, scenes and programs. I like the Atomic Web Browser much better than Safari because it supports full screen mode, tabbed browsing and will save your login information.
Hope this helps,
Copyright © 2016 HandymanHowTo.com Reproduction strictly prohibited.