@abrock Ok…
V1.2
This one allows you to select multiple days of the week.
/**
* Copyright 2017 SecurEndpoint
*
* 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.
*
* Power Cycle
* V1.2 - Added days of the week so can be scheduled to operate only on certain days
* V1.1 - Added daily scheduling
* V1.0 - Initial release
*
* Last updated 07/05/2017
* Sets a schedule to turn off a switch, after a preset number of seconds it will turn back on again - Used to power cycle some equipment daily
*
* Author: COBRA
*/
definition(
name: "Scheduled Power Cycle",
namespace: "Cobra",
author: "SecureEndpoint",
description: "Schedule a switch to turn off then automatically turn it back on after a set number of seconds you specify.",
category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png"
)
preferences {
section("Which switch to cycle...") {
input(name:"theSwitch", type: "capability.switch", required: true, multiple: true)
}
section("Power Cycle at...") {
input (name: "rebootTime", title: "At what time?", type: "time", required: true)
}
section("On Which Days") {
input "days", "enum", title: "Select Days of the Week", required: true, multiple: true, options: ["Monday": "Monday", "Tuesday": "Tuesday", "Wednesday": "Wednesday", "Thursday": "Thursday", "Friday": "Friday", "Saturday": "Saturday", "Sunday": "Sunday"]
}
section("How long to stay off") {
input(name:"secondsdelay", type:"enum", title: "Seconds", required: true, options: [10,20,30,40,50,60,90,120])
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
schedule(rebootTime, rebootNow)
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
schedule(rebootTime, rebootNow)
}
def rebootNow(evt) {
def df = new java.text.SimpleDateFormat("EEEE")
// Ensure the new date object is set to local time zone
df.setTimeZone(location.timeZone)
def day = df.format(new Date())
//Does the preference input Days, i.e., days-of-week, contain today?
def dayCheck = days.contains(day)
if (dayCheck) {
log.debug "Cycling power on switch(es): $theSwitch "
def delay = secondsdelay
theSwitch.off()
log.debug "switch is off"
log.debug " waiting for ${delay} seconds"
if (delay == "10"){
runIn(10, switchOn)}
else if (delay == "20"){
runIn(20, switchOn)}
else if (delay == "30"){
runIn(30, switchOn)}
else if (delay == "40"){
runIn(40, switchOn)}
else if (delay == "50"){
runIn(50, switchOn)}
else if (delay == "60"){
runIn(60, switchOn)}
else if (delay == "90"){
runIn(90, switchOn)}
else if (delay == "120"){
runIn(120, switchOn)}
}
else {
log.debug "Not today!"
}
}
def switchOn (){
log.debug "Switching back on"
theSwitch.on()
log.debug "$theSwitch is now on"
}
I think this is pretty much done now…
I know I could have used smart lighting but I used this as an exercise to help my learning curve with this language.
I have tested this but only for today - If you look in the IDE I have added a little debug logging to see what is going on
Have a play for a couple of days and let me know if this works for you too
Andy