dJOS
September 8, 2023, 7:16am
1
Hi all, I’m the process of writing an application to manage irrigation valves, using weather station data and soil moisture sensors.
But, I’m having difficulty understanding how to subscribe to device drivers and use the data from them.
Can anyone please share some code with me that demonstrates how this works?
PS, I’m an idiot, so simple explanations (or nicely commented code), would be appreciated.
csteele
September 8, 2023, 8:01am
2
You begin by selecting devices. Apps can't talk to devices without being selected. So... now you have a list of devices that have some common Capability. Then, you subscribe to them...
def sensorPage() {
dynamicPage(name: "sensorPage") {
if (deviceType == "powerMeter") {
section ("<b>When this device starts/stops drawing power</b>") {
input "pwrMeter", "capability.powerMeter", title: "Power Meter" , multiple: false, required: false, defaultValue: null
}
}
}
def initialize() {
if (settings.deviceType == "powerMeter") {
subscribe(pwrMeter, "power", powerHandler)
}
}
All those are snippets from Better Laundry Monitor Child
2 Likes
dJOS
September 8, 2023, 8:12am
3
Thank you mate, I’ll take a look tomorrow morning when I don’t have a couple of scotch whiskeys onboard! (It’s friday night here in straya)
3 Likes
csteele
September 8, 2023, 8:16am
4
Auto_Off_child also has subscribe sprinkled in.
1 Like
dJOS
September 8, 2023, 8:23am
5
Cheers, this will be super helpful.
system
Closed
September 7, 2024, 8:24am
6
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.