Rule Machine API

@bravenel couple of questions:

  1. when "runRule" action is triggered does it evaluate any rules specified and then perform the true or false action based on result of rules evaluation?
  2. when "runRuleAct" action is triggered does it always run the true action?

thank you.

Hi @bravenel I was wondering if something along these lines was possible. I would like to be able to pass in information from an outside call and either set a GV with the value or pass the attribute directly to a device driver.

Curious what your thoughts are. Thanks in advance.

Yes, it runs the true actions of a rule or triggered rule.

1 Like

I think this can be added to set a GV from an endpoint call. The value passed would be a string, and only a GV of type string would make sense. The string would be URL encoded, and then URL decoded into the GV. The GV could be passed as a string parameter to a driver using a custom action.

Would that work for you?

1 Like

This sounds about perfect. Thanks for the consideration!

This feature is now available in Rule 3.0, now released.

See [Released] Rule Machine 3.0 and the top post of this topic Rule Machine API

2 Likes

Wow now that is super fast service thanks as always @bravenel and hubitat team!!!

Trying to select cloud endpoint as a trigger gives me this error..

OK, we messed up and didn't turn on OAuth. Will get it fixed.

1 Like

I just updated he but it looks like itā€™s rule machine 2.5

They look the same until you set up Actions.

@bravenel

I am having some difficulty figuring this out. I am not sure If I have the url correct. I do seem to get a 200 response though the global variable never changes.

Here is the url

http://192.168.1.129/apps/api/2832/trigger/setGlobalVariable=test2:abcdefgh?access_token=461f117c-95ad-4d52-8136-asdfadefdasdf

I changed up the access token but otherwise that is what I am trying to use.

and here is the response my node server gets.

Status: 200
Headers: {"connection":"close","date":"Thu, 02 May 2019 03:58:45 GMT","content-type":"text/html;charset=utf-8","server":"Jetty(9.4.z-SNAPSHOT)"}

Using the getRuleList example does work with this same url.

Hmmm, that worked for me. Let me check.

Update: I found something amiss, and have a fix for it. Look at your logs and see if there is an error thrown.

app:28322019-05-01 09:33:04.624 pm errorjava.lang.NullPointerException: Cannot invoke method getAt() on null object (endpointHandler)

guess i should have looked there too....

Looks like this is working now @bravenel. Many thanks.

1 Like

Is there an event one can subscribe to know if a rule executed?

Not directly, no. Rules can throw events, but there is no subscription mechanism for those (haven't thought about this much -- perhaps it should be possible to subscribe to such events). This could be done indirectly of course using a virtual device set by the rule and whose events are subscribed to. The limitation at the moment are the available subscribe() methods, limited to device and location events.

Makes me also wonder whether these app events might not possibly be done as location events instead, thus allowing subscription to them.

So, the ability to subscribe to app events would be an addition to the hub core, while the latter would be a change to apps. Will look into this...

Lots of hair on this one: You'd want a way to subscribe to a specific rule (or app). As you know, internally apps have an appId that is used to reference them. So there would be the hurdle of getting an appId from a rule name or app name. RM has this very issue in offering things like Run Actions or Set Private Boolean of another rule, and so it handles this stuff in the parent.

As it stands right now, Rules do not in general tell the parent they have run.

I re-read the first post at least 3 times and miserably failed to see clear instructions as to how to get the access point to use with HTTP requests. Please help.

Set up a trigger event, either Cloud End Point or Local End Point, as appropriate to your use case. That will give you the link that you can right-click-copy.

Thanks for that, I completely misunderstood that sentence.
So now I guess I misunderstand the rest. I construct a url as follows,

http://192.168.1.113/apps/api/AAA/trigger/action=BBB?access_token=XXX
where AAA is the Local End Point event id, BBB - another rule id I want to run and access_token is the AT I got from Local End Point event.

When executing in the browser I get this JSON,

http://192.168.1.113/apps/api/849/trigger/action=417?access_token=9d1fb079-7eb9-45ad-b724-af448b0e08d4

"status": "success",
"country": "United States",
"countryCode": "US",
"region": "TX",
"regionName": "Texas",
"city": "xx",
"zip": "xx",
"lat": xx,
"lon": xx,
"timezone": "America/Chicago",
"isp": "xx",
"org": "xx",
"as": "xx,
"query": "my public ip"

}

Is that what I am expecting to see? I did not see any effect of executing that rule, i.e. no lights changed.