Driver command with preset options


#1

Does anyone know how can I create a custom command that has a preset list of options to select from?
Something like the "setThermostatMode" in the Nest Thermostat driver:

Trying to create a driver for Sony Bravia TV to send commands like power on/power off, HDMI input selection and want to make it easier for the user...


#2

Here is an example from one of my Drivers...

        input("priority", "enum", title: "Default Message Priority (Blank = NORMAL):", description: "", defaultValue: "0", options:[["-1":"LOW"], ["0":"NORMAL"], ["1":"HIGH"]])

Hope this helps!


#3

Thanks! Isn't that for the preferences? I am trying to do it for a command and not for a preference though.


#4

I have a driver for the sony bravia TV that I ported from ST
I have disabled a lot of the commands because I actually only use on/off but the commands are only commented out (you could re-enable then should you wish)
If nothing else then it can be a starting point.

Let me know if you'd like a copy and I'll put it somewhere for you to download.

Andy


#5

Would love that. I am actually trying to retrieve the available commands from the TV. The Sony device has an interface that allows querying which commands that particular TV supports. Once retrieved, I want to make the commands available to the user. That is why I am looking for drop down list for the command button. That would make it so much cleaner, IMO.


#6

Give me a minute....
BRB


#7

Have a look here:

It has some extra code for an update I was working on but didn't implement on this driver because I didn't release it
I've just marked it so you can ignore that stuff :slight_smile:

Andy


#8

Thanks! Going to take a look at that. I guess you don't know either how the hubitat team managed to get the drop down list on the Nest Thermostat commands, right?


#9

I don't
but I would try creating the drop-down list in preferences and see if you can use the output from that


#10

Cobra's preferences schema will work, but the display will refresh on each entry selection. Not bad.

I believe the pulldown is define within the metadata commands. For fun, try the below code in a test driver then enter text in each of the three entry parameters. Execute and see results.

command "Test", ["On", "Off", "Really?"]

def Test(a,b,c) {
log.info a
log.info b
log.info c
}

def Test(a,b,c) {
log.info a
log.info b
log.info c
}

Raises some questions:

  1. How do I insert a pull-down in this line? (original question).
  2. Is it possible to range check an input within this line rather than code?
  3. Can I change the 2nd line of the displayed tile (currently a repeat of the top line or visa versa) within the command to indicate something useful?

Would be nice to hear from staff on this.


Tabular inputs (as in Thermostat Manager)
#11

I asked for details on this a while back. No response so far.


#12

See update here Requiring Fields for commands


#13

Thank you so much Patrick!!!