I need help programming a smartapp to turn on certain switches (plugs) at a certain time and turn off at another time, during one day a month. I have a few smart plugs set to charge Arlo cameras and want to do this once a month. I also want it to notify me.
So far I’ve cobbled some code together but not sure how to integrate the “day of month” into the cron schedule.
preferences {
section(“Select switches to control…”) {
input name: “switches”, type: “capability.switch”, multiple: true
}
section(“Turn them on at…”) {
input name: “startTime”, title: “Turn On Time?”, type: “time”, required: true
}
section(“And turn them off at…”) {
input name: “stopTime”, title: “Turn Off Time?”, type: “time”, required: true
}
section(“What day to run…”) {
input name: “dayToRun”, title: “Day To Run?”, type: “number”, range: “(1…28)”, required: true
}
section( “Notifications” ) {
input(“recipients”, “contact”, title: “Send notifications to”) {
input “sendPushMessage”, “enum”, title: “Send a push notification?”, options: [“Yes”, “No”], required: false
input “phoneNumber”, “phone”, title: “Send a text message?”, required: false
}
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
schedule(startTime, “startTimerCallback”)
schedule(stopTime, “stopTimerCallback”)
}
def updated(settings) {
unschedule()
schedule(startTime, “startTimerCallback”)
schedule(stopTime, “stopTimerCallback”)
}
def startTimerCallback() {
log.debug "Turning on switches"
switches.on()
}
def stopTimerCallback() {
log.debug "Turning off switches"
switches.off()
}
private send(msg) {
if (location.contactBookEnabled) {
log.debug(“sending notifications to: ${recipients?.size()}”)
sendNotificationToContacts(msg, recipients)
}
else {
if (sendPushMessage == “Yes”) {
log.debug(“sending push message”)
sendPush(msg)
}
if (phoneNumber) {
log.debug("sending text message")
sendSms(phoneNumber, msg)
}
}
log.debug msg
}