/** * Arlo Hubitat Mode * * Copyright 2018 Mavrrick * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License * for the specific language governing permissions and limitations under the License. * */ definition( name: "Arlo Hubitat Mode", namespace: "Mavrrick", author: "Mavrrick", description: "Trigger a recording based on device action. Repeat if enabled until condition has passed.", category: "My Apps", parent: "Mavrrick:Arlo Assistant", iconUrl: "https://farm9.staticflickr.com/8632/16461422990_e5121d68ee_o.jpg", iconX2Url: "https://farm9.staticflickr.com/8632/16461422990_e5121d68ee_o.jpg", iconX3Url: "https://farm9.staticflickr.com/8632/16461422990_e5121d68ee_o.jpg" ) import groovy.time.TimeCategory preferences { page (name: "mainPage", title: "Setup Hubitat Arlo Mode integration") page (name: "modeDefine", title: "What will define what the mode is") page (name: "securityState", title: "What security modes will be used") page (name: "modeRulesetSetup", title: "Define rulesets") page (name: "modeTimeSetup", title: "Day Time Setup") // page (name: "modeCameraSetup", title: "Camera setup") // page (name: "modeAlarmSetup", title: "Siren Setup") // page (name: "notificationSetup", title: "Notification Setup") } def mainPage() { dynamicPage(name: "mainPage", title: "Setup Hubitat Arlo Assistant Mode integration", uninstall: true, install: true) { section(title: "Please name the Hubitat Arlo Assistant Mode") { label title: "Please name this Hubitat Arlo Mode", required: true, defaultValue: "Hubitat Arlo Mode" } section("What will determine when this mode is active") { href "modeDefine", title: "Define criteria for Arlo Assitant Mode", description: "Define Arlo Assistant Mode" } section("Camera State Management") { input "camerasOn", "capability.switch", title: "What cameras do you want to activate in this mode", multiple: true, required: false input "camerasOff", "capability.switch", title: "What cameras do you want to deactivate in this mode", multiple: true, required: false } section("Define Number of Rulesets") { input "numOfSets", "number", title: "How Many Rule Sets will the mode use?", required: false, range: "1..5", defaultValue: 1 } section("Define ruleset values ") { href "modeRulesetSetup", title: "Define rulesets for mode.", description: "Defin the Rulesets that will be active in mode." } } } def modeDefine() { dynamicPage(name: "modeDefine", title: "What will determine if this Arlo Assitant Mode is active", nextPage: "mainPage", uninstall: false, install: false) { section("Defin Hubitat Mode") { input "stmode", "mode", title: "Hubitat Mode that must be active", required: false, multiple: true // input "presense", "capability.presenceSensor", title: "What presense check will be required", required: false } section("Alarm Mode State integration") { input "shmUseState", "bool", title: "Do you want to use the HSM Alarm State", required: false href "securityState", title: "Security system modes to use", description: "Select security modes that will apply" } section("Defin Time criteria") { paragraph "If you use the time values please use it alone. It is not currently setup to work with the Hubitat Mode or HSM alarm state." input "timeSetup", "enum", title: "Type of time rule to setup", required: false, multiple: false, options: ["Time": "Time", "Sunrise": "Sunrise/Sunset"] href "modeTimeSetup", title: "Click here to setup your time options", description: "Click here to setup your time options" } section("Define virtual Switch") { paragraph "If you use a virtual switch please configure it by its self. It is not currently setup to work with the Hubitat Mode or HSM alarm state." input "virtualSwitch", "capability.switch", title: "Add virtual switch for mode.", required: false, multiple: false } section("Is this a general rule") { input "generalRule", "bool", title: "This is a general rule that does not require validation", required: false } } } def modeTimeSetup() { dynamicPage(name: "modeTimeSetup", title: "Time Setup options", nextPage: "modeDefine", uninstall: false, install: false) { if (settings.timeSetup == "Time") { section("Select your time setup options below") { paragraph "Use the below options to setup your start and end time" paragraph "Specify the exact time below if this will be used." input "fromTime", "time", title: "From", required: false input "toTime", "time", title: "To", required: false paragraph "Specify all of the days you wish to use this mode for." input "days", "enum", title: "Select Days of the Week", required: false, multiple: true, options: ["Sunday": "Sunday", "Monday": "Monday", "Tuesday": "Tuesday", "Wednesday": "Wednesday", "Thursday": "Thursday", "Friday": "Friday", "Saturday": "Saturday"] } } if (settings.timeSetup == "Sunrise") { section("Select your time setup options below") { paragraph "Use the below options to setup rules based on sunset and sunrise." input "modeStart", "enum", title: "When will mode start", required: false, multiple: false, options: ["Sunrise": "Sunrise", "Sunset": "Sunset"] input "startOffSet", "number", title: "Turn on this many minutes before sunset", defaultValue: 0 paragraph "What offset woud you like to use to activate this Mode" input "modeStop", "enum", title: "When will mode stop", required: false, multiple: false, options: ["Sunrise": "Sunrise", "Sunset": "Sunset"] input "stopOffSet", "number", title: "Turn on this many minutes before sunset", defaultValue: 0 } } section ("Return to Arlo Hubitat Mode setup"){ href "modeDefine", title: "Return to the previous menu", description: "Return to the previous menu to complete setup." } } } def securityState() { dynamicPage(name: "securityState", title: "What security modes will be used", nextPage: "modeDefine", uninstall: false, install: false) { if (settings.shmUseState) { section("Home Security Monitor mode selection") { paragraph "Please select the SHM Security mode that will be used to identify this mode" paragraph "What Active alarm mode do you want to monitor for 1= ArmedHome, 2=ArmedNight, 3=Disarmed. All other numberical valudes wil be ignored." input "alarmtype1", "number", title: "What type of alarm do you want to trigger from?", required: false, defaultValue: 1 } } section ("Return to Arlo Hubitat Mode setup"){ href "modeDefine", title: "Return to the previous menu", description: "Return to the previous menu to complete setup." } } } def modeRulesetSetup() { dynamicPage(name: "modeRulesetSetup", title: "Define Rulesets", nextPage: "mainPage", uninstall: false, install: false) { section("Ruleset 1") { paragraph "Please select triggers for Ruleset 1" input "motion", "capability.motionSensor", title: "Motion Sensor?", required: false, multiple: true input "sound", "capability.soundSensor", title: "Audio Sensor?", required: false, multiple: true input "contact", "capability.contactSensor", title: "Contact Sensor?", required: false, multiple: true input "myButton", "capability.momentary", title: "What Button?", required: false, multiple: true input "acceleration", "capability.accelerationSensor", title: "Acceleration Sensor?", required: false, multiple: true input "mySwitch", "capability.switch", title: "Switch?", required: false, multiple: true input "myMoisture", "capability.waterSensor", title: "Moisture Sensor?", required: false, multiple: true paragraph "Please select Cameras involved with Ruleset 1" input "recordCameras", "bool", title: "Enable Camera recording?", description: "This switch will enable cameras to record on alarm events.", defaultValue: false, required: true, multiple: false input "cameras", "capability.switch", multiple: true, required: false // input name: "clipLength", type: "number", title: "Clip Length", description: "Please enter the length of each recording.", required: true, range: "5..120", defaultValue: 120 paragraph "Please define light actions with Ruleset 1" input "lightAction1", "bool", title: "Enable Light action for this mode", description: "This switch will tell the mode to run the light action.", defaultValue: false, required: true, multiple: false input "switcheSet1", "capability.switch", title: "These lights will be activated with the action", multiple: true, required: false input "switchLevel1", "capability.switchLevel", title: "Set these lights to the specified value below", multiple: true, required: false input "switchLevelChg1", "number", title: "What level do you want your lights set at.", required: true, range: "1..100", defaultValue: 100 input "lightShutOff", "bool", title: "Enable this option to turn off the light automatically", description: "This switch will schedule a check to turn the lights off", defaultValue: false, required: true, multiple: false input "lightShutOffTime", "number", title: "How many minutes to wait before turning off the lights", required: true, range: "1..90", defaultValue: 5 paragraph "Please define alarm action with Ruleset 1" input "alarmAction1", "bool", title: "Enable Alarm action for this mode", description: "This switch will tell the mode to run the Alarm action.", defaultValue: false, required: true, multiple: false paragraph "Valid alarm types are 1= Siren, 2=Strobe, and 3=Both. All other numberical valudes wil be ignored." input "alarmActionType1", "number", title: "What type of alarm do you want to trigger from?", required: false, range:"1..3", defaultValue: 1 input "alarmSiren1", "capability.alarm", title: "Use these Alarm sirens when triggered", multiple: true, required: false input "alarmDuration1", "number", title: "How many minutes should the alarm stay on for?", required: false, range:"1..15", defaultValue: 1 paragraph "Please define notification setup for Ruleset 1" input "notifyEnable", "bool", title: "Do you want to use this mode to send notifications.", required: false input "message", "text", title: "Send this message if activity is detected.", required: false input "notifiers", "capability.notification", multiple: true, submitOnChange: true, width: 6, required: false /* paragraph "Multiple numbers can be entered as long as sperated by a (;)" // input("recipients", "contact", title: "Send notifications to?") { input "phone", "phone", title: "Enter a phone number to get SMS.", required: false paragraph "If outside the US please make sure to enter the proper country code." */ input "sendPush", "bool", title: "Send Push notifications to everyone?", description: "This will tell Arlo Assistant to send out push notifications to all users of the location", defaultValue: false, required: true, multiple: false input "notifyTimeout", "number", title: "Minimum seconds between messages", required: false, defaultValue: 1 paragraph "A 'HelloHome' notification is always sent to the Location Event log" } if (settings.numOfSets > 1){ section("Ruleset 2"){ paragraph "Please select triggers for Ruleset 2" input "motion2", "capability.motionSensor", title: "Motion Sensor?", required: false, multiple: true input "sound2", "capability.soundSensor", title: "Audio Sensor?", required: false, multiple: true input "contact2", "capability.contactSensor", title: "Contact Sensor?", required: false, multiple: true input "myButton2", "capability.momentary", title: "What Button?", required: false, multiple: true input "acceleration2", "capability.accelerationSensor", title: "Acceleration Sensor?", required: false, multiple: true input "mySwitch2", "capability.switch", title: "Switch?", required: false, multiple: true input "myMoisture2", "capability.waterSensor", title: "Moisture Sensor?", required: false, multiple: true paragraph "Please select Cameras involved with Ruleset 2" input "recordCameras2", "bool", title: "Enable Camera recording?", description: "This switch will enable cameras to record on alarm events.", defaultValue: false, required: true, multiple: false input "cameras2", "capability.switch", multiple: true, required: false // input name: "clipLength2", type: "number", title: "Clip Length", description: "Please enter the length of each recording.", required: true, range: "5..120", defaultValue: 120 paragraph "Please define light actions with Ruleset 2" input "lightAction2", "bool", title: "Enable Light action for this mode", description: "This switch will tell the mode to run the light action.", defaultValue: false, required: true, multiple: false input "switcheSet2", "capability.switch", title: "These lights will be activated with the action", multiple: true, required: false input "switchLevel2", "capability.switchLevel", title: "Set these lights to the specified value below", multiple: true, required: false input "switchLevelChg2", "number", title: "What level do you want your lights set at.", required: true, range: "1..100", defaultValue: 100 input "lightShutOff2", "bool", title: "Enable this option to turn off the light automatically", description: "This switch will schedule a check to turn the lights off", defaultValue: false, required: true, multiple: false input "lightShutOffTime2", "number", title: "How many minutes to wait before turning off the lights", required: true, range: "1..90", defaultValue: 5 paragraph "Please define alarm action with Ruleset 2" input "alarmAction2", "bool", title: "Enable Alarm action for this mode", description: "This switch will tell the mode to run the Alarm action.", defaultValue: false, required: true, multiple: false paragraph "Valid alarm types are 1= Siren, 2=Strobe, and 3=Both. All other numberical valudes wil be ignored." input "alarmActionType2", "number", title: "What type of alarm do you want to trigger from?", required: false, range:"1..3", defaultValue: 1 input "alarmSiren2", "capability.alarm", title: "Set these lights to the specified value below", multiple: true, required: false input "alarmDuration2", "number", title: "How many minutes should the alarm stay on for?", required: false, range:"1..15", defaultValue: 1 paragraph "Please define notification setup for Ruleset 2" input "notifyEnable2", "bool", title: "Do you want to use this mode to send notifications.", required: false input "message2", "text", title: "Send this message if activity is detected.", required: false input "notifiers2", "capability.notification", multiple: true, submitOnChange: true, width: 6, required: false /* paragraph "Multiple numbers can be entered as long as sperated by a (;)" // input("recipients", "contact", title: "Send notifications to?") { input "phone", "phone", title: "Enter a phone number to get SMS.", required: false paragraph "If outside the US please make sure to enter the proper country code." */ input "sendPush2", "bool", title: "Send Push notifications to everyone?", description: "This will tell Arlo Assistant to send out push notifications to all users of the location", defaultValue: false, required: true, multiple: false input "notifyTimeout2", "number", title: "Minimum seconds between messages", required: false, defaultValue: 1 paragraph "A 'HelloHome' notification is always sent to the Location Event log" } } if (settings.numOfSets > 2){ section("Ruleset 3"){ paragraph "Please select triggers for Ruleset 3" input "motion3", "capability.motionSensor", title: "Motion Sensor?", required: false, multiple: true input "sound3", "capability.soundSensor", title: "Audio Sensor?", required: false, multiple: true input "contact3", "capability.contactSensor", title: "Contact Sensor?", required: false, multiple: true input "myButton3", "capability.momentary", title: "What Button?", required: false, multiple: true input "acceleration3", "capability.accelerationSensor", title: "Acceleration Sensor?", required: false, multiple: true input "mySwitch3", "capability.switch", title: "Switch?", required: false, multiple: true input "myMoisture3", "capability.waterSensor", title: "Moisture Sensor?", required: false, multiple: true paragraph "Please select Cameras involved with Ruleset 3" input "recordCameras3", "bool", title: "Enable Camera recording?", description: "This switch will enable cameras to record on alarm events.", defaultValue: false, required: true, multiple: false input "cameras3", "capability.switch", multiple: true, required: false // input name: "clipLength3", type: "number", title: "Clip Length", description: "Please enter the length of each recording.", required: true, range: "5..120", defaultValue: 120 paragraph "Please define light actions with Ruleset 3" input "lightAction3", "bool", title: "Enable Light action for this mode", description: "This switch will tell the mode to run the light action.", defaultValue: false, required: true, multiple: false input "switcheSet3", "capability.switch", title: "These lights will be activated with the action", multiple: true, required: false input "switchLevel3", "capability.switchLevel", title: "Set these lights to the specified value below", multiple: true, required: false input "switchLevelChg3", "number", title: "What level do you want your lights set at.", required: true, range: "1..100", defaultValue: 100 input "lightShutOff3", "bool", title: "Enable this option to turn off the light automatically", description: "This switch will schedule a check to turn the lights off", defaultValue: false, required: true, multiple: false input "lightShutOffTime3", "number", title: "How many minutes to wait before turning off the lights", required: true, range: "1..90", defaultValue: 5 paragraph "Please define alarm action with Ruleset 3" input "alarmAction3", "bool", title: "Enable Alarm action for this mode", description: "This switch will tell the mode to run the Alarm action.", defaultValue: false, required: true, multiple: false paragraph "Valid alarm types are 1= Siren, 2=Strobe, and 3=Both. All other numberical valudes wil be ignored." input "alarmActionType3", "number", title: "What type of alarm do you want to trigger from?", required: false, range:"1..3", defaultValue: 1 input "alarmSiren3", "capability.alarm", title: "Set these lights to the specified value below", multiple: true, required: false input "alarmDuration3", "number", title: "How many minutes should the alarm stay on for?", required: false, range:"1..15", defaultValue: 1 paragraph "Please define notification setup for Ruleset 3" input "notifyEnable3", "bool", title: "Do you want to use this mode to send notifications.", required: false input "message3", "text", title: "Send this message if activity is detected.", required: false input "notifiers3", "capability.notification", multiple: true, submitOnChange: true, width: 6, required: false /* paragraph "Multiple numbers can be entered as long as sperated by a (;)" // input("recipients", "contact", title: "Send notifications to?") { input "phone", "phone", title: "Enter a phone number to get SMS.", required: false paragraph "If outside the US please make sure to enter the proper country code." */ input "sendPush3", "bool", title: "Send Push notifications to everyone?", description: "This will tell Arlo Assistant to send out push notifications to all users of the location", defaultValue: false, required: true, multiple: false input "notifyTimeout3", "number", title: "Minimum seconds between messages", required: false, defaultValue: 1 paragraph "A 'HelloHome' notification is always sent to the Location Event log" } } if (settings.numOfSets > 3){ section("Ruleset 4"){ paragraph "Please select triggers for Ruleset 4" input "motion4", "capability.motionSensor", title: "Motion Sensor?", required: false, multiple: true input "sound4", "capability.soundSensor", title: "Audio Sensor?", required: false, multiple: true input "contact4", "capability.contactSensor", title: "Contact Sensor?", required: false, multiple: true input "myButton4", "capability.momentary", title: "What Button?", required: false, multiple: true input "acceleration4", "capability.accelerationSensor", title: "Acceleration Sensor?", required: false, multiple: true input "mySwitch4", "capability.switch", title: "Switch?", required: false, multiple: true input "myMoisture4", "capability.waterSensor", title: "Moisture Sensor?", required: false, multiple: true paragraph "Please select Cameras involved with Ruleset 4" input "recordCameras4", "bool", title: "Enable Camera recording?", description: "This switch will enable cameras to record on alarm events.", defaultValue: false, required: true, multiple: false input "cameras4", "capability.switch", multiple: true, required: false // input name: "clipLength4", type: "number", title: "Clip Length", description: "Please enter the length of each recording.", required: true, range: "5..120", defaultValue: 120 paragraph "Please define light actions with Ruleset 4" input "lightAction4", "bool", title: "Enable Light action for this mode", description: "This switch will tell the mode to run the light action.", defaultValue: false, required: true, multiple: false input "switcheSet4", "capability.switch", title: "These lights will be activated with the action", multiple: true, required: false input "switchLevel4", "capability.switchLevel", title: "Set these lights to the specified value below", multiple: true, required: false input "switchLevelChg4", "number", title: "What level do you want your lights set at.", required: true, range: "1..100", defaultValue: 100 input "lightShutOff4", "bool", title: "Enable this option to turn off the light automatically", description: "This switch will schedule a check to turn the lights off", defaultValue: false, required: true, multiple: false input "lightShutOffTime4", "number", title: "How many minutes to wait before turning off the lights", required: true, range: "1..90", defaultValue: 5 paragraph "Please define alarm action with Ruleset 4" input "alarmAction4", "bool", title: "Enable Alarm action for this mode", description: "This switch will tell the mode to run the Alarm action.", defaultValue: false, required: true, multiple: false paragraph "Valid alarm types are 1= Siren, 2=Strobe, and 3=Both. All other numberical valudes wil be ignored." input "alarmActionType4", "number", title: "What type of alarm do you want to trigger from?", required: false, range:"1..3", defaultValue: 1 input "alarmSiren4", "capability.alarm", title: "Set these lights to the specified value below", multiple: true, required: false input "alarmDuration4", "number", title: "How many minutes should the alarm stay on for?", required: false, range:"1..15", defaultValue: 1 paragraph "Please define notification setup for Ruleset 4" input "notifyEnable4", "bool", title: "Do you want to use this mode to send notifications.", required: false input "message4", "text", title: "Send this message if activity is detected.", required: false input "notifiers4", "capability.notification", multiple: true, submitOnChange: true, width: 6, required: false /* paragraph "Multiple numbers can be entered as long as sperated by a (;)" // input("recipients", "contact", title: "Send notifications to?") { input "phone", "phone", title: "Enter a phone number to get SMS.", required: false paragraph "If outside the US please make sure to enter the proper country code." */ input "sendPush4", "bool", title: "Send Push notifications to everyone?", description: "This will tell Arlo Assistant to send out push notifications to all users of the location", defaultValue: false, required: true, multiple: false input "notifyTimeout4", "number", title: "Minimum seconds between messages", required: false, defaultValue: 1 paragraph "A 'HelloHome' notification is always sent to the Location Event log" } } if (settings.numOfSets > 4){ section("Ruleset 5"){ paragraph "Please select triggers for Ruleset 5" input "motion5", "capability.motionSensor", title: "Motion Sensor?", required: false, multiple: true input "sound5", "capability.soundSensor", title: "Audio Sensor?", required: false, multiple: true input "contact5", "capability.contactSensor", title: "Contact Sensor?", required: false, multiple: true input "myButton5", "capability.momentary", title: "What Button?", required: false, multiple: true input "acceleration5", "capability.accelerationSensor", title: "Acceleration Sensor?", required: false, multiple: true input "mySwitch5", "capability.switch", title: "Switch?", required: false, multiple: true input "myMoisture5", "capability.waterSensor", title: "Moisture Sensor?", required: false, multiple: true paragraph "Please select Cameras involved with Ruleset 5" input "recordCameras5", "bool", title: "Enable Camera recording?", description: "This switch will enable cameras to record on alarm events.", defaultValue: false, required: true, multiple: false input "cameras5", "capability.switch", multiple: true, required: false // input name: "clipLength5", type: "number", title: "Clip Length", description: "Please enter the length of each recording.", required: true, range: "5..120", defaultValue: 120 paragraph "Please define light actions with Ruleset 5" input "lightAction5", "bool", title: "Enable Light action for this mode", description: "This switch will tell the mode to run the light action.", defaultValue: false, required: true, multiple: false input "switcheSet5", "capability.switch", title: "These lights will be activated with the action", multiple: true, required: false input "switchLevel5", "capability.switchLevel", title: "Set these lights to the specified value below", multiple: true, required: false input "switchLevelChg5", "number", title: "What level do you want your lights set at.", required: true, range: "1..100", defaultValue: 100 input "lightShutOff5", "bool", title: "Enable this option to turn off the light automatically", description: "This switch will schedule a check to turn the lights off", defaultValue: false, required: true, multiple: false input "lightShutOffTime5", "number", title: "How many minutes to wait before turning off the lights", required: true, range: "1..90", defaultValue: 5 paragraph "Please define alarm action with Ruleset 5" input "alarmAction5", "bool", title: "Enable Alarm action for this mode", description: "This switch will tell the mode to run the Alarm action.", defaultValue: false, required: true, multiple: false paragraph "Valid alarm types are 1= Siren, 2=Strobe, and 3=Both. All other numberical valudes wil be ignored." input "alarmActionType5", "number", title: "What type of alarm do you want to trigger from?", required: false, range:"1..3", defaultValue: 1 input "alarmSiren5", "capability.alarm", title: "Set these lights to the specified value below", multiple: true, required: false input "alarmDuration5", "number", title: "How many minutes should the alarm stay on for?", required: false, range:"1..15", defaultValue: 1 paragraph "Please define notification setup for Ruleset 5" input "notifyEnable5", "bool", title: "Do you want to use this mode to send notifications.", required: false input "message5", "text", title: "Send this message if activity is detected.", required: false input "notifiers5", "capability.notification", multiple: true, submitOnChange: true, width: 6, required: false /* paragraph "Multiple numbers can be entered as long as sperated by a (;)" // input("recipients", "contact", title: "Send notifications to?") { input "phone", "phone", title: "Enter a phone number to get SMS.", required: false paragraph "If outside the US please make sure to enter the proper country code." */ input "sendPush5", "bool", title: "Send Push notifications to everyone?", description: "This will tell Arlo Assistant to send out push notifications to all users of the location", defaultValue: false, required: true, multiple: false input "notifyTimeout5", "number", title: "Minimum seconds between messages", required: false, defaultValue: 1 paragraph "A 'HelloHome' notification is always sent to the Location Event log" } } } } def installed() { log.debug "Installed with settings: ${settings}" initialize() } def updated() { log.debug "Updated with settings: ${settings}" unsubscribe() unschedule() runIn((5), initialize) } def initialize() { if (stmode) { subscribe(location, "mode", modeTriggerEvt) } if (shmUseState) { subscribe(location, "hsmStatus", modeTriggerEvt) } if (virtualSwitch) { log.debug "Subscribing to virtualSwitch" subscribe(virtualSwitch, "switch.on", modeTriggerEvt) subscribe(virtualSwitch, "switch.off", modeTriggerEvt) } if (settings.timeSetup == "Time") { schedule (fromTime, timeModeTrigger) schedule (toTime, modeNowDeactivate) } if (settings.timeSetup == "Sunrise") { if (settings.modeStart == "Sunrise") { subscribe(location, "sunriseTime", sunriseTimeHandler) sunriseTurnOn(location.currentValue("sunriseTime")) subscribe(location, "sunsetTime", sunsetStopTimeHandler) sunsetTurnOff(location.currentValue("sunsetTime")) } if (settings.modeStart == "Sunset") { subscribe(location, "sunsetTime", sunsetTimeHandler) sunsetTurnOn(location.currentValue("sunsetTime")) subscribe(location, "sunriseTime", sunriseStopTimeHandler) sunriseTurnOff(location.currentValue("sunriseTime")) } } state.noteTime = now() state.noteTime2 = now() state.noteTime3 = now() state.noteTime4 = now() state.noteTime5 = now() state.modeActive = 0 // modeTriggerEvt() if (generalRule) { modeNowActive () } } def sunsetTimeHandler(evt) { //when I find out the sunset time, schedule the lights to turn on with an offset sunsetTurnOn(evt.value) } def sunsetTurnOn(sunsetString) { //get the Date value for the string def sunsetTime = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", sunsetString) //calculate the offset def timeBeforeSunset = new Date(sunsetTime.time - (startOffSet * 60 * 1000)) log.debug "Scheduling Start for: $timeBeforeSunset (sunset is $sunsetTime)" //schedule this to run one time runOnce(timeBeforeSunset, modeNowActive) } def sunriseTimeHandler(evt) { //when I find out the sunset time, schedule the lights to turn on with an offset sunriseTurnOn(evt.value) } def sunriseTurnOn(sunriseString) { //get the Date value for the string def sunriseTime = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", sunriseString) //calculate the offset def timeBeforeSunrise = new Date(sunriseTime.time - (startOffSet * 60 * 1000)) log.debug "Scheduling Start for: $timeBeforeSunrise (sunset is $sunriseTime)" //schedule this to run one time runOnce(timeBeforeSunrise, modeNowActive) } def sunsetStopTimeHandler(evt) { //when I find out the sunset time, schedule the lights to turn on with an offset sunsetTurnOff(evt.value) } def sunsetTurnOff(sunsetString) { //get the Date value for the string def sunsetTime = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", sunsetString) //calculate the offset def timeBeforeSunset = new Date(sunsetTime.time - (stopOffSet * 60 * 1000)) log.debug "Scheduling Turn off for: $timeBeforeSunset (sunset is $sunsetTime)" //schedule this to run one time runOnce(timeBeforeSunset, timeStopMode) } def sunriseStopTimeHandler(evt) { //when I find out the sunset time, schedule the lights to turn on with an offset sunriseTurnOff(evt.value) } def timeStopMode(evt) { unsubscribe() runIn((5), initialize) } def sunriseTurnOff(sunriseString) { //get the Date value for the string def sunriseTime = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", sunriseString) //calculate the offset def timeBeforeSunrise = new Date(sunriseTime.time - (stopOffSet * 60 * 1000)) log.debug "Scheduling Turn off for: $timeBeforeSunrise (sunrise is $sunriseTime)" //schedule this to run one time runOnce(timeBeforeSunrise, timeStopMode) } def modeNowActive (){ if (contact) { subscribe(contact, "contact.open", modeAction) } if (acceleration) { subscribe(acceleration, "acceleration.active", modeAction) } if (motion) { subscribe(motion, "motion.active", modeAction) } if (mySwitch) { subscribe(mySwitch, "switch.on", modeAction) } if (myMoisture) { subscribe(myMoisture, "water.wet", modeAction) } if (myButton) { subscribe(myButton, "momentary.pushed", modeAction) } if (sound) { subscribe(sound, "sound.detected", modeAction) } if (settings.numOfSets > 1){ if (contact2) { subscribe(contact2, "contact.open", modeAction2) } if (acceleration2) { subscribe(acceleration2, "acceleration.active", modeAction2) } if (motion2) { subscribe(motion2, "motion.active", modeAction2) } if (mySwitch2) { subscribe(mySwitch2, "switch.on", modeAction2) } if (myMoisture2) { subscribe(myMoisture2, "water.wet", modeAction2) } if (myButton2) { subscribe(myButton2, "momentary.pushed", modeAction2) } if (sound2) { subscribe(sound2, "sound.detected", modeAction2) } } if (settings.numOfSets > 2){ if (contact3) { subscribe(contact3, "contact.open", modeAction3) } if (acceleration3) { subscribe(acceleration3, "acceleration.active", modeAction3) } if (motion3) { subscribe(motion3, "motion.active", modeAction3) } if (mySwitch3) { subscribe(mySwitch3, "switch.on", modeAction3) } if (myMoisture3) { subscribe(myMoisture3, "water.wet", modeAction3) } if (myButton3) { subscribe(myButton3, "momentary.pushed", modeAction3) } if (sound3) { subscribe(sound3, "sound.detected", modeAction3) } } if (settings.numOfSets > 3){ if (contact4) { subscribe(contact4, "contact.open", modeAction4) } if (acceleration4) { subscribe(acceleration4, "acceleration.active", modeAction4) } if (motion4) { subscribe(motion4, "motion.active", modeAction4) } if (mySwitch4) { subscribe(mySwitch4, "switch.on", modeAction4) } if (myMoisture4) { subscribe(myMoisture4, "water.wet", modeAction4) } if (myButton4) { subscribe(myButton4, "momentary.pushed", modeAction4) } if (sound4) { subscribe(sound4, "sound.detected", modeAction4) } } if (settings.numOfSets > 4){ if (contact5) { subscribe(contact5, "contact.open", modeAction5) } if (acceleration5) { subscribe(acceleration5, "acceleration.active", modeAction5) } if (motion5) { subscribe(motion5, "motion.active", modeAction5) } if (mySwitch5) { subscribe(mySwitch5, "switch.on", modeAction5) } if (myMoisture5) { subscribe(myMoisture5, "water.wet", modeAction5) } if (myButton5) { subscribe(myButton5, "momentary.pushed", modeAction5) } if (sound5) { subscribe(sound5, "sound.detected", modeAction5) } } if (camerasOn) { camerasOn.on() } if (camerasOff) { camerasOff.off() } state.noteTime = now() state.noteTime2 = now() state.noteTime3 = now() state.noteTime4 = now() state.noteTime5 = now() // state.modeMatch = false state.modeActive = 1 } def modeNowDeactivate() { def delay = 0L delay += 3000 log.debug "Updated with settings: ${settings}" unsubscribe() runIn((5), initialize) } def timeModeTrigger(){ if (timeSetup) { def df = new java.text.SimpleDateFormat("EEEE") df.setTimeZone(location.timeZone) def day = df.format(new Date()) def dayCheck = days.contains(day) if (dayCheck) { def between = timeOfDayIsBetween(fromTime, toTime, new Date(), location.timeZone) if (between) { log.debug "Time Validation successfull" modeNowActive() } } else { log.debug "Time did not validate. No action" unsubscribe() runIn((5), initialize) } } } // Method to activate when a mode defining state changes in Hubitat def modeTriggerEvt(evt){ log.debug "${evt.device} has generated a ${evt.name} event with status of ${evt.value}. Checking to see if in mode for this Smartapp" if (stmode && shmUseState) { def curMode = location.currentMode if (stmode =~ curMode) { def alarmState = evt.value if (alarmState == "armedHome" && alarmtype1 == 1) { log.debug "Current alarm mode: ${alarmState}.Current HSM alarm mode has been validated. Executing Action." modeNowActive() } else if (alarmState == "armedNight" && alarmtype1 == 2) { log.debug "Current alarm mode: ${alarmState}.Current HSM alarm mode has been validated. Executing Action." modeNowActive() } else if (alarmState == "disarmed" && alarmtype1 == 3) { log.debug "Current alarm mode: ${alarmState}.Current HSM S alarm mode has been validated. Executing Action." modeNowActive() } else { log.debug "Alarm mode did not match with mode. This action does not apply to this mode" unsubscribe() runIn((5), initialize) } } else { log.debug "Hubitat mode did not validate. This action does not apply to this mode" unsubscribe() runIn((5), initialize) } } else if (shmUseState) { def alarmState = evt.value log.debug "Identified to use HSM Alarm Mode. Checking what alarm mode is active" if (alarmState == "armedHome" && alarmtype1 == 1) { log.debug "Current alarm mode: ${alarmState}.Current HSM alarm mode has been validated. Executing Action." modeNowActive() } else if (alarmState == "armedNight" && alarmtype1 == 2) { log.debug "Current alarm mode: ${alarmState}.Current HSM alarm mode has been validated. Executing Action." modeNowActive() } else if (alarmState == "disarmed" && alarmtype1 == 3) { log.debug "Current alarm mode: ${alarmState}.Current HSM alarm mode has been validated. Executing Action." modeNowActive() } else { log.debug "Current alarm mode: ${alarmState}. Current alarm setup value: ${alarmtype1}. This is not a valid match. Mode will not execute" unsubscribe() runIn((5), initialize) } } else if (stmode) { def curMode = location.currentMode log.debug "These modes were configured and are ${stmode} are being reviewed." if (stmode =~ curMode) { /* stmode.findAll { it.value ==~ curMode } .each { log.debug "Found Mode: ID: ${it.value} , Mode found. ${curMode} is current mode." */ modeNowActive() log.debug "mode is active" } /* } */ else { log.debug "No longer in proper ST Mode for integration reseting app. Hubitat modes is ${curMode} does not match ${stmode}." unsubscribe() runIn((5), initialize) } } else if (virtualSwitch) { def check = virtualSwitch.currentSwitch if (check != "off") { log.debug "Virtual Switch mode validation has been validated. Executing Action" modeNowActive() } else { log.debug "Virtual swtich is off and not in proper state for mode" unsubscribe() runIn((5), initialize) } } else if (generalRule){ log.debug "No Mode critera defined. Running actions" modeNowActive() } else { log.debug "Hubitat not in applicable conditions for mode to apply." unsubscribe() runIn((5), initialize) } } def cameraReset() { cameras?.off() } def modeAction(evt){ log.debug "Ruleset 1 event" if (recordCameras) { cameras.each { it?.on() } } if (lightAction1) { lightAction() } if (alarmAction1) { alarmActionOn() } alarmAction1 if (notifyEnable){ def timePassed = now() - state.noteTime log.debug "${new Date(state.noteTime)}" log.debug "${timePassed}" if (timePassed > notifyTimeout*1000){ sendnotification() state.noteTime = now() } else { log.debug "Not enogh time has passed. No notification is sent" } } runIn((5), cameraReset) } def alarmActionOn() { switch (alarmActionType1.value) { case 1 : log.debug "Alarm type ${alarmActionType1.value} detected. Turning on siren." alarmSiren1?.siren() break case 2 : log.debug "Alarm type ${alarmActionType1.value} detected. Turning on strobe." alarmSiren1?.strobe() break case 3 : log.debug "Alarm type ${alarmActionType1.value} detected. Turning on Siren and Strobe." alarmSiren1?.both() break default: log.debug "Ignoring unexpected alarmtype mode." log.debug "Alarm type ${alarmActionType1.value} detected." break } runIn((alarmDuration1*60), alarmActionOff) } def alarmActionOff() { log.debug "Turning off siren" alarmSiren1?.off() } def arloCapture() { log.debug "Sending cameras message to record with 1 min capture" switcheSet1?.on() } def sendnotification() { def msg = message if ( msg == null ) { log.debug "Message not configured. Skipping notification" } else { log.debug "Alarm Notification., '$msg'" // log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'" if (phone) { // check that the user did select a phone number if ( phone.indexOf(";") > 0){ def phones = phone.split(";") for ( def i = 0; i < phones.size(); i++) { log.debug("Sending SMS ${i+1} to ${phones[i]}") sendSmsMessage(phones[i], msg) } } else { log.debug("Sending SMS to ${phone}") sendSmsMessage(phone, msg) } } if (settings.sendPush) { log.debug("Sending Push to everyone") // sendPushMessage(msg) notifiers?.deviceNotification(msg) log.debug("Send Hello Home Message") sendLocationEvent(name: "HelloHome", descriptionText: message, value: app.label, type: 'APP_NOTIFICATION') } // sendNotifications(msgPrefix, msg) if (settings.notifyRepeat) { runIn((msgrepeat * 60) , notifyRepeatChk) } } } def lightAction(){ switcheSet1?.on() if (switchLevel1) { switchLevel1?.setLevel(${switchLevelChg1}) } if (settings.lightShutOff) { runIn((lightShutOffTime*60), lightActionChk) } } def lightActionChk() { def curActive = 0 if (contact) { contact.each { def satus = it.currentContact log.debug "Contact is in ${satus} state" if (satus == "open") { log.debug("Contact is still open. Leaving Light on") curActive = (curActive+1) } else { log.debug("Contact is closed. Turning the light off") } } log.debug("curActive = ${curActive}") } /* if (acceleration) { subscribe(acceleration, "acceleration.active", modeTriggerEvt) } */ if (motion) { motion.each { def satus = it.currentMotion log.debug "motion is in ${satus} state" if (satus == "on") { log.debug("Motion is still active. Leaving Light on") curActive = (curActive+1) } else { log.debug("Motion is inactive, Turning the light off") } } log.debug("curActive = ${curActive}") } if (mySwitch) { mySwitch.each { def satus = it.currentSwitch log.debug "mySwitch is in ${satus} state" if (satus == "on") { log.debug("Switch is still on. Leaving Light on") curActive = (curActive+1) } else { log.debug("Switch is off, Turning the light off") } } log.debug("curActive = ${curActive}") } /* if (myMoisture) { subscribe(myMoisture, "water.wet", modeTriggerEvt) } if (myButton) { subscribe(myButton, "momentary.pushed", modeTriggerEvt) } if (sound) { subscribe(myButton, "sound.detected", modeTriggerEvt) } */ if (curActive >0) { log.debug("Current activity value is greater then 1") runIn((lightShutOffTime*60), lightActionChk) } else { log.debug ("no activty found turning off lights") switcheSet1?.off() } } // Create Routines for ruleset 2 def cameraReset2() { cameras2?.off() } def modeAction2(evt){ log.debug "Ruleset2 event" if (recordCameras2) { cameras2.each { it?.on() } } if (lightAction2) { lightAction2() } if (alarmAction2) { alarmActionOn2() } alarmAction2 if (notifyEnable2){ def timePassed2 = now() - state.noteTime2 log.debug "${new Date(state.noteTime2)}" log.debug "${timePassed2}" if (timePassed2 > notifyTimeout2*60000){ sendnotification2() state.noteTime2 = now() } else { log.debug "Not enogh time has passed. No notification is sent" } } runIn((5), cameraReset2) } def alarmActionOn2() { switch (alarmActionType2.value) { case 1 : log.debug "Alarm type ${alarmActionType2.value} detected. Turning on siren." alarmSiren2?.siren() break case 2 : log.debug "Alarm type ${alarmActionType2.value} detected. Turning on strobe." alarmSiren2?.strobe() break case 3 : log.debug "Alarm type ${alarmActionType2.value} detected. Turning on Siren and Strobe." alarmSiren2?.both() break default: log.debug "Ignoring unexpected alarmtype mode." log.debug "Alarm type ${alarmActionType2.value} detected." break } runIn((alarmDuration2*60), alarmActionOff2) } def alarmActionOff2() { log.debug "Turning off siren" alarmSiren2?.off() } def arloCapture2() { // log.debug "$evt.name: $evt.value" log.debug "Sending cameras message to record with ${clipLength2} second capture" Date start2 = new Date() Date end2 = new Date() use( TimeCategory ) { end2 = start2 + clipLength2.seconds } log.debug "Capturing at ${start2} to ${end2}..." cameras2.capture(start2, start2, end2) } def sendnotification2() { def msg2 = message2 if ( msg2 == null ) { log.debug "Message not configured. Skipping notification" } else { log.debug "Alarm Notification., '$msg2'" /* log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'" */ if (phone2) { // check that the user did select a phone number if ( phone2.indexOf(";") > 0){ def phones2 = phone2.split(";") for ( def i = 0; i < phones2.size(); i++) { log.debug("Sending SMS ${i+1} to ${phones2[i]}") sendSmsMessage(phones2[i], msg2) } } else { log.debug("Sending SMS to ${phone2}") sendSmsMessage(phone2, msg2) } } if (settings.sendPush2) { log.debug("Sending Push to everyone") // sendPushMessage(msg) notifiers2?.deviceNotification(msg2) log.debug("Send Hello Home Message") sendLocationEvent(name: "HelloHome", descriptionText: message2, value: app.label, type: 'APP_NOTIFICATION') } // sendNotifications(msgPrefix, msg) if (settings.notifyRepeat2) { runIn((msgrepeat2 * 60) , notifyRepeatChk2) } } } def lightAction2(){ switcheSet2?.on() if (switchLevel2) { switchLevel2?.setLevel(${switchLevelChg2}) } if (settings.lightShutOff2) { runIn((lightShutOffTime2*60), lightActionChk2) } } def lightActionChk2() { def curActive2 = 0 if (contact2) { contact2.each { def satus2 = it.currentContact2 log.debug "Contact is in ${satus2} state" if (satus2 == "open") { log.debug("Contact is still open. Leaving Light on") curActive2 = (curActive2+1) } else { log.debug("Contact is closed. Turning the light off") } } log.debug("curActive = ${curActive2}") } /* if (acceleration) { subscribe(acceleration, "acceleration.active", modeTriggerEvt) } */ if (motion2) { motion2.each { def satus2 = it.currentMotion2 log.debug "Motion is in ${satus2} state" if (satus2 == "on") { log.debug("Motion is still active. Leaving Light on") curActive2 = (curActive2+1) } else { log.debug("Motion is inactive, Turning the light off") } } log.debug("curActive = ${curActive2}") } if (mySwitch2) { mySwitch2.each { def satus2 = it.currentSwitch2 log.debug "mySwitch is in ${satus2} state" if (satus2 == "on") { log.debug("Switch is still on. Leaving Light on") curActive2 = (curActive2+1) } else { log.debug("Switch is off, Turning the light off") } } log.debug("curActive = ${curActive2}") } /* if (myMoisture) { subscribe(myMoisture, "water.wet", modeTriggerEvt) } if (myButton) { subscribe(myButton, "momentary.pushed", modeTriggerEvt) } if (sound) { subscribe(myButton, "sound.detected", modeTriggerEvt) } */ if (curActive2 >0) { log.debug("Current activity value is greater then 1") runIn((lightShutOffTime2*60), lightActionChk2) } else { log.debug ("no activty found turning off lights") switcheSet2?.off() } } //Rule set 3 routines def cameraReset3() { cameras3?.off() } def modeAction3(evt){ log.debug "Ruleset 3 event" if (recordCameras3) { cameras3.each { it?.on() // runIn((5), cameraReset3) } } if (lightAction3) { lightAction3() } if (alarmAction3) { alarmActionOn3() } alarmAction3 if (notifyEnable3){ def timePassed3 = now() - state.noteTime3 log.debug "${new Date(state.noteTime3)}" log.debug "${timePassed3}" if (timePassed3 > notifyTimeout3*60000){ sendnotification3() state.noteTime3 = now() } else { log.debug "Not enogh time has passed. No notification is sent" } } runIn((5), cameraReset3) } def alarmActionOn3() { switch (alarmActionType3.value) { case 1 : log.debug "Alarm type ${alarmActionType3.value} detected. Turning on siren." alarmSiren3?.siren() break case 2 : log.debug "Alarm type ${alarmActionType3.value} detected. Turning on strobe." alarmSiren3?.strobe() break case 3 : log.debug "Alarm type ${alarmActionType3.value} detected. Turning on Siren and Strobe." alarmSiren3?.both() break default: log.debug "Ignoring unexpected alarmtype mode." log.debug "Alarm type ${alarmActionType3.value} detected." break } runIn((alarmDuration3*60), alarmActionOff3) } def alarmActionOff3() { log.debug "Turning off siren" alarmSiren3?.off() } def arloCapture3() { // log.debug "$evt.name: $evt.value" log.debug "Sending cameras message to record with ${clipLength3} second capture" Date start3 = new Date() Date end3 = new Date() use( TimeCategory ) { end3 = start3 + clipLength3.seconds } log.debug "Capturing at ${start3} to ${end3}..." cameras3.capture(start3, start3, end3) } def sendnotification3() { def msg3 = message3 if ( msg3 == null ) { log.debug "Message not configured. Skipping notification" } else { log.debug "Alarm Notification., '$msg3'" /* log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'" */ if (phone3) { // check that the user did select a phone number if ( phone3.indexOf(";") > 0){ def phones3 = phone3.split(";") for ( def i = 0; i < phones3.size(); i++) { log.debug("Sending SMS ${i+1} to ${phones3[i]}") sendSmsMessage(phones3[i], msg3) } } else { log.debug("Sending SMS to ${phone3}") sendSmsMessage(phone3, msg3) } } if (settings.sendPush3) { log.debug("Sending Push to everyone") // sendPushMessage(msg) notifiers3?.deviceNotification(msg3) log.debug("Send Hello Home Message") sendLocationEvent(name: "HelloHome", descriptionText: message3, value: app.label, type: 'APP_NOTIFICATION') } // sendNotifications(msgPrefix, msg) if (settings.notifyRepeat3) { runIn((msgrepeat3 * 60) , notifyRepeatChk3) } } } def lightAction3(){ switcheSet3?.on() if (switchLevel3) { switchLevel3?.setLevel(${switchLevelChg3}) } if (settings.lightShutOff3) { runIn((lightShutOffTime3*60), lightActionChk3) } } def lightActionChk3() { def curActive3 = 0 if (contact3) { contact3.each { def satus3 = it.currentContact3 log.debug "Contact is in ${satus3} state" if (satus3 == "open") { log.debug("Contact is still open. Leaving Light on") curActive3 = (curActive3+1) } else { log.debug("Contact is closed. Turning the light off") } } log.debug("curActive = ${curActive3}") } /* if (acceleration) { subscribe(acceleration, "acceleration.active", modeTriggerEvt) } */ if (motion3) { motion3.each { def satus3 = it.currentMotion3 log.debug "Motion is in ${satus3} state" if (satus3 == "on") { log.debug("Motion is still active. Leaving Light on") curActive3 = (curActive3+1) } else { log.debug("Motion is inactive, Turning the light off") } } log.debug("curActive = ${curActive3}") } if (mySwitch3) { mySwitch3.each { def satus3 = it.currentSwitch3 log.debug "mySwitch is in ${satus3} state" if (satus3 == "on") { log.debug("Switch is still on. Leaving Light on") curActive3 = (curActive3+1) } else { log.debug("Switch is off, Turning the light off") } } log.debug("curActive = ${curActive3}") } /* if (myMoisture) { subscribe(myMoisture, "water.wet", modeTriggerEvt) } if (myButton) { subscribe(myButton, "momentary.pushed", modeTriggerEvt) } if (sound) { subscribe(myButton, "sound.detected", modeTriggerEvt) } */ if (curActive3 >0) { log.debug("Current activity value is greater then 1") runIn((lightShutOffTime3*60), lightActionChk3) } else { log.debug ("no activty found turning off lights") switcheSet3?.off() } } // Ruleset 4 Methods def cameraReset4() { cameras4?.off() } def modeAction4(evt){ log.debug "Ruleset 4 event" if (recordCameras4) { cameras4.each { it?.on() // runIn((5), cameraReset4) } } if (lightAction4) { lightAction4() } if (alarmAction4) { alarmActionOn4() } alarmAction4 if (notifyEnable4){ def timePassed4 = now() - state.noteTime4 log.debug "${new Date(state.noteTime4)}" log.debug "${timePassed4}" if (timePassed4 > notifyTimeout4*60000){ sendnotification4() state.noteTime4 = now() } else { log.debug "Not enogh time has passed. No notification is sent" } } runIn((5), cameraReset4) } def alarmActionOn4() { switch (alarmActionType4.value) { case 1 : log.debug "Alarm type ${alarmActionType4.value} detected. Turning on siren." alarmSiren4?.siren() break case 2 : log.debug "Alarm type ${alarmActionType4.value} detected. Turning on strobe." alarmSiren4?.strobe() break case 3 : log.debug "Alarm type ${alarmActionType4.value} detected. Turning on Siren and Strobe." alarmSiren4?.both() break default: log.debug "Ignoring unexpected alarmtype mode." log.debug "Alarm type ${alarmActionType4.value} detected." break } runIn((alarmDuration4*60), alarmActionOff4) } def alarmActionOff4() { log.debug "Turning off siren" alarmSiren4?.off() } def arloCapture4() { // log.debug "$evt.name: $evt.value" log.debug "Sending cameras message to record with ${clipLength4} second capture" Date start4 = new Date() Date end4 = new Date() use( TimeCategory ) { end4 = start4 + clipLength4.seconds } log.debug "Capturing at ${start4} to ${end4}..." cameras4.capture(start4, start4, end4) } def sendnotification4() { def msg4 = message4 if ( msg4 == null ) { log.debug "Message not configured. Skipping notification" } else { log.debug "Alarm Notification., '$msg4'" /* log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'" */ if (phone4) { // check that the user did select a phone number if ( phone4.indexOf(";") > 0){ def phones4 = phone4.split(";") for ( def i = 0; i < phones4.size(); i++) { log.debug("Sending SMS ${i+1} to ${phones4[i]}") sendSmsMessage(phones4[i], msg4) } } else { log.debug("Sending SMS to ${phone4}") sendSmsMessage(phone4, msg4) } } if (settings.sendPush4) { log.debug("Sending Push to everyone") // sendPushMessage(msg) notifiers4?.deviceNotification(msg4) log.debug("Send Hello Home Message") sendLocationEvent(name: "HelloHome", descriptionText: message4, value: app.label, type: 'APP_NOTIFICATION') } // sendNotifications(msgPrefix, msg) if (settings.notifyRepeat4) { runIn((msgrepeat4 * 60) , notifyRepeatChk4) } } } def lightAction4(){ switcheSet4?.on() if (switchLevel4) { switchLevel4?.setLevel(${switchLevelChg4}) } if (settings.lightShutOff4) { runIn((lightShutOffTime4*60), lightActionChk4) } } def lightActionChk4() { def curActive4 = 0 if (contact4) { contact4.each { def satus4 = it.currentContact4 log.debug "Contact is in ${satus4} state" if (satus4 == "open") { log.debug("Contact is still open. Leaving Light on") curActive4 = (curActive4+1) } else { log.debug("Contact is closed. Turning the light off") } } log.debug("curActive = ${curActive4}") } /* if (acceleration) { subscribe(acceleration, "acceleration.active", modeTriggerEvt) } */ if (motion4) { motion4.each { def satus4 = it.currentMotion4 log.debug "Motion is in ${satus4} state" if (satus4 == "on") { log.debug("Motion is still active. Leaving Light on") curActive4 = (curActive4+1) } else { log.debug("Motion is inactive, Turning the light off") } } log.debug("curActive = ${curActive4}") } if (mySwitch4) { mySwitch4.each { def satus4 = it.currentSwitch4 log.debug "mySwitch is in ${satus4} state" if (satus4 == "on") { log.debug("Switch is still on. Leaving Light on") curActive4 = (curActive4+1) } else { log.debug("Switch is off, Turning the light off") } } log.debug("curActive = ${curActive4}") } /* if (myMoisture) { subscribe(myMoisture, "water.wet", modeTriggerEvt) } if (myButton) { subscribe(myButton, "momentary.pushed", modeTriggerEvt) } if (sound) { subscribe(myButton, "sound.detected", modeTriggerEvt) } */ if (curActive4 >0) { log.debug("Current activity value is greater then 1") runIn((lightShutOffTime4*60), lightActionChk4) } else { log.debug ("no activty found turning off lights") switcheSet4?.off() } } // Methods for Ruleset 5 def cameraReset5() { cameras5?.off() } def modeAction5(evt){ log.debug "Ruleset 5 event" if (recordCameras5) { cameras5.each { it?.on() // runIn((5), cameraReset5) } } if (lightAction5) { lightAction5() } if (alarmAction5) { alarmActionOn5() } alarmAction5 if (notifyEnable5){ def timePassed5 = now() - state.noteTime5 log.debug "${new Date(state.noteTime5)}" log.debug "${timePassed5}" if (timePassed5 > notifyTimeout5*60000){ sendnotification5() state.noteTime5 = now() } else { log.debug "Not enogh time has passed. No notification is sent" } } runIn((5), cameraReset5) } def alarmActionOn5() { switch (alarmActionType5.value) { case 1 : log.debug "Alarm type ${alarmActionType5.value} detected. Turning on siren." alarmSiren5?.siren() break case 2 : log.debug "Alarm type ${alarmActionType5.value} detected. Turning on strobe." alarmSiren5?.strobe() break case 3 : log.debug "Alarm type ${alarmActionType5.value} detected. Turning on Siren and Strobe." alarmSiren5?.both() break default: log.debug "Ignoring unexpected alarmtype mode." log.debug "Alarm type ${alarmActionType5.value} detected." break } runIn((alarmDuration5*60), alarmActionOff5) } def alarmActionOff5() { log.debug "Turning off siren" alarmSiren5?.off() } def arloCapture5() { // log.debug "$evt.name: $evt.value" log.debug "Sending cameras message to record with ${clipLength5} second capture" Date start5 = new Date() Date end5 = new Date() use( TimeCategory ) { end5 = start5 + clipLength5.seconds } log.debug "Capturing at ${start5} to ${end5}..." cameras5.capture(start5, start5, end5) } def sendnotification5() { def msg5 = message5 if ( msg5 == null ) { log.debug "Message not configured. Skipping notification" } else { log.debug "Alarm Notification., '$msg5'" /* log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'" */ if (phone5) { // check that the user did select a phone number if ( phone5.indexOf(";") > 0){ def phones5 = phone5.split(";") for ( def i = 0; i < phones5.size(); i++) { log.debug("Sending SMS ${i+1} to ${phones5[i]}") sendSmsMessage(phones5[i], msg5) } } else { log.debug("Sending SMS to ${phone5}") sendSmsMessage(phone5, msg5) } } if (settings.sendPush5) { log.debug("Sending Push to everyone") // sendPushMessage(msg) notifiers5?.deviceNotification(msg5) log.debug("Send Hello Home Message") sendLocationEvent(name: "HelloHome", descriptionText: message5, value: app.label, type: 'APP_NOTIFICATION') } // sendNotifications(msgPrefix, msg) if (settings.notifyRepeat5) { runIn((msgrepeat5 * 60) , notifyRepeatChk5) } } } def lightAction5(){ switcheSet5?.on() if (switchLevel5) { switchLevel5?.setLevel(${switchLevelChg5}) } if (settings.lightShutOff5) { runIn((lightShutOffTime5*60), lightActionChk5) } } def lightActionChk5() { def curActive5 = 0 if (contact5) { contact5.each { def satus5 = it.currentContact5 log.debug "Contact is in ${satus5} state" if (satus5 == "open") { log.debug("Contact is still open. Leaving Light on") curActive5 = (curActive5+1) } else { log.debug("Contact is closed. Turning the light off") } } log.debug("curActive = ${curActive5}") } /* if (acceleration) { subscribe(acceleration, "acceleration.active", modeTriggerEvt) } */ if (motion5) { motion5.each { def satus5 = it.currentMotion5 log.debug "Motion is in ${satus5} state" if (satus5 == "on") { log.debug("Motion is still active. Leaving Light on") curActive5 = (curActive5+1) } else { log.debug("Motion is inactive, Turning the light off") } } log.debug("curActive = ${curActive5}") } if (mySwitch5) { mySwitch5.each { def satus5 = it.currentSwitch5 log.debug "mySwitch is in ${satus5} state" if (satus5 == "on") { log.debug("Switch is still on. Leaving Light on") curActive5 = (curActive5+1) } else { log.debug("Switch is off, Turning the light off") } } log.debug("curActive = ${curActive5}") } /* if (myMoisture) { subscribe(myMoisture, "water.wet", modeTriggerEvt) } if (myButton) { subscribe(myButton, "momentary.pushed", modeTriggerEvt) } if (sound) { subscribe(myButton, "sound.detected", modeTriggerEvt) } */ if (curActive5 >0) { log.debug("Current activity value is greater then 1") runIn((lightShutOffTime5*60), lightActionChk5) } else { log.debug ("no activty found turning off lights") switcheSet5?.off() } }vvv