`import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.model.script.actions.Timer //for the taking of input from the sitemap
import java.util.Date
import java.text.SimpleDateFormat
import org.joda.time.*
var Number Dusk = 18 //This is the hour after which lights should turn on when you walk in, 18 = 6:00 PM
var Number Dawn = 4 //This is when to stop turning on lights based on doors, not really dawn but after this time doors would only be for people leaving early so no need to turn lights on.
var autoOff = 1
//autoOff = (SirenWarningTime.state as DecimalType).intValue
//setup the siren
rule "Siren Configuration Initialization"
when
System started
then
postUpdate(SirenWarningTime, 5)
end
//sound the alarm after the wait period
rule "Alarm 2"
when
Item BackDoor changed
then
logInfo(“STDOUT”, “A door was just opened or closed.” )
if(DoorArmed.state == ON)
{
logInfo(“STDOUT”, “Door is armed, about to get the time delay from SirenWarningTime item.” )
autoOff = (SirenWarningTime.state as DecimalType).intValue
logInfo(“STDOUT”, “Siren time to wait " + autoOff + " seconds.” )
SirenTimer = createTimer(now.plusSeconds(autoOff)) [|
if(DoorArmed.state == ON){
logInfo(“STDOUT”, “The timer is up and the door is armed.” )
sendCommand(Siren, ON)
logInfo(“STDOUT”, “Clear the SirenTimer variable” )
SirenTimer = null}
else{
sendCommand(Siren, OFF)
logInfo(“STDOUT”, “Timer ran out but the door is no longer armed.” )}
]}
else{logInfo(“STDOUT”, “The alarm was not armed.” )}
end
rule "Alarm Off"
when
Item DoorArmed changed
then
if(DoorArmed.state == OFF){
sendCommand(Siren, OFF)}
end
//test any door changes option
rule "Doors have changed"
when
Item Doors changed
then
logInfo(“STDOUT”, “A door has in fact changed”)
end
//Vacation Mode Rules
rule "Not Home"
when
Time cron "0 33 21 * * ?"
then
if(VacationMode.state == ON){
sendCommand(LivingroomDimmer, 100)
logInfo( “file”, “Vacation mode, turning on the living room lights”)
}
else
logInfo( “file”, “Vacation mode not active”)
end
rule "Not Home 2"
when
Time cron "0 35 21 * * ?"
then
if(VacationMode.state == ON){
sendCommand(LivingroomDimmer, OFF)
logInfo( “file”, “Vacation mode, turning off the living room lights”)
}
else
logInfo( “file”, “Vacation mode not active”)
end
//end Vacation Mode Rules
//end new stuff
//end new stuff
/* This rule removed for troubleshooting
rule "MyTimeSTamp"
when
Item BackDoor changed
then
var SimpleDateFormat df = new SimpleDateFormat( “YYYY-MM-dd HH:mm:ss” )
var String Timestamp = df.format( new Date() )
logInfo( “File”, Timestamp )
end
*/
rule "Walk In Lights - Garage Door"
when
Item GarageDoor changed
then
if(GarageDoor.state == OPEN) {
logInfo( “file”, “door open, is it after dusk?”)
if(now.getHourOfDay >= Dusk) {
sendCommand(KitchenDimmer, ON);}
else {
logInfo( “file”, “door open, is it before dawn?”)
if(now.getHourOfDay <= Dawn){
sendCommand(KitchenDimmer, ON);}
}
}
end
rule "Walk In Lights - Front Door"
when
Item FrontDoor changed
then
if(FrontDoor.state == OPEN) {
logInfo( “file”, “door open, is it after dusk?”)
if(now.getHourOfDay >= Dusk) {
sendCommand(LivingroomDimmer, ON);}
else {
logInfo( “file”, “door open, is it before dawn?”)
if(now.getHourOfDay <= Dawn){
sendCommand(LivingroomDimmer, ON);}
}
}
end
/**This rule is for the alarm siren to go off when it is armed and the door is open
rule "Alarm"
when
Item BackDoor changed
then
if(DoorArmed.state == ON && BackDoor.state == OPEN)
sendCommand(Siren, ON)
if(BackDoor.state == CLOSED)
sendCommand(Siren, OFF)
end
*/
//2 rules to dim the boys lights at a given time
rule "Bedtime Reminder"
when
Time cron "0 45 21 * * ?"
then
sendCommand(Bedroom1Dimmer,60)
logInfo( “file”, “changing the lights based on the time”)
end
rule "Bedtime"
when
Time cron "0 5 22 * * ?"
then
sendCommand(Bedroom1Dimmer,OFF)
logInfo( “file”, “changing the lights based on the time”)
end
//Turn the boys lights on at a given time
rule "Wake up Routine"
when
Time cron "0 0 7 * * ?"
then
sendCommand(Bedroom1Dimmer,100)
logInfo( “file”, “changing the lights based on the time”)
end`