Rule Machine API

@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.

This one is too complex. A simple variant:

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

That's going to do a stopRuleAct against rule with appId 943. And that is triggering a rule with appId of 10249.

What action are you trying to do? "action=417" isn't right. It has to be one of these:

Ah, that's much clearer. In the initial post since these all are over the post I didn't connect the dots that /action=XXX where action should be replaced with one of those. Okay, fair enough.

Ok so I have the following Rule with a trigger (850)

Then I have a rule to run (436)

So I construct this URL

http://192.168.1.113/apps/api/850/trigger/runRuleAct=436?access_token=xxx

and get this response
{

  • error: true,
  • type: "java.lang.Exception",
  • message: "An unexpected error occurred."
    }

In the hub logs there's this msg,

app:8502020-10-17 07:46:38.062 pm errorjava.lang.NullPointerException: Cannot invoke method getAt() on null object on line 7182 (endpointHandler)

1 Like

OK, Hard to tell what caused that. Had you hit Done in both rules?

Separate question: Why are you trying to do this from an end point in the first place. Why not just have the rule with the End Point trigger run the action of the other rule?

Yes, both are done rules.
What I am trying to do is to replace my webCore pistons with Rules. For webCore pistons I have endpoints exposed, so that I can trigger them from my phone using Tasker. So that's exactly what I am trying to replicate with the Rule Machine. Are there better ways to achieve that?

You can just trigger a rule with an end point. You don't need the rest of this.

1 Like

I do this, using this

You just copy the end point from the rule once it's creates one and paste it to taskers as a task event.

1 Like

Okay, I just wanna make sure I understand what you both are saying... Here's a Rule that I want to trigger from Tasker. Where is its endpoint and how do I retrieve it?

Create a Trigger Event for Cloud End Point. I showed that above in a screenshot.

Since you are doing this for a Tasker Profile, I recommend creating rule on phone instead of computer. Then you can right click on End Point in Trigger, Copy, the Paste into Tasker without having to type out the End Point.

So every Rule that I want to call remotely needs a cloud and/or local endpoint? Is that how they get exposed?

Yes. They can have other Trigger Events also.

1 Like