How to set a device parameter/value from an app

I'm trying to set the temperature of a thermostat from a app. I've read this post but apparently I'm too dense to glean all the steps.

I've read through the old ST docs and the Hubitat docs but I haven't been able to put all the steps together.

I'm guessing some variation of one of these is in the ball park

sendEvent(name: "coolingSetpoint", value: 24.5, unit: "F") // 76°F
setCoolingSetpoint(number)

but I haven't found how to relate a device to the commands.

I understand in a driver I can use the input code to tell the program what to "read"

input "tstatSet", "capability.thermostat", title: "Select Thermostat to Ctrl", submitOnChange: true, required: true, multiple: false

But I've not figured out how to create such a connection for an output.

Does someone have a simple example I can use to get how this should work?

Thanks
John

This will give you a reference to the device, and you can call commands on it like a regular Groovy method (the same way they are implemented, if you happen to be familiar with the flip side).

So, something like tstatSet.setCoolingSetpoint(75) is an example of a call you could make that would do what you want in an app.

This, on the other hand, is what you could do in such a driver to actually change the value of the reported coolingSetpoint attribute (in real devices, normally after a report for such is received; in virtual devices, usually just in response to a command since there's nothing "real" behind it).

Not relevant but thought I'd point it out since you might have tried. :smiley: (You actually can generate an event in the app too, but app events are very rarely used in Hubitat and it wouldn't affect any devices.)

1 Like

To add to this, the commands (methods) available on a device depend on its capabilities in the driver definition and are documented (along with the attributes) in the capabilities list you can find here:

That's a good reference!

For a specific device, the device detail page will also show you all commands and (usually, unless the developer failed to specify these for custom commands) parameters -- but technically the only ones you can count on being there for an arbitrary device are the ones required by the capability you used on the input type.

Thank you so much :slight_smile:

Would I be correct that the "input" in

input "tstatSet"

is really superfluous? And the function is only to get the device ID?

And (not being practical but) Is this the same device ID found in the UI? If so, in theory you could hard code the deviceID and have it work. I understand this would be ill advised, just asking to help me "sink in" the concepts/relationships.

Thank you. I've used that list for an app that reads the temperature and state of a thermostat. However I couldn't see how to setup a "write" to method.

Do you mean "can I get rid of input?" If so, no--it is absolutely necessary. It's kind of hard to tell given how Groovy allows the creation of domain-specific languages that can look a lot like English, but input is a method that is taking parameters (parentheses are optional but would also work and might make this clearer if you are used to other langues that require them: input("tstatSet", ...)).

No, you can't do much with the device ID. You need a reference to the device object itself (technically a DeviceWrapper, but you don't really need to know much about the class itself). The ID alone won't help, nor do you really need to know the ID to use the object.

This is part of Hubitat's user app security model: they can only work with devices the user (even if it's yourself) has directly selected via inputs in the UI, like the above.

1 Like

Thanks again :slight_smile:

I was unclear about the "input" question. My though was the inference by the word "input" is not technically correct. While I'm not advocating a change, I would think "assign" would be more intuitive than "input"

I think of it as building a declarative UI (years before such frameworks were popular): you are defining an "input" as displayed in the interface.

It helps me to remember that this is analogous to paragraph and href (other kinds of things you can display instead of inputs) and even the pages and sections in which all are (usually explicitly) contained. Or at least that's what I think. :slight_smile:

1 Like