Newby Questions

Question 1: I need to use some functionality in the Java GregorianCalendar class, but… I’m hitting a wall:

def contactOpenHandler(evt) {
// include "java.util.GregorianCalendar"
def cal = new GregorianCalendar()
def tim = cal.getTime()
def hr = cal.get(HOUR_OF_DAY)
def min = cal.get(MINUTE)
def sec = cal.get(SECOND)
def day = cal.get(DAY_OF_MONTH)
def mon = cal.get(MONTH) /* jan=0 */
def year = cal.get(YEAR)
log.debug “cal: hr=$hr min=$min sec=$sec day=$day mon=$mon year=$year”

I’ve commented out the include, because it gets an error. and for sure, the MINUTE, SECOND are not defined.

Second Question: How would I arrange to turn a light on, and then off in 10 minutes?

murf

Look at documentation, on the left hand side find API > Content > SmartApp and look at the runIn method. That is how you schedule events in the future

http://docs.smartthings.com/en/latest/ref-docs/smartapp-ref.html

2 Likes

You may also find the more in-depth documentation guide on scheduling useful as well. In general it’s a good idea to browse the documentation, but here are some topics that may be of particular use:

  • The Scheduling documentation covers all the different ways you can schedule future executions in detail.
  • The Working with time documentation provides some solutions to common time-based tasks. It doesn’t cover every possibility, but covers common cases and can be used to build on for your own use.
  • The Groovy with SmartThings documentation details the specific sandboxed Groovy DSL SmartThings uses, including the whitelist of allowed classes.
  • Not directly related, but the Hubs and Locations discusses the multi-shard server architecture, and the Publishing documentation covers making sure you are working on the correct shard (a very common stumbling block since it is not straightforward at all).

Hope that helps!

3 Likes