Rule Machine API

@bravenel does the RMUtils API allow the setting of hub or global variables? I see you can set them via endpoint trigger but hoping the RMUtils API allows this as well. If so what is the syntax to pass the variable name and variable value?

If I take your example above would expect something like the following:

def rules = RMUtils.getRuleList()
input "theseRules", "enum", title: "Select which rules to stop", options: rules
RMUtils.sendAction(theseRules, "setHubVariable", "varName:varString")
RMUtils.sendAction(theseRules, "setGlobalVariable", "varName:varString")

I'm not sure about "legacy" global variables, but hub variables have their own API (this is no longer an RM-specific feature), and documentation on them can be found here for the time being:

3 Likes

Would you kindly add this to the original post? Iā€™ve been spinning my wheels on this for hours. :cry: It might help somebody else in the future.

Thank you.

I'd suggest just looking at the documentation (which has, indeed, since been updated) instead:

https://docs2.hubitat.com/apps/rule-machine#rule-machine-api

2 Likes

I had seen that at some point last night but wasnā€™t finding it again. At the time I didnā€™t note the differences.

A link in the OP would be helpful if not an update.

Perhaps I'm mis-reading this aspect of the Rule Machine API docs, which explains how the following GET call can be invoked for triggering more than one RM rule at a time using HTTP:

http://[hub-IP]/apps/api/723/trigger/runRule=723&729?access_token=ca0199c9-618c-4203-9d9e-99xxxx

However, repeated attempts have only triggered the 1st rule (appid 723, which makes a lot of sense), but not the 2nd rule (appid 729). The response I get in the Web browser is:

{'result':'Triggered with runRule=723&729'}

...which, on its face, suggests that the intent was for both rules to be triggered. For the record, both rules include a Trigger of "Local Endpoint" and both work as expected when called with their respective RM URLs. Just not in tandem.

So I'm left with these questions, which I hope someone smarter than me can shed light on:

  1. Must each Rule contain a Trigger of type Endpoint in order to be executed by the runRule URL?
  2. Have I formed the multi-Rule calling URL correctly?
  3. Am I missing some other crucial setup for this construct to work?
  4. What is the format (if not JSON) of the response object? (I don't see a list of all possible Success and Error responses listed in the Docs, but didn't hunt far)

Appreciate any enlightenment on this obscure-but-powerful API.

Maybe:

http://[hub-IP]/apps/api/723/trigger/action=723&729?access_token=ca0199c9-618c-4203-9d9e-99xxxx 

action instead of runRule

1 Like

It's my understanding that action in this context is simply a placeholder word standing in for a list of potential actions, like runRule per the Docs. But I will try it ASAP, thanks!

RESULT: {'result':'Triggered with action=723&729'}
(and rule 723 ran while the other one did not, like before). Looks like the response( ) is just a recapitulation of the input string ingredients.

@bravenel trying to set a HV Boolean to try from a local endpoint read the instructions but I must be missing something

http://192.168.1.81/apps/api/8938/setHubVariable=StevenInBed:True?access_token=(the access token)

Where the variable is StevenInBed. Is this correct/ what am I doing wrong?

I will look into it...

1 Like

should be "true", not "True".

Also tried that before I put True. Still didn't work.

However the key thing is I'm on the correct lines?

No, your URL isn't right.

http://192.168.0.36/apps/api/10249/trigger/setHubVariable=StevenInBed:true?access_token=ecd95469-bbcd-4889-a694-9b05ef80f4db

2 Likes

If that is your actual access_token, you might want to delete it.

Some access token from a few years ago and some other hub. At this point, a meaningless string.

2 Likes

I should have know. :face_with_open_eyes_and_hand_over_mouth:

Hello!

I've been searching for some time but never found a solution to my issue:

Is it possible to read a local variable from a Rule Machine Rule as a JSON somehow?
I need to read it with my PC dashboard web page.

Thank you!

I'm not sure about with RM, but as an alternative, you could look at setting up a Hub Variable with a connector and adding the connector to the list of devices available via a Maker API instance.

1 Like