My goal is to write an app to read a temperature sensor & a humidity sensor, calculate the Dew Point and Heat Index. Then put the results somewhere a dashboard tile can access the data.
My understanding is the creation of a ChildDevice is needed to store each result. Is this correct?
Is there a way to store two results in one ChildDevice?
I envision the ChildDevice is only some code that creates an object in the data base where a number/text can be assigned.
In this line:
averageDev.setLux(avg)
I don't understand the assignment of a value to the ChildDevice. In the above line from the code at the end of this post appears to be setting the "averageDev" object to a value "avg".
What has me completely baffled is the " .setLux " modifier. Nowhere in the code are the letters setLux defined as anything. If it was just "set" I could see how it might be just an assignment modifier but I have no idea where "setLux" came from.
Below is an excerpt from Hubitat Example Code
def initialize() {
def averageDev = getChildDevice("AverageLux_${app.id}")
if(!averageDev) averageDev = addChildDevice("hubitat", "Virtual Illuminance Sensor", "AverageLux_${app.id}", null, [label: thisName, name: thisName])
averageDev.setLux(averageLux())
subscribe(luxSensors, "illuminance", handler)
}
def averageLux() {
def total = 0
def n = luxSensors.size()
luxSensors.each {total += it.currentIlluminance}
return (total / n).toDouble().round(0).toInteger()
}
def handler(evt) {
def averageDev = getChildDevice("AverageLux_${app.id}")
def avg = averageLux()
averageDev.setLux(avg) <<<<<<<<<<<<<<<<<<<<<<<<<<<<
log.info "Average illuminance = $avg lux"
}