OH3 and Tasker with Rest api - 405 error

Tags: #<Tag:0x00007efec7928b88> #<Tag:0x00007efec79289d0>

Hi all,

I am using Tasker from my android phone to communicate with Openhab. I use the http post function form Tasker. This worked well in OH2. Now I am seeing lots of errors like this in my Openhab logs:

2021-01-13 21:49:47.799 [WARN ] [s.impl.WebApplicationExceptionMapper] - javax.ws.rs.ClientErrorException: HTTP 405 Method Not Allowed
        at org.apache.cxf.jaxrs.utils.SpecExceptions.toHttpException(SpecExceptions.java:117)
        at org.apache.cxf.jaxrs.utils.ExceptionUtils.toHttpException(ExceptionUtils.java:168)
        at org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:514)
        at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:181)
        at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:78)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
        at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
        at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:220)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:852)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:544)
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1581)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1307)
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:482)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1549)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1204)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
        at org.eclipse.jetty.server.Server.handle(Server.java:494)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:374)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
        at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918)
        at java.base/java.lang.Thread.run(Thread.java:834)

I suppose that this error has something to do with the new security system in OH3. I am looking into authentication and api-tokens, but I am no security guru. I have not worked out how to make all my tasker tasks run properly again under OH3. Has anyone encountered the same problem?

One has to ask first of all why you are not using the openHAB plug-in with Tasker. If you install the openHAB Android App you can have Tasker talk to it instead of directly to the server through the REST API. Not only is it easier, you don’t have to do anything special to have it use the local URL when on your LAN and the remote URL when away.

It also does the authentication for you which is the problem here. OH 3 now has authentication and authorization in place and it uses OAuth2 by default. If you want to use simple username/password you have to enable basic auth. If you want to continue to use OAuth2, you can generate an authorization token and you will have to add that to the header of your request.

+1 to the Android app. I’m using it with no authentication on my home network, and I didn’t have to change anything in Tasker for it to keep working.

If you want, you can also use the Notification Listener plug-in to have Tasker respond to notifications from the openHAB Android app (or any app you choose). That enables you to receive commands sent by openHAB.

Good question. I had missed that this was now an option. My tasker-openhab communication just worked. No need to change anything. I will try the plugin.

1 Like

Tasker has a built-in feature to react to notifications, but Notification Listener is a bit more advanced. I use it to pick up the notifications from the OH app and then have Tasker immediately delete them, so that I never see them.

I use AutoRemote for that. I got the idea from Rich in this post:

I use it to say “Goodnight” to my Google home. That switches ON the GoogleGoodnight switch on openhab. That triggers a rule with a sendHttpPostRequest that way you can trigger AutoRemote calls. Tasker can respond to them natively. There is no ‘fixed’ notification, just a notification that is shown on your phone’s screen for about a second. No need to delete the notification. If tasker detects the incomming AutoRemote call, my phone turns on my alarm.

I’m pretty much doing the same thing, but using sendNotification with Notification Listener instead of sendHttpPostRequest with AutoRemote.

Notification Listener has a fixed notification, but you can turn it off on Android 9+ and it doesn’t impact the behaviour at all.