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!

Can you put it here the print screen of the configuration? what is the full url ?

Did somebody reliably get this to work with just the local IP, so without TLS? I have six of the Smoke alarms and two got entities, but four just refuse to get any entities:

It’s super hard to debug this on the shelly side, as the logs don’t show anything about the websocket, not even on the devices that do have entities (AND get updates)… I guess I’m always just too late to see it in the logs, as the logs only streamed, so you only get logs whenever you open the page…

I’m using “TLS, no validation” and use the non-TLS websocket: ws://:8123/api/shelly/ws

I guess I did something different / in a different order for the two that worked, but I don’t know what… Maybe somebody found a way how to get entities for thos smoke alarms in HA without TLS…

Have you enabled debugging?

image

Good point, I only checked the Shelly side, but didn’t think about checking if HA maybe gets a WS connection. It indeed does and after a bit of more searching, I found that exact issue thread here: Shelly Plus Smoke configured but without entities · Issue #117818 · home-assistant/core · GitHub

Still not solved for me, but I’ll try poking what they meant with “resetting the HA” to make it work :smiley: