steilerDev / homebridge-openhab2-complete

A homebridge plugin for openHAB, that has the expectation to fully support all Services offered by Apple's Homekit Accessory Protocol (HAP)
GNU General Public License v3.0
52 stars 16 forks source link

OH 3.0 partially working , test... #87

Closed grzegorz914 closed 3 years ago

grzegorz914 commented 3 years ago

Hi,

Connection and read from OH3 working correct but write and change state of items returned error:

` ==> /var/log/openhab/openhab.log <== 2020-10-15 16:31:58.953 [ERROR] [rg.apache.cxf.jaxrs.utils.JAXRSUtils] - No message body reader has been found for class java.lang.String, ContentType: application/octet-stream

==> /var/log/openhab/openhab.log <== 2020-10-15 16:32:00.462 [WARN ] [s.impl.WebApplicationExceptionMapper] - javax.ws.rs.WebApplicationException: HTTP 415 Unsupported Media Type at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1382) at org.apache.cxf.jaxrs.utils.JAXRSUtils.processRequestBodyParameter(JAXRSUtils.java:877) at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:822) at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:214) 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)`

hartmood commented 3 years ago

Same here.

hartmood commented 3 years ago

@grzegorz914 Did you find a workaround?

grzegorz914 commented 3 years ago

No,

right now I have removed openhab2-complete from homebridge and enabled HomeKit bridge in OH3.0.

hartmood commented 3 years ago

@grzegorz914 Thanks - that means what in terms of effort?

D-J-See commented 3 years ago

