Cannot connect Shelly H&T using websocket

I have a problem with connecting Shelly Plus H&T and Plug Plus S using websocket.

I am following this documentation: Shelly - Home Assistant

I have enabled the outbound websocket on my Shelly Plus H&T and on Plug Plus S and I have used the following settings:

TLS: Default TLS
URL: wss://my-homeassistant-domain:8123/api/shelly/ws

I am running Home Assistant with https and a calid certificate, therefore I have tried to change the URL to start with wss:// instead of ws://. I have also tried with ws:// with no difference.

When I restart my device and I look into diagnostics I can see:

mgos_rpc_channel_ws:269 0x3ffd4ac4 Connecting to wss://my-homeassistant-domain:8123/api/shelly/ws, SSL? 1
mgos_rpc_channel_ws.:54 0x3ffd4ac4 WS handshake resp 404

And the error repeats.

It seems that the endpoint for the websocket is not found on my HA installation, hence the 404 error.
I also get “Not found” error when trying out the URL in Postman.
I have tried to change the url to end with /api/websocket and I get the connection however the way that endpoint is implemented is not compatible with Shelly devices and I’m getting this error:

mg_rpc.c:516 0x3ffd4ac4 INVALID FRAME (856): '{"type":"auth_invalid","message":"Auth message incorrectly formatted: extra keys not allowed @ data['dst']. Got 'ws'\nextra keys not allowed @ data['method']. Got 'NotifyFullStatus'\nextra keys not a

The firmware on the Shelly Plus H&T is 0.12 and on Plug Plus S is 0.13.

I have also other shelly devices, however they are all Gen 1 and are integrated through REST API.

My HA version is 2023.2.4.

I have searched the web and the forum and I can see that people are able to connect their Shelly devices using the URL mentioned above, however it seems that my HA instance does not expose it. Is there a way to debug what websocket endpoint HA exposes?

Is there anyone else who tried to integrate Shelly Gen 2 devices with websocket in the 2023 HA version?

same here,
looks like entire /api/shelly is not available

Running 2023.2.5

I think I have figured out the problem.

It could have been Docker messing up the networking. Except of WebSocket endpoints being not accessible, I have also experienced some requests made from the Home Assistant container to be lacking some headers, which resulted in 400 errors when it was reaching the devices.

My solution was to ditch Docker and switch to the Home Assistant OS on Raspberry PI. Once installed, everything worked out of the box. No more problems with missing endpoints or modified requests.

searching HAss Shelly Websocket Errors brings this thread near the top.

I had this same symptom and had also followed the duckdns guide. The local IP would not work but using wss:// with my duckdns domain worked.

1 Like

Hello!

I’m experiencing the same issue: I’m running HA OS on a VM, and the sensor can’t connect to the Shelly websocket on the HA server.

@tentacle, did you also have your HA working on Docker? I don’t understand the solution that you applied to fix this. Could you please provide more details?

Thanks!