What device methods can be accessed in Rules 4?

I'm thinking only methods that are associated with a pre-defined capability can be invoked in a rule.

Is that correct?

In my case, I need a custom driver, and a virtual device.

There's really not a device that maps well with what I'm doing, so in the driver code, I'll just pick a (pretty much arbitrary) capability and put the code I want executed in the rule in a method required for that capability.

Is that understanding correct?

Thanks

I don't believe it's legal to have a driver with no capabilities defined, but it's a bad idea regardless since most apps use capability-based selectors for devices, and so you'll run in to difficulties there. (Technically you can also select for devices by specific type/driver name, but I wouldn't normally do that. You can't do this in RM but could in a custom app.)

If you're writing a custom driver and don't have any attributes or commands that are good matches for the standard capabilities, you can use one of the "do nothing" capabilities, capability "Actuator" or capability "Sensor". Neither requires you to actually implement anything, though theoretically the former is intended for devices that accept commands (dimmers, switches, etc.) and the latter for devices that report attributes (most sensors)--but, again, it doesn't really technically matter. It just makes it possible to select the device by some capability, which is generally something you want for most apps.

Or if this is what you're asking instead: Rule Machine does not limit you to "standard" commands. There is an action called "Run custom action" that you can use to run any command (custom or even standard if you want to do it that way instead) on any device, as long as you can get the device selected. This selection is done by capability, so your driver does need to "implement" at least one.

Thanks!

There is an action called "Run custom action" that you can use to run any command (custom or even standard if you want to do it that way instead) on any device, as long as you can get the device selected. This selection is done by capability, so your driver does need to "implement" at least one.

Yes, this was what I was thinking I'd use. But the "command" needs to be one required for the capabilities defined in the driver for that device?

Maybe that's the definition of "command", versus the other user defined methods in a custom driver.

But, then I don't know what you mean by "standard" commands.

I think (sorry for being redundant):

The only user defined methods in a custom driver that can be accessed in a Rule action are those associated with a capability. Other methods in the driver can NOT be acccessed.

Easy answer, No.

There are two way of accessing a method in a driver:
a: A Capability has a set of standard commands. These commands are methods.
b. You define a command in the driver as a separate line. ile., command "ledOff' would call a method:

def ledOff() {
// method code
}

This could be called then via a rule as a custom action.

def ledOff() {
// method code
}

This could be called then via a rule as a custom action.

Ok, then I just can't figure out how to do it.

While defining an action in Rules, I select "Run .... custom action"

I get a pull down something like which action. Then I have to select a capability.

I can't figure out how to specify methods other than the ones needed for the capability.

In my specific case, I have a method send_ir(String, String) that's implemented in the driver for a virtual device. I'd like to call it with parameters from a Rule.

But, I can see how to do it using a method that's associated with a capability.

The driver supplies all of its published methods after you select the device.

The method must be defined as a Command in the driver to be visible.

That's not happening for me.

"defined as a command"

More than just the def like :

def ledOff() {
// method code
}

Maybe I missing how to publish a method?

Yes, you need a line like this in your metadata:

command "ledOff"

2 Likes

Thank you!

Download the Hubitat app