[RestAPI] How to use actions

Hi,

I am trying to access and execute available actions through the RestAPI.
Unfortunately there seems to be no endpoint which exposes the registered actions.
Am I missing something?

Also under the VOICE endpoint there is no way to trigger a SAY command.
Was this forgotten or is this intentional?

Linkback


I suspect the two are related as the SAY command is an Action. Until very recently, Actions were still OH 1.x and maintained in the openhab1-addons repo. A lot of work needs to be made, including creating REST endpoints, for them and other parts of OH (e.g. Persistence configuration).

There is also a new way to do Actions for 2.x bindings where the Actions are now a part of the bindings (see MQTT 2) and to use them in Rules they have to be imported. See https://www.openhab.org/addons/bindings/mqtt.generic/#rule-actions. I’d not be surprised if there is no REST end point for these either.

While I know why you want these end points, I doubt that Actions as a concept have ever been considered to be used from anywhere but the Rules engines built into OH.

Exactly - or at least that was my impression.

Thank you for your quick reply - I have created two issues to track this since I believe this should be part of the Rest API provided by the core.

Were these issues ever solved?
Also looking for ways to call actions via rest api.

Here is the issue in case anyone is looking for it. https://github.com/openhab/openhab-core/issues/926

No - I use items mapped to channels instead of actions or use corresponding python libraries instead of bindings.

@Spaceman_Spiff, has there been any movement on getting actions incorporated into the REST API? I am waiting on converting about 1/3 of my Jython rules to HABapp because they are pretty heavy on action calls. (Mostly notification and Voice) I moved over to HABapp because of the threat of JSR233 dying on the vine (Jython anyways), but the HABapp docs say to make proxy items and JSR233 rules to make the action calls, which seems pretty circular, so for now I think I’m just going to keep my Jython rules until there’s an action-able (see what I did there?) solution. Looking forward to being 100% HABapp eventually though! Thank you for all your efforts.

In the mean time, one could implement the action by sending the arguments as json through MQTT, and create a rule on openhab’s side using rulesdsl, or something else. It would be a generic one that can invoke any built in actions or actions from any binding. It would work well for actions that do not return values.

For Transformation, Ephemeris, etc, using REST would probably be better since you’ll need the action’s return value.

I was thinking you could probably create a “HabAppBridge” add-on that facilitates this, amongst others.

Yes - it’s a bad workaround but that’s the only thing that’s supported out of the box atm.

What you always can do ist make the REST call directly. E.g. in the API explorer look at the actions and then create a rule that does make these calls.
You can use the self.async_http.get which provides an aiohttp wrapper.

It’s working on the openHAB side (or at least the endpoints are there).
However I still have to come up with a good concept how I can type hint the actions so that you get auto-complete and checks in your IDE.
Unfortunately my life is currently very busy, so this is something that will not come before summer, probably even later.

That would work or just use a proxy item and send a json there. No need to go over MQTT.

Or just use an existing python library for your notification service and skip the action altogether :wink:

Thanks for the very complete response. I didn’t realize that actions were available via the API. I’ll take a look at the API tool and figure out if making http calls to API would simplify my code at all. And, I’m looking forward to it being available in HAPapp, whenever that might be. If you need any help testing it, prior to all they type-hints being complete, let me know.

1 Like