Trouble with Websocket_api

Sorry about the delay! I didn’t see your reply.

No, you shouldn’t need any additional configuration. When you tried the websocket.org page, did you see any error messages pop up in your logs?

Can you try the test again and then when you hit the connect button, look at your logs and see if any error messages pop up?

Hi @code-in-progress! No need for excuses! I’m grateful for all help I can get!

When I test:
ws://192.168.50.167:8123/api/websocket
nothing happens - it´s like I don’t have pushed the connect button.
The example: wss://echo.websocket.org work just fine. So it´s something wrong with my adress I guess. I have portforwarded 192.168.50.167:8123 in my router, so that shouldn’t be the error. Getting crazy here…

Welcome to HA? :wink:

You shouldn’t have to forward anything. The code on that page actually runs locally through javascript.

Ok. Let’s try another approach: On WebSocket API | Home Assistant Developer Docs there are three links near the top. Click on the Python link. It’ll open a new tab with some raw python in it. Copy that to a file on your local system and name it something like haws.py. Change the token in the line starting with ACCESS_TOKEN to use your token and change the line websocket = await asyncws.connect('ws://localhost:8123/api/websocket') to the IP address of your HA server. Then, run the file using python3 haws.py. If all goes well, you’ll see something like this:

Ok. I typed in the command in the Terminal in HA. This is what came out:
image

Try running pip install asyncio (you might need to run it as pip3 install asyncio) and then running the command again.

I did, and I even ran pip install asyncws.
This is the result:

Hmmmm… are you certain that the IP is correct? If that python code fails, then there’s no socket listening at that port. What IP do you use to hit HA in your browser? Is it the same?

Yes, it’s the same. Here is a snapshot of my browser:
image

Hmmmm, ok. Let me check a couple of things because that websocket should be opened by default.

1 Like

@code-in-progress - did any lightbulbs turn on above your head? :slight_smile:
Have a great day!

Hi. When I look in the Supervisor log, this is what I see:

`21-04-06 05:56:47 ERROR (MainThread) [asyncio] Task exception was never retrieved
future: <Task finished name='Task-48091' coro=<HomeAssistantWebSocket.async_send_command() done, defined at /usr/src/supervisor/supervisor/homeassistant/websocket.py:101> exception=TypeError('Received message 257:None is not str')>
Traceback (most recent call last):
  File "/usr/src/supervisor/supervisor/homeassistant/websocket.py", line 129, in async_send_command
    return await self._client.async_send_command(message)
  File "/usr/src/supervisor/supervisor/homeassistant/websocket.py", line 46, in async_send_command
    response = await self.client.receive_json()
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client_ws.py", line 291, in receive_json
    data = await self.receive_str(timeout=timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client_ws.py", line 276, in receive_str
    raise TypeError(f"Received message {msg.type}:{msg.data!r} is not str")
TypeError: Received message 257:None is not str`

Don’t know if it´s to any help to understand the problem…
I´m so greatful for any help. Thanks!
/Fanan

Fanan, i have almost the same error as yours in the supervisor log, and im not using any MSR service. So i dont think is something non related to that svc.

Too bad I don’t have any answers…

If I only knew why.

Hi @code-in-progress! Did you find anything?
My HA installation was on a VM on a PC. I the installed it on a RPi 4 - and that was ok as long as I didn’t restore a snapshot. Then it had the same issues.

From your browser screenshot, it seems you have https enabled. Is it correct?

If so, the protocol is wss://, and, as it seems you use some self-signed certificate, you have to be sure to ignore the certificate errors in whatever client.

Hi @koying! Thanks for your swift reply! That’s correct, I have https enabled.
I changed the protocol to wss (instead of ws). I got these errors instead:

2021-05-14T11:07:12.308Z <HassController:NOTICE> HassController#hass attempting reconnection to wss://192.168.50.167:8123/api/websocket/api/websocket
2021-05-14T11:07:12.309Z <HassController:NOTICE> HassController#hass connecting via WS to wss://192.168.50.167:8123/api/websocket/api/websocket
2021-05-14T11:07:12.367Z <HassController:WARN> HassController#hass websocket error during open/negotation: Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: IP: 192.168.50.167 is not in the cert's list:
2021-05-14T11:07:12.368Z <HassController:NOTICE> HassController#hass websocket to wss://192.168.50.167:8123/api/websocket/api/websocket closed during open/negotiation
2021-05-14T11:07:12.373Z <HassController:WARN> HassController#hass failed to connect/initialize communication: Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: IP: 192.168.50.167 is not in the cert's list:

Yep, that’s what I mentioned regarding your certificate being invalid :wink:

Is your certificate a “proper” one, with SAN (alternative names = host names)? If so, you have to use the actual hostname of your certificate in the url. IP will not be accepted.

Sorry for being a newbee… But how do I do to solve it?

What is the certificate you are using?
For the test, there is a way to disable SSL validation, but probably too much hassle for a test.

Check if "Multisystem reactor” has a way to disable “SSL Verification”

If it doesn’t, and that you don’t know your way around certificates, and that all your connections are local, probably easiest for you is to disable https in HA.

1 Like

Thanks!
I disabled https in HA, and that did the trick!