Let's start with the script! Open up the Script Editor, paste the code below and save it to the Indigo / Scripts / Attachments folder (I saved it as createDelay.scpt but it doesn't make a difference what it is called).
- Code: Select all
on CreateDelay(DelayName, DelayTime, TargetItem, TargetAction)
tell application "IndigoServer"
set DelayTime to ((current date) + (60 * DelayTime))
if not (time date action DelayName exists) then
make new time date action with properties {name:DelayName, time trigger type:absolute, date trigger type:absolute, absolute trigger time:DelayTime, enabled:true, auto delete:true}
tell first action step of time date action DelayName
if (TargetAction is not "On" and TargetAction is not "Off") then
set action type to executeScript
set script code to TargetItem
else
set action type to controlLightOrAppliance
set device name to TargetItem
if (TargetAction is "On") then
set device action to turnOn
else
set device action to turnOff
end if
end if
end tell
else
set absolute trigger time of time date action DelayName to DelayTime
end if
end tell
end CreateDelay
Now reload the Attachments Scripts - You are done with the hard stuff. Now let's put this script to work!
INSTEON MOTION SENSOR
The issue that has been brought up time and time again is how the motion sensor doesn't send out ON events after the first time the sensor is activated and if motion is detected. In other words, if you have the sensor in a high traffic room (Say the kitchen and a person is in it for hours cooking) Indigo would only receive one (1) ON event from that sensor over the given period.
Scenario 1 - Want lights to come on when motion is detected in the Pantry but not off until X Time passes. Because normally someone doesn't spend a bunch of time in the pantry, there will not be continuous motion detected. While Indigo can handle this, so can this script. Follow these steps:
1. Set the Insteon Motion Sensor to ON ONLY.
2. Link the Insteon Motion Sensor to the Pantry switch.
3. Create a Indigo Trigger to watch for an ON event from the Insteon Motion Sensor in question. In the Actions tab use type Execute Applescript with the following code
- Code: Select all
CreateDelay("_delayed_action_PantryLightOff", 10, "Kitchen - Pantry Light", "Off")
Your done. Now every time motion is detected, your light will go on immediatly and out 10 minutes later. With that said, if you walk back in 3 minutes later the timer will reset (This is based on the 1 minute default set within the Insteon Motion Sensor).
Now let's look at this code to see what it is doing.
"_delayed_action_PantryLightOff" - This is the name of the delay
"9" - This is the number of minutes from the trigger that you want X to occur
"Kitchen - Pantry Light" - This is the name of the device you want to control
"Off" - What cation you want done (On, Off, and Script are valid)
NOTE: If you use Script then replace the Device with the Applescript you want executed. This is nice for executing group / scene commands.
Scenario 2 - Want to have the lights turn off after x amount of time in a room but only if NO motion is detected after X minutes and NOT turn on the lights. This is were the Insteon Motion Sensor fails in most of the posts I have seen. This situation would be used in a hall bathroom let's say. You don't want the lights turning on by themselves but you want them to turn off.
1. Set the Insteon Motion Sensor to normal ON / OFF operation
2. Do not link the Insteon Motion Sensor to any switches.
3. Create a Indigo Trigger to look for an OFF event from that motion sensor. In the Actions tab use type Execute Applescript with the following code
- Code: Select all
CreateDelay("_delayed_action_HallBathroomLightOff", 9, "HallBath - Light", "Off")
Since the default of the Insteon Motion Sensor is set to 1 minute of inactivity before sending an OFF command this will give you 10 minutes of light.
4. Create a Indigo Trigger to look for an ON event from that motion sensor. In the Actions tab use type Execute Applescript with the following code:
- Code: Select all
if (time date action "_delayed_action_HallBathroomLightOff" exists) then
delete time date action "_delayed_action_HallBathroomLightOff"
end if
Now if a ON event is detected it will remove the previous delay and will wait for the OFF command before adding another delay. Now if someone walks in 5 minutes after the last person left the room the timer will reset and basically the light will remain on for another 10 minutes.
3-WAY SWITCH AUTO OFF
This issues stems from the way Auto Offs are named / handled within Indigo. If you create a trigger that watches for an ON event from the "Kitchen - Light" and "Kitchen - Light (3 Way)" switches both with 20 minutes delays to turn off the light "Kitchen - Light". If you press the ON "Kitchen - Light" switch button and then a few minutes later you press the ON "Kitchen - Light (3 Way)" switch button you end up with two (2) different delayed actions within indigo. Wouldn't it be nice to just have one so that both switches update the same delayed action? Here's how to do it:
1. Create a Indigo Trigger to look for an ON event from the "Kitchen - Light" switch. In the Actions tab use type Execute Applescript with the following code:
- Code: Select all
CreateDelay("_delayed_action_KitchenLightOff", 30, "Kitchen - Light", "Off")
CreateDelay("_delayed_action_KitchenLightSwitchOff", 30, "Kitchen - Light (3 Way)", "Off")
2. Create a Indigo Trigger to look for an ON event from the "Kitchen - Light (3 Way)" switch. In the Actions tab use type Execute Applescript with the following code:
- Code: Select all
CreateDelay("_delayed_action_KitchenLightOff", 30, "Kitchen - Light", "Off")
CreateDelay("_delayed_action_KitchenLightSwitchOff", 30, "Kitchen - Light (3 Way)", "Off")
You're done! Now either switch will reset the time an the lights will stay on for another 30 minutes.
EXAMPLE OF USING SCRIPTING
Just in case you wanted an example of how to use the CreateDelay Function above with AppleScript here it is:
- Code: Select all
CreateDelay("_delayed_action_ChristmasLightsOff", 10, "send insteon group instnTurnOff using index 21", "Script")
I'm sure I miss typed something above but these scenarios are just examples of how you can use the script. Let me know if you have any questions