[Feature Request] Get return value of Custom Functions

Driver programming and using it in Rule Machine...

I can create a custom command that returns a value; At least it compiles this:

def doThis(param) {
log.info param + param
return param + param
}

And when I create such a device I can click on the command "doThis" to execute it (as the log proves).

But how can I call such functions from Rule Machine and use the returned value?

"Run Custom Action" allows only to execute a driver command, without any chance to get the value; And "Set Variable" does not offer the use of Custom Actions...

@bravenel, do you have any idea to accomplish such mission?

Give your driver Actuator capability.

Thanx, done,

But I still cannot find any possibility to get the return value of this drivers' function... :thinking:

Define an attribute. Dominic Meglioā€™s (@dman2306) port of the Litter-Robot driver shows a good example.

https://raw.githubusercontent.com/dcmeglio/hubitat-litterrobot/master/devicetypes/natekspencer/litter-robot.src/litter-robot.groovy

Thanx again, but in Dominic Meglioā€™s example there are no functions defined:
None of his Attributes uses parameters (IMHO according to the specification it's not allowed), and also none of his Commands. :thinking:

If you think about using an Attribut to only return the value of a previous called Custom Action: That would not be reliable, because of the concurrent executions of such methods. :cry:

AFAIK, thatā€™s the only mechanism I have seen.

1 Like

Nevertheless, thank you very much for your help! :+1:

I adjusted the subject to an feature request...

Will you describe a use-case for this functionality? It may be possible to find a workaround, but it would help to understand why you are asking for this functionality.

I am currently working on utility devices, which among other things allow (almost) any calculations.
But of course the usecases for such a feature would be endless...

Thinking of ideas to work around the limitations:

Could you pass a caller-specified UID as a parameter to the command and then update an attribute with the response, embedding the UID and the result in a way that could be tokenized by this feature for further interpretation?

It would require a pair of RM rules to send the command and observe a change on the attribute for each response.

1 Like

Thanx a lot for all your ideas. In fact there are some (but quite cumbersome) possibilities.

That's exactly what I want to reduce! :wink:

The attribute is where the value is stored in the driver. This is the result of a sendEvent. A command is where the math is done, and those take parameters. So, RM calls a Custom Action for the device, passing the value as a parameter. The command method does the math and puts the result in the attribute using sendEvent. RM can Wait for Conditions with a Custom Attribute changed, thus getting the result back in %value%.

But that would not be reliable, because of the concurrent executions of such methods.

E.g.: Rule1 as calling this device with param1, in the same time is Rule2 calling this device with param2. Who gets result1, and who result2?

A concurrent function should never change the state of an object!

LOL. Can't help you when you want to do things outside the design envelope.

Therefor it's called a "Feature Request". :wink:

Something like
Set xVar to yAction(1+2*3) on zDevice
would be enough.

There is no way to do that. Device commands don't return values....

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.