How to trigger a Rule or set a Variable via HTTP from another platform on the LAN?

Just need a nudge in the right direction from those that have done this.

Is this going offering a quick and dirty path to achieve either ?

https://docs2.hubitat.com/en/apps/rule-machine#using-rule-machine-from-http-requests

...or should I start digging in here?

From: Rule Machine | Hubitat Documentation

Using Rule Machine from HTTP requests

It is also possible to cause Rule Machine to perform these same actions from an HTTP request. To accomplish this, you would create a trigger event with either "Local End Point" or "Cloud End Point." The endpoint URL given by Rule Machine has a form similar to the following:

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

To run rule actions the above URL must be modified to include the list of rules and the action. The modification takes the following form:

/action=rule1&rule2&rule3

where action is the action from the list above and rule1&rule2&rule3 are the app IDs of the rules to run, separated by ampersands.

This parameter is inserted in the endpoint URL just before the ? that precedes the access_token as follows.

http://192.168.0.36/apps/api/10249/trigger/stopRuleAct=943&956&10217?access_token=ecd95469-bbcd-4889-a694-9b05ef80f4db

This example would do the same thing as the code example above, where 943&956&10217 are the app IDs that were selected by consequence of the input for theseRules, and stopRuleAct is the action to perform.

The app IDs are the values selected by the input described above, for example, theseRules. The app IDs can also be found for a rule by opening the rule and observing its appId in its URL as follows.

http://192.168.0.36/installedapp/configure/10249/mainPage

The app ID for that rule would be 10249.

Optionally, the value of the rule's built in %value% variable (normally set to the value of a trigger eevent) can be specified by providing a string instead of an action name, as with myValue in this example (note that this value must be URL-encoded and not conflict with the name of an action):

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

Both HTTP GET and HTTP POST to the above endpoints are supported, with the same outcome for either.

3 Likes

In case you need to set a hub variable instead of a rule's local variable, you can do that also. I just set this up a week or two ago to set hub variables based on changes to values on a Node Red dashboard.

I created a rule that is triggered by a local endpoint with no actions assigned to it. That app was app #1383.

I use this HTTP get to set the variable:

http://{hubitat.ip}/apps/api/1383/trigger/setHubVariable={variable_name}:{variable_value}?access_token={access token from the rule's local endpoint}

2 Likes

Thanks guys. Got the right direction now. Appreciate it.

EDIT ADD:
OMG was that easy stuff to work with!
I thought I was going to have to get deep into Maker API stuff.

1 Like

OK I'm still playing with this but how would YOU parse out the pieces of your URL for filling out the fields below,

http://{hubitat.ip}/apps/api/1383/trigger/setHubVariable={variable_name}:{variable_value}?access_token={access token from the rule's local endpoint}

I have http://{hubitat.ip}/apps/api/ set in as a configured Recipient which you can't see in this snapshot as it's just a blank Action at this point but that piece of the URL would be selected.

Haven't used this enough to know what of the rest is suppose to be "Message", vs say "Header" or "Body".

I would switch the method from POST to GET, as it's just simpler.

I'm not familiar with whatever system the screen shot is from, but the entire URL should be able to go in the recipient field. Switching to GET should hopefully make the message field go away.

You could put everything after the ? in the query string suffix field if it doesn't work in the recipient field.

Edit: the more I look at that form, the less I think that's designed to just call a URL. I was thinking that the message field was for the POST body, but then realized there is a separate body field. And the recipient field looks like a drop-down list. So where do you even put the URL? I'm not sure I can be of much help here.

Thanks for looking at this. Yeah the GET may be cleaner. The recipient field gets built in another screen.

I do get a URL composed after populating the fields but I get encoding and other artifacts that aren't as clean as the single line URL as you posted it (and as I generated and proved works in the browser from mimic-ing your example).

I'll keep playing with it. I figured those that code this stuff w/o a menu with fields to populate might know what's OK to put where. Reading about GET & POST formats is getting me there, kinda.

Well, I got it to work (as a GET) by just building the Recipient field out to the full URL as HE offers it in one string.

I know that can't be the only way to do this, each of those separate fields surely has it's purpose. I just have to learn what's what and how.

I don’t think you’ve really mentioned what your eventual goal is here. Other than what you wrote in the thread title.

Are you triggering a rule? Setting a variable to a specific value? Both?

The type of HTTP request you send, and the various details (including no details at all, potentially), will depend on what information you’re actually trying to send to the hub, and for what specific purpose.

1 Like