This fixed it for me - util/OpenHAB.js add an explicit header. https://github.com/steilerDev/homebridge-openhab2-complete/pull/92

     request({
         url: myURL,
         method: 'POST',
         body: command,
         headers: {
             'Content-Type': 'text/plain'
         }
     }
Mr-iX commented 3 years ago

This fixed it for me - util/OpenHAB.js add an explicit header.

92

     request({
         url: myURL,
         method: 'POST',
         body: command,
         headers: {
             'Content-Type': 'text/plain'
         }
     }

Thanks @D-J-See Do you also have the problem, that it takes quite a while until the status update is reflected in the home app with openhab 3?

Found it. In the startSubscription method the rest api must be changed from "smarthome" to "openhab"

D-J-See commented 3 years ago

Thanks @Mr-iX. I hadn’t noticed the slow update issue until you mentioned it. Thanks for the fix.

bananajoe86 commented 3 years ago

Have you guys any idea, how can HB update the Status? I use State-Sensors like Garagedoor, Window and Doors, but if the Items change in Openhab, in HB and Home the States doesn´t change.

D-J-See commented 3 years ago

@bananajoe86 If the behaviour is only since upgrade to Openhab 3, then @Mr-iX fix for startSubscription should work.

bananajoe86 commented 3 years ago

For me not. I changed it in startSubscription() { let myURL = this._getURL('/rest/events',topics=openhab/items/); const CLOSED = 2; But only when HB starts, the Status changes.

D-J-See commented 3 years ago

@bananajoe86 Did you update the second ‘smarthome’ string as well?

bananajoe86 commented 3 years ago

you are my hero, that´s it. Changing 2 times "smarthome" in "openhab". Now works perfect. ` startSubscription() { let myURL = this._getURL('/rest/events',topics=openhab/items/`); const CLOSED = 2; let source = new EventSource(myURL); source.onmessage = function (eventPayload) { let eventData = JSON.parse(eventPayload.data); if (eventData.type === "ItemStateChangedEvent") { let item = eventData.topic.replace("openhab/items/", "").replace("/statechanged", ""); let value = this._cleanOpenHABState(JSON.parse(eventData.payload).value); ``

D-J-See commented 3 years ago

@bananajoe86 Great!

bananajoe86 commented 3 years ago

I have fixed the two positions, but I'm not 100% satisfied yet. From time to time I find status messages always very delayed. As an example, I have a garage door, the gate was closed in the Openhab log, but in Home an HB Log it can takes 30 minutes since the message came. Has someone the same problem or any ideas?

blafois commented 3 years ago

Same here

Le lun. 15 févr. 2021 à 17:14, bananajoe86 notifications@github.com a écrit :

I have fixed the two positions, but I'm not 100% satisfied yet. From time to time I find status messages always very delayed. As an example, I have a garage door, the gate was closed in the Openhab log, but in Home an HB Log it can takes 30 minutes since the message came. Has someone the same problem or any ideas?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/steilerDev/homebridge-openhab2-complete/issues/87#issuecomment-779322287, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGT6OTQVPD3FCP3FASVD2LS7FB7FANCNFSM4SSCUCDQ .

-- Envoyé avec Gmail Mobile

grzegorz914 commented 3 years ago

Why You all not using native openHAB3 HomeKit

blafois commented 3 years ago

I migrated to HB while openhab was in version 2, and it was not stable/supporting enough accessories (2 Times a month all devices returned in default room). In addition I m still unsure OH3 supports homekit devices grouping (for exemple grouping ac thermostat and fan under the same Device)

Le lun. 15 févr. 2021 à 18:49, Grzegorz notifications@github.com a écrit :

Why You all not using native openHAB3 HomeKit

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/steilerDev/homebridge-openhab2-complete/issues/87#issuecomment-779372208, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGT6ORQCBP5MDJWI254Y63S7FNBJANCNFSM4SSCUCDQ .

-- Envoyé avec Gmail Mobile

eliempje commented 3 years ago

@bananajoe86

I have fixed the two positions, but I'm not 100% satisfied yet. From time to time I find status messages always very delayed. As an example, I have a garage door, the gate was closed in the Openhab log, but in Home an HB Log it can takes 30 minutes since the message came. Has someone the same problem or any ideas?

Did you also apply the content type fix? https://github.com/steilerDev/homebridge-openhab2-complete/issues/87#issuecomment-750314795

There is a cache process in the code in which each 5min for max 30min the status is checked. Only then the OpenHAB is queried. In the mean time the value can only be changed by the update originated from OpenHAB to the subscriber (via REST API) Homebridge.

Please check your log of OpenHAB, the rest api and the log of homebridge to check where the process stops.

eliempje commented 3 years ago

@steilerDev can you give any timeline when you would like to merge these changes? Do you need additional maintainers for your repository?

steilerDev commented 3 years ago

Hi @eliempje, I just merged the PR's into upstream. And yes, I have not found the appropriate time to maintain this properly. If you or someone else wants to help me maintain this, please let me know.

Tbh I never had a popular open source project, so I have no experience over collaboration here, any guidance would be appreciated :)

eliempje commented 3 years ago

@steilerDev I will contact you about this by email.

LeoFauSR commented 3 years ago

This fixed it for me - util/OpenHAB.js add an explicit header.

92

     request({
         url: myURL,
         method: 'POST',
         body: command,
         headers: {
             'Content-Type': 'text/plain'
         }
     }

I'm pretty new to OpenHAB and have the same Problem explained here. I would like to try this solution, but I can't find where to insert this code. Can you tell me where to find the right file? Thank you in advance :)

kolcun commented 3 years ago

I'm pretty new to OpenHAB and have the same Problem explained here. I would like to try this solution, but I can't find where to insert this code. Can you tell me where to find the right file? Thank you in advance :)

On my raspberry pi install the file is located here /usr/lib/node_modules/homebridge-openhab2-complete/util/OpenHAB.js

LeoFauSR commented 3 years ago

Thank you for your very quick response! I am running OpenHAB directly on my Windows system and I can't find a file called "OpenHAB.js" anywhere in my OpenHAB folder or on my computer. Does anyone have any experience with this setup?

D-J-See commented 3 years ago

Thank you for your very quick response! I am running OpenHAB directly on my Windows system and I can't find a file called "OpenHAB.js" anywhere in my OpenHAB folder or on my computer. Does anyone have any experience with this setup?

How are you running homebridge? If docker will be in the container.

LeoFauSR commented 3 years ago

I don't think I am running homebridge at all... Again, I'm very new to this. I just followed the installation tutorial in the OpenHAB documentation and started with the tutorials. I than found a guide on how to create a switch with three status options, which worked fine for creating but did not function the way it is supposed to. I am getting the discussed error message, when trying to use the switch. My other items, rules etc. that I created all work fine though.

steilerDev commented 3 years ago

@LeoFauSR you need another component besides OpenHab to use this plugin. That one is homebridge. Have a look there, follow their installation guide and install this plugin (homebridge-openhab2-complete). Homebridge will be the component communicating with HomeKit/your iPhone. This plugin will translate the HomeKit protocol to OpenHab and control devices from there.

steilerDev commented 3 years ago

Now included with the 1.3.0 release.