Creating a button in device/preferences

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:

Guess I'll just look at some community devices and piece it together.

You actually want the device definition docs for that, anyway. :slight_smile: 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