Is it possible for an App to send a custom command to a Device

I'm very familiar with device drivers but this is my first foray into the Apps side of things. For my first project I'd like to be able to do some integration tasks with the device drivers I've already written.
Each device driver has a tasmotaCustomCommand button that takes two string parameters.

Would it be possible for an app to initiate this command with parameters across a number of devices. If so could someone point me to an example of this.

Everything I have found so far seems to be specific actions tied to known capabilities and usually enacted after subscribing to some kind of trigger. In this case there would be no trigger and it would not be a standard system command like on\off.

Any help appreciated.

This is absolutely possible, and it's no different from a "standard"/capability command--they're all just implemented as Groovy methods in the driver, and once you get a reference to the device(s), you can call that method like any command from a custom app. So instead of myDevice.on(), as it sounds like you may be used to, you call myDevice.customCommand(param1, param2) or whatever.

This assumes you know the basics of how to get a device reference in an app, which is done via an input where you have the user select a device. This is often done by capability (though there is a way to select for a specific driver if you really want), but the specific capability you use does not matter — once you get a reference to the device, you can call any command (and access any attribute) on it. Something like:

input name: "myDevice", type: "capability.switch", title: "Choose device"

If you add multuple: true, you'll be able to select multiple devices, and you'll get a list instead of a single object (technically a DeviceWrapperList instead of a DeviceWrapper), but you can call methods for commands directly on either type of object, so there shouldn't be any difference just for this.

Subscriptions are not relevant, as you do not need one to send a command. They are necessary if you want your app to wake (generally because you want it to do something) in response to an event from the device. Custom attributes work the same as "standard"/capability attributes here, too, however, should you need that for other purposes.

2 Likes

Thank you so much, that was a huge help and I now have a working skeleton sending commands to multiple devices. This is going to be big help.

[quote="bertabcd1234, post:2, topic:99592"]
This is often done by capability (though there is a way to select for a specific driver if you really want)
[/quote] I'm currently using this as my criteria for input as most devices are switches.
input "tswitch", "capability.switch", title: "Tasmota Switches" , multiple: true, required: false, defaultValue: null
Is there a way to populate list using the entire device list regardless of capability?

You have piqued my interest, can you point me to something?

Thanks again.

capability.* as the selector, but if you're depending on a specific command being there, this is probably not what you want..

device.DriverName as the selector, where DriverName is the name from the driver metadata (or how it displays in the "Type" dropdown) with spaces removed.

1 Like

duh, seems obvious now!!

This is for working with a series of drivers that I have written and they all support the same tasmotaCustomCommand so this option should work quite well.

Thanks again, this has been so helpful.

1 Like

Download the Hubitat app