Rule Machine Function

Platform Version2.4.0.151
Hardware VersionC-8

The documentation for creating a rule function in the Rule Machine uses screen shots instead of text. Since I am blind, this is not terribly helpful to me. I need to create a rule that returns a boolean value. And how do I create function parameters. This is what need.

F(device) = device.battery greater than 10 and device luminosity level greater than 850. The device in question is a motion sensor that also has a luminosity sensor. This function is an oversimplified version of what I am trying to do, but hopefully what I am trying to ask is clear enough. I believe that passing a device is not supported, so could that be a suggestion for a future release? One could use a pointer and then C language style casting to dereference the pointer to the actual device perhaps?

Most importantly, how do I return a value?

Konchog

Adding to the above, as you note, devices are not a valid variable type in Rule Functions (or hub variables on the hub or local variables in Rule Machine), so even with a Rule Function, you wouldn't be able to do exactly what you want.

You might be more interested in writing actual custom apps for the hub. These are written in Groovy. Rule Machine and some other apps exist so you can create custom automations without having to do this, but at some point, if you're pushing the limits of RM, it may be a good idea to look into.

If you still wanted to use a rule function for this: there is a special "Return value from Rule Function" action, available only to Rules configured as Rule Functions, available under the "Set variable, mode or file, run custom action" category. But I suspect another approach, perhaps the one suggested above, would be better for you.

Also, if you are talking about the Community post introducing Rule Functions, that has been updated with alt text for all the images in the original post now, so hopefully that i helpful. (It might not be--I think it was all explained in the text anyway, but this is something that should be there regardless.)

Good luck!

2 Likes

Ok. The problem here is that I need this to work for several devices individually in several different rules. Using the hub variable simply punts the test to a different variable. Instead of checking the battery level I have to check the hub variable. This does not simplify the code in any way.

MVDA, the screen reader I use does not parse alt.text. I switched to JAWS to read the alt.text, and I am still not clear on a few things--namely passing of parameters to the function. I would like to pass two parameters--the battery level and the lumens value. I found the way to return the value to the calling function.
How do I specify parameters in the call to the function and how do I parse them in the function itself?

You can only pass a single parameter, the name of a Hub Variable. Its value is available in the Rule Function as %param%.

1 Like

Thank you. You have given me a useful jumping off point from which I can write this fule function. At least I have a clearer understanding of the potential and limitations of rule functions, and I will experiment with this using your example as a starting point.

Thanks again.

3 Likes

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