What I have are options for Daily, Weekly(Temp removed), and Monthly schedules. Input for daily and monthly options are passed to the same schedule. But if the weekly option is chosen then that input would be passed to a second and separate schedule. Only one schedule would run and to avoid any runtime errors unschedule() during install should only allow one schedule to run correct? Here’s my code minus the message section
preferences
{
section(“Select which meter to collect from…”)
{
input(name: “meter”, type: “capability.powerMeter”, title: “Collect from this meter…”, required: true, multiple: false, description: null)
}
section("When to send report")
{
input(name: "repeatHour", type: "number", title: "Everyday at...(0-23). Default=12p", required: true, defaultValue:12)
input(name: "repeatDate", type: "text", title: "Monthly on which date...(1-31). No input = everyday", required: false, defaultValue: "*")
}
section("When to reset data(Optional)")
{
input(name: "optional", type: "bool", title: "Run Reset schedule??", required: true)
input(name: "resetHour", type: "number", title: "Everyday at...(0-23). Default=12p", required: false, defaultValue:12)
input(name: "resetDate", type: "text", title: "Monthly on which date...(1-31). No input = everyday", required: false, defaultValue: "*")
}
section
{
input("recipients", "contact", title: "Send notifications to")
{
input(name: "sms", type: "phone", title: "Send A Text To", description: null, required: false)
input(name: "pushNotification", type: "bool", title: "Send a push notification", description: null, defaultValue: true)
}
}
}
def installed()
{
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated()
{
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize()
{
//subscribe(meter, “energy”, meterHandler)
def RepeatTime = "0 0 ${repeatHour} ${repeatDate} * ?"
schedule(RepeatTime, meterHandler)
if(optional == true)
{
def ResetTime = "0 0 ${resetHour} ${resetDate} * ?"
schedule(ResetTime, meterReset)
}
}
def meterHandler()
{
def msg = "${meter} used ${meter.latestValue(“energy”)} kWh."
sendMessage(msg)
}
def meterReset()
{
meter.reset()
}
def sendMessage(msg)