These methods can be used in both apps and drivers
Converts a given Celsius temperature to Fahrenheit.
BigDecimal celsiusToFahrenheit(BigDecimal val)
A temperature in Celsius.
The specified temperature in Fahrenheit.
Converts a given Fahrenheit temperature to Celsius
BigDecimal fahrenheitToCelsius(BigDecimal val)
A temperature in Fahrenheit.
The specified temperature in Celsius.
Converts the given color temperature to a string name. Most commonly used to populate colorName
attribute in driver. (Since 2.3.2)
convertTemperatureToGenericColorName(Integer colorTemp)
String name representation of the color temperature (e.g., "Soft White").
Converts the given color (hue and saturation) to a string name. Most commonly used to populate colorName
attribute in driver. (Since 2.3.2)
convertHueToGenericColorName(Integer hue, Integer saturation)
String name representation of the color (e.g., "Red", "Spring", "Cyan", etc.).
Location getLocation()
Returns the sunset and sunrise values for the current day. (Common method since 2.1.0)
Map getSunriseAndSunset()
Map getSunriseAndSunset(Map options)
options
- Map
with optional offset for sunrise/sunset or date; possible values are:
sunriseOffset
and sunsetOffset
: can either be a number of minutes or a String of the format "hours:minutes"
date
: instance of Date
representing the base date (day)Map
with with key values sunrise
and sunset
of type Date
// get today's sunrise and sunset
def riseAndSet = getSunriseAndSunset()
log.debug riseAndSet.sunrise
log.debug riseAndSet.sunset
// get sunrise time offset by 1 minute early, and get sunset offset by 1 hour, 5 minutes later
def offsetRiseAndSet = getSunriseAndSunset(sunriseOffset: -1, sunsetOffset: "1:05")
getTodaysSunrise()
getTodaysSunrise(TimeZone tz)
(since 2.3.6.118)TimeZone tz
: optional time zoneDate
representing today's sunrise timegetTomorrowsSunrise()
getTomorrowsSunrise(TimeZone tz)
(since 2.3.6.118)TimeZone tz
: optional time zoneDate
representing tomorrow's sunrise timegetTodaysSunset()
getTodaysSunset(TimeZone tz)
(since 2.3.6.118)TimeZone tz
: optional time zoneDate
representing today's sunset timegetTomorrowsSunset()
getTomorrowsSunset(TimeZone tz)
(since 2.3.6.118)TimeZone tz
: optional time zoneDate
representing tomorrow's sunset timeGet the current temperature scale set for the hub.
String getTemperatureScale()
none
String
- "F" or "C" based on the setting in the hub.
long now()
Get a Date object with today's date and the time specified
Date timeToday(String timeString, TimeZone timeZone = null)
timeString
- The time to use, can be either "HH:mm" or and ISO8601 date/time string
timeZone
- (optional) The timezone to use for the new Date.
Date
- A Date object with today's date and the time that was passed as timeString
Check if a date is between two dates.
boolean timeOfDayIsBetween(Date start, Date stop, Date value[, TimeZone timeZone])
start
- The date to start comparison against.
stop
- The date to stop comparison against.
value
- The date to compare
timezone
- (Optional) The timezone to use for the comparison
boolean
- true if the value date is between the start and stop dates, otherwise returns false.
Remove any scheduled tasks. If method is called without parameters, all schedules will be removed.
void unschedule()
void unschedule(handlerMethod)
handlerMethod
- Only remove schedules for this handlerMethod
Send an http GET request and return control to the calling code. Any response from the call will be passed to the callback method.
void asynchttpGet(callbackMethod, Map params, Map data = null)
callbackMethod
- The name of a callback method to send the response to. Can be null if the response can be ignored.
params
- the parameters to use to build the HTTP GET call. Possible values:
uri
- The URI to send the request toqueryString
- The raw, already-escaped query string.query
- Add these parameters to the existing query string. If any of the parameters already exist in the query, these values will not replace them. Multiple values for the same query parameter may be added by putting them in a list.headers
- Request headerspath
- The path component of this request. The value may be absolute or relative to the current path.contentType
- The content-type used for any data in the request body, as well as the Accept
content-type that will be used for parsing the response.requestContentType
- Assign a different content-type for the request than is expected for the response.timeout
(since 2.0.9) - timeout in seconds for the request, max timeout is 300ignoreSSLIssues
(since 2.1.8) - possible values: true
, false
. Ignores certificate issues for SSL connections. Cert does not have to be from a trusted authority and the hostname does not need to be verified. This is primarily for dev situations that make use of localhost, build, and test servers. Defaults to false.followRedirects
(since 2.2.9) - possible values: true
, false
. Determines whether or not redirects will be automatically followed. Defaults to true.data
- optional data to be passed to the callback method.
void asynchttpPost(String callbackMethod = null, Map params, Map data = null)
callbackMethod
- The name of a callback method to send the response to. Can be null if the response can be ignored.
params
- the parameters to use to build the http GET call. Possible values:
uri
- The URI to send the request toqueryString
- The raw, already-escaped query string.query
- Add these parameters to the existing query string. If any of the parameters already exist in the query, these values will not replace them. Multiple values for the same query parameter may be added by putting them in a list.headers
- Request headerspath
- The path component of this request. The value may be absolute or relative to the current path.contentType
- The content-type used for any data in the request body, as well as the Accept
content-type that will be used for parsing the response.requestContentType
- Assign a different content-type for the request than is expected for the response.body
- The request body. If this is a Map or Array, the system will take care of encoding it based on the requestContentType.timeout
(since 2.0.9) - timeout in seconds for the request, max timeout is 300ignoreSSLIssues
(since 2.1.8) - possible values: true, false. Ignores certificate issues for SSL connections. Cert does not have to be from a trusted authority and the hostname does not need to be verified. This is primarily for dev situations that make use of localhost, build, and test servers. Defaults to false.followRedirects
(since 2.2.9) - possible values: true, false. Determines whether or not redirects will be automatically followed. Defaults to true.data
- optional data to be passed to the callback method.
void asynchttpPatch(String callbackMethod = null, Map params, Map data = null)
callbackMethod
- The name of a callback method to send the response to. Can be null if the response can be ignored.
params
- the parameters to use to build the HTTP PATCH call. Possible values:
uri
- The uri to send the request toqueryString
- The raw, already-escaped query string.query
- Add these parameters to the existing query string. If any of the parameters already exist in the query, these values will not replace them. Multiple values for the same query parameter may be added by putting them in a list.headers
- Request headerspath
- The path component of this request. The value may be absolute or relative to the current path.contentType
- The content-type used for any data in the request body, as well as the Accept
content-type that will be used for parsing the response.requestContentType
- Assign a different content-type for the request than is expected for the response.body
- The request body. If this is a Map or Array, the system will take care of encoding it based on the requestContentType.timeout
(since 2.0.9) - timeout in seconds for the request, max timeout is 300ignoreSSLIssues
(since 2.1.8) - possible values: true, false. Ignores certificate issues for SSL connections. Cert does not have to be from a trusted authority and the hostname does not need to be verified. This is primarily for dev situations that make use of localhost, build, and test servers. Defaults to false.followRedirects
(since 2.2.9) - possible values: true, false. Determines whether or not redirects will be automatically followed. Defaults to true.data
- optional data to be passed to the callback method.
Send an HTTP GET request. Any response from the call will be passed to the closure.
void httpGet(String uri, Closure closure)
void httpGet(Map params, Closure closure)
uri
- The full URI to send the request to.
params
- the parameters to use to build the http GET call. Possible values:
uri
- The uri to send the request toqueryString
- The raw, already-escaped query string.query
- Add these parameters to the existing query string. If any of the parameters already exist in the query, these values will not replace them. Multiple values for the same query parameter may be added by putting them in a list.headers
- Request headerspath
- The path component of this request. The value may be absolute or relative to the current path.contentType
- The content-type used for any data in the request body, as well as the Accept
content-type that will be used for parsing the response.requestContentType
- Assign a different content-type for the request than is expected for the response.timeout
(since 2.0.9) - timeout in seconds for the request, max timeout is 300textParser
(since 2.1.1) - possible values: true, false. If set to true, the response will be parsed as plain text, if false the system will attempt to determine the content type and parse the response into an object. Defaults to false.ignoreSSLIssues
(since 2.1.8) - possible values: true, false. Ignores certificate issues for SSL connections. Cert does not have to be from a trusted authority and the hostname does not need to be verified. This is primarily for dev situations that make use of localhost, build, and test servers. Defaults to false.followRedirects
(since 2.2.9) - possible values: true, false. Determines whether or not redirects will be automatically followed. Defaults to true.closure
- code to handle a successful HTTP response. an object of type HttpResponseDecorator
is passed to this code.
void httpPost(String uri, String body, Closure closure)
void httpPost(Map params, Closure closure)
uri
- The full URI to send the request to.
body
- The body of the request as a String. Any encoding should be done before passing to the system.
params
- the parameters to use to build the http call. Possible values:
uri
- The uri to send the request toqueryString
- The raw, already-escaped query string.query
- Add these parameters to the existing query string. If any of the parameters already exist in the query, these values will not replace them. Multiple values for the same query parameter may be added by putting them in a list.headers
- Request headerspath
- The path component of this request. The value may be absolute or relative to the current path.contentType
- The content-type used for any data in the request body, as well as the Accept
content-type that will be used for parsing the response.requestContentType
- Assign a different content-type for the request than is expected for the response.body
- The request body. If this is a Map or Array, the system will take care of encoding it based on the requestContentType.timeout
(since 2.0.9) - timeout in seconds for the request, max timeout is 300*textParser*
(since 2.1.1) - possible values: true
, false
. If set to true, the response will be parsed as plain text, if false the system will attempt to determine the content type and parse the response into an object. Defaults to false.ignoreSSLIssues
(since 2.1.8) - possible values: true, false. Ignores certificate issues for SSL connections. Cert does not have to be from a trusted authority and the hostname does not need to be verified. This is primarily for dev situations that make use of localhost, build, and test servers. Defaults to false.followRedirects
(since 2.2.9) - possible values: true, false. Determines whether or not redirects will be automatically followed. Defaults to true.closure
- code to handle a successful HTTP response. an object of type HttpResponseDecorator is passed to this code.
Similar to httpPost
except that the contentType
parameter is set to "application/json"
void httpPostJson(String uri, String stringBody, Closure closure)
void httpPostJson(String uri, Map mapBody, Closure closure)
void httpPostJson(Map params, Closure closure)
uri
- The full URI to send the request to.
stringBody
- The body of the request as a String
. Any encoding should be done before passing to the system.
mapBody
- The body of the request as a Map
.
params
- the parameters to use to build the HTTP call. Possible values:
uri
- The URI to send the request toqueryString
- The raw, already-escaped query string.query
- Add these parameters to the existing query string. If any of the parameters already exist in the query, these values will not replace them. Multiple values for the same query parameter may be added by putting them in a list.headers
- Request headerspath
- The path component of this request. The value may be absolute or relative to the current path.requestContentType
- Assign a different content-type for the request than is expected for the response.body
- The request body. If this is a Map or Array, the system will take care of encoding it as JSON.timeout
(since 2.0.9) - timeout in seconds for the request, max timeout is 300textParser
(since 2.1.8) - possible values: true, false. If set to true, the response will be parsed as plain text, if false the system will attempt to determine the content type and parse the response into an object. Defaults to false.ignoreSSLIssues
(since 2.1.8) - possible values: true, false. Ignores certificate issues for SSL connections. Cert does not have to be from a trusted authority and the hostname does not need to be verified. This is primarily for dev situations that make use of localhost, build, and test servers. Defaults to false.followRedirects
(since 2.2.9) - possible values: true, false. Determines whether or not redirects will be automatically followed. Defaults to true.closure
- code to handle a successful HTTP response. an object of type HttpResponseDecorator
is passed to this code.
void httpPut(String uri, String body, Closure closure)
void httpPut(Map params, Closure closure)
uri
- The full uri to send the request to.
body
- The body of the request as a String. Any encoding should be done before passing to the system.
params
- the parameters to use to build the http call. Possible values:
uri
- The uri to send the request toqueryString
- The raw, already-escaped query string.query
- Add these parameters to the existing query string. If any of the parameters already exist in the query, these values will not replace them. Multiple values for the same query parameter may be added by putting them in a list.headers
- Request headerspath
- The path component of this request. The value may be absolute or relative to the current path.requestContentType
- The content-type used for any data in the request body, as well as the Accept
content-type that will be used for parsing the response.requestContentType
- Assign a different content-type for the request than is expected for the response.body
- The request body. If this is a Map or Array, the system will take care of encoding it based on the requestContentType.timeout
(since 2.0.9) - timeout in seconds for the request, max timeout is 300textParser
(since 2.1.1) - possible values: true, false. If set to true, the response will be parsed as plain text, if false the system will attempt to determine the content type and parse the response into an object. Defaults to false.ignoreSSLIssues
(since 2.1.8) - possible values: true, false. Ignores certificate issues for SSL connections. Cert does not have to be from a trusted authority and the hostname does not need to be verified. This is primarily for dev situations that make use of localhost, build, and test servers. Defaults to false.followRedirects
(since 2.2.9) - possible values: true, false. Determines whether or not redirects will be automatically followed. Defaults to true.closure
- code to handle a successful HTTP response. an object of type HttpResponseDecorator is passed to this code.
void httpPatch(String uri, String body, Closure closure)
void httpPatch(Map params, Closure closure)
uri
- The full uri to send the request to.
body
- The body of the request as a String. Any encoding should be done before passing to the system.
params
- the parameters to use to build the http call. Possible values:
uri
- The URI to send the request toqueryString
- The raw, already-escaped query string.query
- Add these parameters to the existing query string. If any of the parameters already exist in the query, these values will not replace them. Multiple values for the same query parameter may be added by putting them in a list.headers
- Request headerspath
- The path component of this request. The value may be absolute or relative to the current path.contentType
- The content-type used for any data in the request body, as well as the Accept
content-type that will be used for parsing the response.requestContentType
- Assign a different content-type for the request than is expected for the response.body
- The request body. If this is a Map or Array, the system will take care of encoding it based on the requestContentType.timeout
- timeout in seconds for the request, max timeout is 300textParser
- possible values: true, false. If set to true, the response will be parsed as plain text, if false the system will attempt to determine the content type and parse the response into an object. Defaults to false.ignoreSSLIssues
(since 2.1.8) - possible values: true, false. Ignores certificate issues for SSL connections. Cert does not have to be from a trusted authority and the hostname does not need to be verified. This is primarily for dev situations that make use of localhost, build, and test servers. Defaults to false.followRedirects
(since 2.2.9) - possible values: true, false. Determines whether or not redirects will be automatically followed. Defaults to true.closure
- code to handle a successful HTTP response. an object of type HttpResponseDecorator
is passed to this code.
void runIn(Long delayInSeconds, String handlerMethod, Map options = null)
delayInSeconds
- How long to wait in seconds until the handler should be called, don't expect that it will be called in exactly that time.
handlerMethod
- The name of a handler method in your driver or app. The method name should not contain parentheses.
options
- Optional values to control the scheduling of this method
overwrite
- defaults to true, which cancels the previous scheduled running of the handler method and schedules new; if set to false, this will create a duplicate schedule.data
- optional Map
of data to be passed to the handler method.misfire
- If set to "ignore" then the scheduler will simply try to fire it as soon as it can. NOTE: if a scheduler uses this instruction, and it has missed several of its scheduled firings, then several rapid firings may occur as the scheduler attempts to catch back up to where it would have been.runIn(50, "myMethod", [data: [myKey:"myValue"]])
// ...
void myMethod(data) {
log.debug "myMethod parameter: $data"
}
void runInMillis(Long delayInMilliSeconds, String handlerMethod, Map options = null)
delayInMilliseconds
- How long to wait until the handler should be called, don't expect that it will be called in exactly that time.
handlerMethod
- the name of a handler method in your driver or app. The method name should not contain parentheses.
options
- Optional values to control the scheduling of this method
overwrite
- defaults to true which cancels the previous scheduled running of the handler method and schedules new, if set to false this will create a duplicate schedule.data
- optional Map
of data to be passed to the handler method.misfire
- If set to "ignore" then the scheduler will simply try to fire it as soon as it can. NOTE: if a schduler uses this instruction, and it has missed several of its scheduled firings, then several rapid firings may occur as the scheduler attempts to catch back up to where it would have been.private processQueue(Map queue) {
if (isQueueEmpty(queue)) {
sendEvent name: 'lifxdiscovery', value: 'complete'
return
}
def data = getNext(queue)
sendPacket data.ipAddress, data.packet
runInMillis(queue.delay, 'processQueue', [data: queue])
}
runInMillis(50, 'processQueue', [data: queue])
void pauseExecution(Long millisecs)
millisecs
- The amount of time in milliseconds to pause.
Converts text to speech.
Map textToSpeech(String stringToBeSynthesized, String voice = null)
stringToBeSynthesized
- The text to be converted to audio. The text may contain supported SSML tags.
voice
- The name of a voice supported by Amazon Polly, you can find a list of voices here. If not specified the default system setting is used.
Map
- Returns a Map with two entries, uri
which contains a URI to the MP3 file and duration
is the length of the MP3 in seconds.
Returns a list of the supported text-to-speech voices.
Map getTTSVoices()
None
Map
- Returns a Map
with three entries: name
, which is the name of a voice that can be specified to textToSpeech
, gender
, which contains either Male or Female; and language
, which contains the language of this voice.
Date toDateTime(String dateTimeString)
dateTimeString
- A date/time string in ISO8601 format. ("yyyy-MM-dd", "yyyyMMdd'T'HHmmssX", "yyyy-MM-dd'T'HH:mm:ssX", "yyyy-MM-dd'T'HH:mm:ss.SSSX")
void schedule(String expression, String handlerMethod, Map options = null)
expression
- a 7-parameter Quartz cron string where the expression is: "Seconds" "Minutes" "Hours" "Day Of Month" "Month" "Day Of Week" "Year"
handlerMethod
- method to run at given schedule
options
- Optional values to control the scheduling of this method
// run 'mymethod' every tenth minute.
schedule('0 */10 * ? * *', mymethod)
// same with a parameter
schedule('0 */10 * ? * *', mymethod, [data: ["myKey":"myValue"]])
// ...
void mymethod(data) {
log.debug "mymethod parameter: $data"
}
String getObjectClassName(Object obj)
Object obj
: any objectThe name of the Java/Groovy class of which the specified object is a type (this is effectively an alternative to <object>.getClass()
that is allowed in the Hubitat sandbox)