I have this working:
definition(
name: "Security",
namespace: "hubitat",
author: "Bryan LaMarca",
description: "A Security App",
category: "Convenience",
iconUrl: "",
iconX2Url: ""
)
preferences {
page(name: "mainPage")
}
Map mainPage() {
dynamicPage(name: "mainPage", title: "Security", uninstall: true, install: true) {
section {
input "appName", "text", title: "Security Instance", submitOnChange: true
if(appName) app.updateLabel(appName)
input "tempSensors", "capability.temperatureMeasurement", title: "Select Temperature Sensors", submitOnChange: true, required: true, multiple: true
}
}
}
void updated() {
unsubscribe()
initialize()
}
void installed() {
initialize()
}
void initialize() {
tempSensors.each {
log.debug "Temp: " + it.currentTemperature
}
}
Mainly copied from example code. The question is, where do I find "it.currentTemperature" or any other values? The documentation only gives me this:
TemperatureMeasurement
Device Selector
capability.temperatureMeasurement
Driver Definition
capability "TemperatureMeasurement"
Attributes
temperature - NUMBER, unit:°F || °C
Commands
To clarify, when run the tempSensors.each loop, what can I get from it? We know it.currentTemperatue, what else?
What you need to know, and I'm not sure is documented, is that .currentTemperature
is shortcut for .currentValue("temperature")
when you're dealing with a device object, as you are here. The currentValue()
method is documented, but the purpose is to get the value of the attributes you can see under "Current States" on the device page. For a device that implements the TemperatureMeasurement
capability, as you posted above, you can see that the temperature
attribute should be one of these. (It's likely your device implements other capabilities and may have such attributes, but this is all we can say for sure for a device where only this capability is known.)
Any of other other methods/properites on the device object (technically a DeviceWrapper
or, here, a DeviceWrapperList
that you are iterating over with each()
and getting the individual DeviceWrapper
objects) can also be used: Device Object - Hubitat Documentation
1 Like
The other available values will depend on the device’s capabilities and the attributes made available by the driver you use for each device. For example, a 6-in-1 sensor will have different attributes available than a 4-in1 sensor, or a weather station. If you use the 4-in-1 driver for the 6-in-1 device you will only see the four attributes exposed by the driver.
1 Like
So I did this:
tempSensors.each {
log.debug "Temp: " + it.getCurrentValue("temperature")
}
and now I am getting this:
java.lang.IllegalArgumentException: Command 'getCurrentValue' is not supported by device 323. on line 52 (method updated)
Sorry, I make that mistake all the time when writing the method off the top of my head: it's currentValue("attributeName")
. So, it.currentValue("temperature")
should fix that problem.
1 Like