Hi folks, I'm hoping someone could offer me some help as I try to figure out some custom devices with limited programming experience. I have a device and custom driver that works, but on occasion I would like the ability to send it a command which in effect resets an internal calibration. Currently I have it kind of hacked together in that I made a preference that passes the number it's set to to the device in an awkward "set this to 1 to recalibrate then set it back to 0 afterwards" arrangement. Of course it doesn't need to be a number setting, just a custom "recalibrate" button that sends the device a message would be better for this.
I would prefer the buttons be in the device preferences/edit device area rather than being a function of the device itself, eg I'd rather it be on the bottom of the device page and accessible through the preferences area rather than being on the top like "on, off, recalibrate" as I don't expect it be using it very often.
How can I replace my "set recalibrate preference to 1 and then back to 0 to recalibrate" with a regular button that just recalibrates?
I know this isn't what you said you wanted to do, but I would use a command for this for a few reasons. First, it seems like a literal command to me: an action that performs something for the device or at least the driver. Second, that is the only way to get a "button" on the device page for this: those are just lists of commands (and the button provides a way to manually execute them)--there is no "button" input type (ST docs, but same idea) for preferences, nor would it really make sense to be since those are just ways to save things to the settings
Map. Third, commands are the only way apps have to automate devices, so this would allow a user to, for example, make a Dashboard tile that can do this (via a virtual button or something) or automate this via a rule or other app should they desire. Finally, the device page isn't really intended for day-to-day control of devices--just a "quick and dirty" way to manually run commands as well as a way to set preferences, rename the device, change drivers, or other things that are often only done when setting up the device or testing (an app or automation is generally how devices are controlled, and Hubitat's recommended solution for manual control is Dashboard or a similar offering).
Not being a developer myself (but being pretty tech savvy and having smashed together some drivers and such before successfully), I wanted to check out documentation on implementing a custom command, but lo, there is none:
https://docs.hubitat.com/index.php?title=Command_Object
Guess I'll just look at some community devices and piece it together.
You actually want the device definition docs for that, anyway.
Device Definition - Hubitat Documentation
Inside the definition
in your metadata
, you just specify something like this for a command if it takes no parameters:
command "myCommandName"
This just requires you to have a Groovy method matching that command name in the driver, for example:
void myCommandName() {
// do things
}
Hubitat as a few example drivers on their GitHub. One I know of with custom commands is the Iris v3 keypad driver if you want to see this in the real world: HubitatPublic/irisKeypadV3.groovy at master · hubitat/HubitatPublic · GitHub
I just stumbled on this old thread... did you ever solve it? There are several ways to get data into a driver from a dashboard.
- Add the Momentary capability, and then provide a push() method to do what you want from the button tile you put on the dashboard (leave button number blank on the button tile)
- Add the PushableButton capability, and then provide as many buttons as you need for dashboard control, implementing a pushed(number) method to do any commands based on the button pushed
- Add the Variable capability, and create a variable attribute. Then have your app subscribe to the variable attribute, and use the Variable String template input on the dashboard to update it. I use this to enter a simple map that gets parsed out for what I want to do in the app. Example: [CSP: 70, HSP: 72] when sent from the string variable tile gets parsed by the app when saved, to set the cooling setpoint to 70, and the heating setpoint to 72, calling the set methods for those in the driver from the app.
- You can also use a variable tile like above, but as a multiple value input, combined with a button. So a button can be "set heating setpoint" and when pressed, it takes the current value from the variable tile, and sets the attribute based on that. You can have several buttons that pull the current variable attribute value to set something specific to a value.