How to set up Z-Wave JS and Z-Wave JS Server

I’m trying to make the move from Domoticz to HomeAssistant and the first thing that needs to work is my Z-Wave network (locked in with ~40 switches, so this is definitely required…).

My setup is to have HA running in a Docker container on a Synology 1520+. In a second container on the same machine, I run Z-Wave JS Server (zwavejs2mqtt).

I set up Z-Wave JS Server first and this is working, all Z-Wave devices are found. The second step is to connect the Z-Wave JS integration with the websocket URL. This step fails. I followed all steps and tried all kinds of URLs (ws://localhost:3000, ws://192.168.2.201:3000 (the host URL), ws://172.17.0.3:3000 (the Docker internal URL), ws://a0d7b954-zwavejs2mqtt:3000 and I think a couple more).

The result is ‘Failed to connect to Z-Wave JS server’ and ‘Unexpected error’.

I tried all kinds of configurations on Z-Wave JS Server side, enabling/disabling WS and MQTT, but no result. What am I doing wrong? Should the Docker containers be linked? What should be the configuration of Z-Wave JS Server and which URL should be used in the Z-Wave JS integration?

The log shows this:

2021-02-12 16:30:18 ERROR (MainThread) [homeassistant.components.zwave_js.config_flow] Failed to connect to Z-Wave JS server: Cannot connect to host localhost:3000 ssl:default [Connect call failed ('127.0.0.1', 3000)]
2021-02-12 16:31:08 ERROR (MainThread) [homeassistant.components.zwave_js.config_flow] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/zwave_js/config_flow.py", line 56, in async_get_version_info
    version_info: VersionInfo = await get_server_version(
  File "/usr/local/lib/python3.8/site-packages/zwave_js_server/version.py", line 9, in get_server_version
    client = await session.ws_connect(url)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 754, in _ws_connect
    resp = await self.request(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
    return await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/zwave_js/config_flow.py", line 106, in async_step_manual
    version_info = await validate_input(self.hass, user_input)
  File "/usr/src/homeassistant/homeassistant/components/zwave_js/config_flow.py", line 45, in validate_input
    return await async_get_version_info(hass, ws_address)
  File "/usr/src/homeassistant/homeassistant/components/zwave_js/config_flow.py", line 61, in async_get_version_info
    raise CannotConnect from err
  File "/usr/local/lib/python3.8/site-packages/async_timeout/__init__.py", line 55, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.8/site-packages/async_timeout/__init__.py", line 92, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
2021-02-12 16:31:26 ERROR (MainThread) [homeassistant.components.zwave_js.config_flow] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/zwave_js/config_flow.py", line 56, in async_get_version_info
    version_info: VersionInfo = await get_server_version(
  File "/usr/local/lib/python3.8/site-packages/zwave_js_server/version.py", line 9, in get_server_version
    client = await session.ws_connect(url)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 754, in _ws_connect
    resp = await self.request(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
    return await fut
asyncio.exceptions.CancelledError

I am running zwavejs2mqtt on a remote raspberry PI. As I recall only had to configure 2 things. Expose port 3000 in the docker container and enable WS Server under the Home Assistant settings in zwavejs2mqtt.

Issue resolved. I was running Docker containers in Bridge mode. When switching to Host mode, it’s working.