Stuck using RM API

I'm trying to add the RM API into one of my apps, but not having any luck. I've tried to follow @bravenel post Rule Machine API but must be missing something.

In my app...

Up top, I have the import command

Then my input...

and the handler...

Finally, the error in the log when it runs :thinking:

Hopefully someone will know what I'm doing wrong!
Thanks

It's probably because your RmRule input is a String value of "2482" and needs to be a numeric value.
Edit: @bptworld Try rmRule.toInteger() in your sendAction and see if that works.

Thanks. Didn't work... Same error.

I also tried this...

Edit: slightly different error

Hmm. I have this implemented in my ABC app but it's done in a roundabout way that you won't need. You can reference it if you think it would help. I don't have time to parse through it right now to see the difference. I will later if you haven't solved it by then.

Thanks, after I got stuck I actually looked at yours and at WATO but that just made me more confused! lol. Yours made sense but the differences didn't seem to make or break what I have done. Wato doesn't seem to be fully implemented. There is no way to choose what command gets sent.

Thanks again for trying!

The answer is actually in the error message, you are calling it with the first parameter as a String (or an Integer in the second example) but sendAction only accepts a List for the first parameter

Thanks. This is the example from the Rule Machine API post. Which is basically all I did. Still not sure where I went wrong?

Example:

 def rules = RMUtils.getRuleList()
 input "theseRules", "enum", title: "Select which rules to stop", options: rules
 RMUtils.sendAction(theseRules, "stopRuleAct", app.label)

Ahh...this isnt very clear in the Api docs linked in the OP,
@bptworld, just change the rmRule input line to multiple=true....and don't forget to remove the toInteger stuff :wink:

1 Like

BAM, that did it! lol. Thank you!

That's what I get for READING the official instructions! No mention of it anywhere, especially in the example. Oh well. :grin:

1 Like

Sorry for the confusion. Will explain better... All of it assumes that you can operate on multiple rules, hence the multiple: true and the list.

2 Likes

Would there be any reason why the code wouldn't work on one hub but does on the other?

Im cleaning out the RM rules on my first hub as I still got some Custom Actions laying around (which aren't visible in the list btw: RMUtils.getRuleList() ), but could that disturb the sendAction function lateron after selection of some other rules?

Do you mean Custom Commands? These should not cause any problems. You haven't provided enough information about what you're doing or what problem you're having.

Yes I mean custom commands, sorry for that,
I followed the exact road @bptworld was following just on my older hub its not working, and with it I mean the sendAction (on the older hub lots of rules in RM [from 3.0 all versions] and the above mentioned CustomCommands).
On my new hub (C5) I installed the same APP the same Rules to test with and it worked straight away (just 2 rules to play with).

I have no clue where to start, there is no error message to go on, apart from the sendAction it seems to work fine. I use the example as stated above just added the [multple: true] which makes the example work.

What information should I provide that would give a clue about what is going on with the older hub?