Need help with simple switch schedule

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

}

I appreciate the need/want to do things and learn, but there is a SmartApp already out there that can do all this for you.
webCoRE. Works brilliantly.
Go to the webCoRE forum for more information.

See “Schedule using cron” in the Scheduling developer documentation

Thanks for the information. Maybe it’s out of a desire to learn, but I’m trying to combine the variable of time and the variable of chosing the day of the month into the schedule call using cron. This is where I wasn’t sure how to code it.

Figured out the correct schedule syntax for calling the day, simply by calling the variable itself. See below if it helps anyone…

definition(
name: “Run Monthly”,
namespace: “”,
author: “”,
description: “Run once a month”,
category: “My Apps”,
iconUrl: “http://cdn.device-icons.smartthings.com/Appliances/appliances17-icn.png”,
iconX2Url: “http://cdn.device-icons.smartthings.com/Appliances/appliances17-icn@2x.png”)

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(“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 “pushNotify”, “enum”, title: “Send a push notification ?”, metadata:[values:[“Yes”, “No”]], required: false
input “phoneNumber”, “phone”, title: “Send a text message ?”, required: false
}

}

def installed() {
setNextSchedule()
}

def updated(settings) {
unschedule()
setNextSchedule()
}

def setNextSchedule()
{
def tz = location.timeZone
def schedStartTime = timeToday(startTime,tz)
def schedStopTime = timeToday(stopTime,tz)
def startHour = schedStartTime.format(“H”,tz)
def startMin = schedStartTime.format(“m”,tz)
def stopHour = schedStopTime.format(“H”,tz)
def stopMin = schedStopTime.format(“m”,tz)
schedule(“0 $startMin $startHour $dayToRun * ?”, “startTimerCallback”)
schedule(“0 $stopMin $stopHour $dayToRun * ?”, “stopTimerCallback”)
log.debug “Updated with settings: $startHour $startMin $stopHour $stopMin $dayToRun”
}

def startTimerCallback() {
log.debug "Turning on switches"
switches.on()
sendNotificationWithStart()
}

def stopTimerCallback() {
log.debug "Turning off switches"
switches.off()
sendNotificationWithStop()
setNextSchedule()
}

private sendNotificationWithStart() {
def msg = "Monthly Task Started"
if (pushNotify == “Yes”) {
sendPush(msg)
}
if (phoneNumber) {
sendSms(phoneNumber,msg)
}
}

private sendNotificationWithStop() {
def msg = "Monthly Task Stopped"
if (pushNotify == “Yes”) {
sendPush(msg)
}
if (phoneNumber) {
sendSms(phoneNumber,msg)
}
}