Anyone know of a smart app to open switch on a time AND date

anyone know of a smart app to open switch on a time AND date.

got smartvent… need to close on dec 1st and open on apr. 1st… got it where office is too hot in winter and keep forgetting to close vent to stop heat from going in, but need ac in summer. dont want it based on temp, so dont recomment that.

webCoRE can use date logic in its pistons.

2 Likes

That should not be difficult to write a smartapp for that.
Pickup any smartapp that drives a swtch and use runOnce per http://docs.smartthings.com/en/latest/smartapp-developers-guide/scheduling.html

Should be really few lines of code.

Yep already did thanks

/**

  • Copyright 2015 SmartThings
  • 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.
  • lg kahn smart app to turn device on when temp is between two values
  • and off otherwise. Also has to be between 2 date ranges.
  • also give alerts when turning on off.
  • I use for a roof heater wire/coil.
  • v2 add disable/enable option
  • Author: LGKahn kahn-st@lgk.com
    */

definition(
name: “Schedule Switch on by date”,
namespace: “lgkapps”,
author: “lgkahn”,
description: “Control a device , turn on on given date.”,
category: “Green Living”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch@2x.png
)

preferences {
section("Select the outlet(s)… "){
input “outlets”, “capability.switch”, title: “Outlets”, multiple: true
}

section("Start after Date format (yyyymmdd)..."){
	input "startDate", "number", title: "Date?"
}
section("End after Date format (yyyymmdd)..."){
	input "endDate", "number", title: "Date?"
}
section("Time Zone Offset ie -5 etc...."){
	input "tzOffset", "number", title: "Offset?", range: "-12..12"
}
	section("Disabled?"){
	input "disabled", "bool", title: "Disabled?", defaultValue: false
}

 section( "Notifications" ) {
    input("recipients", "contact", title: "Send notifications to") {
        input "sendPushMessage", "enum", title: "Send a push notification?", options: ["Yes", "No"], required: false
        input "alsoSendTextMessage", "enum", title: "Also Send a text message?", options: ["Yes", "No"], required: false
        input "phone1", "phone", title: "Send a Text Message?", required: false
    }
}

}

def installed()
{
log.debug “in switch controller installed”

}

def updated()
{

log.debug "in coil controller updated … "
unsubscribe()

if (disabled == null)
 disabled = false
 // turn off if on
 
  if (disabled == true)
       {
         log.debug "Disabled!"
         outlets.off()
       }
       
  subscribe(location, "sunrise", sunriseHandler)

}

def sunriseHandler(evt)
{

log.debug "in sunrise handler"
log.debug "set offset = $tzOffset"
log.debug “disabled = $disabled”

def today = new Date();

def ltf = new java.text.SimpleDateFormat("yyyyMMdd")
ltf.setTimeZone(TimeZone.getTimeZone("GMT${tzOffset}"))
	 
     String date1 = ltf.format(today);
     int intdate = Integer.parseInt(date1)
     log.debug "int date = $intdate"
     log.debug "enddate = $endDate"
     log.debug "startdate = $startDate"
     def currSwitches = outlets.currentSwitch
     def onOutlets = currSwitches.findAll { switchVal -> switchVal == "on" ? true : false }
     def onsize = onOutlets.size()
     def allsize = outlets.size()
     if (disabled == true)
       {
         log.debug "Currently Disabled!"
       }
      else
      {
     if  ((intdate >= startDate) && (intdate <= endDate))
        
       {
                 // dont do anything if already on
                 log.debug "In try turn on, number of outlets on = $onsize, total outlets = $allsize."
                 if (onsize != allsize)
                   {
                     log.debug "turning outlets On as we are within the date range ($startDate - $endDate)!"
        	         mysend("Turning device(s) On as we are within the date range ($startDate - $endDate)!")
                     outlets.on()
                   }
                  else log.debug "Not turning on again, all already on!"
             }
         else 
             {
                // dont do anything if already off
                  log.debug "In try turn off, number of outlets  On = $onsize."
              
                 if (onsize != 0)
                   {
             	    log.debug "turning outlets Off! as we are no longer within the date range ($startDate - $endDate)!"
                    mysend("Turning device(s) Off aw we are no longer within the date range ($startDate - $endDate)!")
                    outlets.off()
                   }
                  else log.debug "All outlets already off!"
             }
             
}

}

private mysend(msg) {
if (location.contactBookEnabled) {
log.debug(“sending notifications to: ${recipients?.size()}”)
sendNotificationToContacts(msg, recipients)
}
else {
if (sendPushMessage != “No”) {
log.debug(“sending push message”)
sendPush(msg)
}

    if ((phone1) && (alsoSendTextMessage == "Yes")) {
        log.debug("sending text message")
        sendSms(phone1, msg)
    }
}

// log.debug msg
}

1 Like