ZWaveJS gets a "serial port error" and "Cannot lock port" and looses entities on most devices

My ZWaveJS has stopped working 2 times and lost most of its info of all devices in the ZWave network over the last 4-5 days.

In the logs for Z-Wave JS to MQTT, it says:

21:59:50.384 DRIVER   serial port errored: Error Resource temporarily unavailable Cannot lock port
Unable to start driver [Error: Error Resource temporarily unavailable Cannot lock port]
[21:59:53] INFO: Successfully send discovery information to Home Assistant.

The last time it happens was today just after 05:02 in the morning. An identical issue is described here, but I don’t see any solutions:
https://www.gitmemory.com/issue/home-assistant/core/47429/793114459

The result is that most of my ZWave devices looses parts of their information or everything. This last time, all my devices is partly β€œcrashed” and have lost many if not all entities.

image

This is the versions I have:

Home Assistant core-2021.4.1
Z-Wave JS 0.1.17
Z-Wave JS to MQTT 0.11.0

The first time it happened, I had to do a β€œRe-interview” on all my nodes which was a 2 day job to get it all working again. Obviously as it has happened again, I now really need to find the root cause of this and fix it without doing this every time this happens.

I have pulled the plug, reinserted the Aeotec ZWave Gen5 Plus stick (the one compatible with Raspberry Pi 4), waited 10 seconds and inserted the plug again. On the second try, the β€œCannot lock port” went away, but unfortunately so did a lot of my entities of all my devices. Last time it was most of my devices.

Have any experience with this serious issue and maybe have a solution? I really would appreciate some help as this brings my smart house down on its knees.

1 Like

I thought the error was gone, but it now returned quite quickly again. This is from the Z-Wave JS logs:

2021-04-13T07:52:38.620Z DRIVER   serial port errored: Error Resource temporarily unavailable Cannot lock port
Unable to start driver [Error: Error Resource temporarily unavailable Cannot lock port]
[09:52:39] INFO: Successfully send discovery information to Home Assistant.
2021-04-13T07:52:41.261Z DRIVER   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—    β–ˆβ–ˆβ•—  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•—   β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—             β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
                                  β•šβ•β•β–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•‘    β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β•β•β•             β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β•β•β•
                                    β–ˆβ–ˆβ–ˆβ•”β•  β–ˆβ–ˆβ•‘ β–ˆβ•— β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—      β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
                                   β–ˆβ–ˆβ–ˆβ•”β•   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•”β•β•β•   β•šβ•β•β•β•β• β–ˆβ–ˆ   β–ˆβ–ˆβ•‘ β•šβ•β•β•β•β–ˆβ–ˆβ•‘
                                  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β•šβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘  β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—        β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘
                                  β•šβ•β•β•β•β•β•β•  β•šβ•β•β•β•šβ•β•β•  β•šβ•β•  β•šβ•β•   β•šβ•β•β•β•   β•šβ•β•β•β•β•β•β•         β•šβ•β•β•β•β•  β•šβ•β•β•β•β•β•β•
2021-04-13T07:52:41.270Z DRIVER   version 7.1.1
2021-04-13T07:52:41.271Z DRIVER   
2021-04-13T07:52:41.333Z DRIVER   serial port errored: Error Resource temporarily unavailable Cannot lock port
Unable to start driver [Error: Error Resource temporarily unavailable Cannot lock port]
[09:52:42] INFO: Successfully send discovery information to Home Assistant.
2021-04-13T07:52:44.077Z DRIVER   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—    β–ˆβ–ˆβ•—  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•—   β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—             β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
                                  β•šβ•β•β–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•‘    β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β•β•β•             β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β•β•β•
                                    β–ˆβ–ˆβ–ˆβ•”β•  β–ˆβ–ˆβ•‘ β–ˆβ•— β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—      β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
                                   β–ˆβ–ˆβ–ˆβ•”β•   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•”β•β•β•   β•šβ•β•β•β•β• β–ˆβ–ˆ   β–ˆβ–ˆβ•‘ β•šβ•β•β•β•β–ˆβ–ˆβ•‘
                                  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β•šβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘  β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—        β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘
                                  β•šβ•β•β•β•β•β•β•  β•šβ•β•β•β•šβ•β•β•  β•šβ•β•  β•šβ•β•   β•šβ•β•β•β•   β•šβ•β•β•β•β•β•β•         β•šβ•β•β•β•β•  β•šβ•β•β•β•β•β•β•
2021-04-13T07:52:44.086Z DRIVER   version 7.1.1
2021-04-13T07:52:44.088Z DRIVER   
2021-04-13T07:52:44.156Z DRIVER   serial port errored: Error Resource temporarily unavailable Cannot lock port
Unable to start driver [Error: Error Resource temporarily unavailable Cannot lock port]

I migrated away from OpenZWave a few months ago and that one has been removed, so all has been good for a long time until the last week or so when I upgraded to the latest versions of Z-Wave JS and Z-Wave JS to MQTT.

I restored the Z-Wave JS and Z-Wave JS to MQTT addons for 2 days ago when everything was guaranteed okay.

I restarted Z-Wave JS with success.
I restarted Z-Wave JS to MQTT, but the error β€œCannot lock port” turned up again.

I stopped both add-ons and started Z-Wave JS to MQTT first with success.
I then started Z-Wave JS and the β€œCannot lock port” problem appeared on this add-on instead.

It seems like these two plugins sometimes locks the Aeotec Z-Stick from being used by both add-ons. Is there something wrong in my config? It did work just fine for 3,5 months until I upgraded both add-ons a week ago.

You run 2 zwaveJS at same time? You can only run one addon

5 Likes

Holy crap. You’re right! That’s it. I can’t believe I managed to run like this for way over 3 months without ending up with problems. At the time I installed, I was sure the β€œZ-Wave JS to MQTT” was just a build needed on top of β€œZ-Wave JS”.

Thank you very much for your simple, but very helpful solution joselito1!

The restore brought back all the entities by the way.

3 Likes

I’m having this same issue. I’ve stopped and uninstalled the zwave js add on. Afterwards, everything works fine for a day or so, but the problem reappears. When I go into Supervisor, the zwave js add-on is back. Does anyone have advice on how to prevent it from being automatically installed by HA? Thanks in advance.

EDIT: after writing this, it occurred to me that activating the zwave js integration automatically configures the z wave js add-on. I decided to test what happens if I just stop the add-on and disable the β€˜start on boot’ option, but don’t uninstall it. We’ll see what happens. I’ll update this thread if it works.

I was also struggling with this issue.

Did not manage to just get one ZWAVE-JS(2MQTT) started. ZWAVE-JS every tim comes back even after deleting (HASSIO).

After updating ZWAVEJS2MQTT suddenly all nodes are gone; figured out that both addons are accessing the same usb device.

What I have done:

(1) switched the USB path of ZWAVE-JS to one unused
(2) rebooted HA
(3) double checked if ZWAVEJS2MQTT points to ws://a0d7b954-zwavejs2mqtt:3000?
(4) nodes back working again but ZWAVE-JS still running and reinstalling after deletion
(5) searched in core.config_entries (folder .storage)
for β€œ . β€œdomain”: β€œzwave_js”, (6) result:

  • β€œentry_id”: β€œa631a429cl65736473463cle53”,
  • 369 β€œversion”: 1,
  • 370 β€œdomain”: β€œzwave_js”,
    = core.1.config_entries .st… 1
    371
    β€œdomain”: β€œzwave”, = core.config_entries .sto… 2
    β€œdomain”: β€œzwavejs”, x β€œurl”: "ws://a0d7b954-zwavejs…
    β€œtitle”: β€œZ-Wave JS”,
  • 372 β€œdata”: {
  • 373 β€œurl”: β€œws://a0d7b954-zwavejs2mqtt:3000”,
  • 374 β€œusb_path”: β€œ/dev/ttyS0”,
  • 375 β€œnetwork_key”: β€œβ€,
  • 376 β€œuse_addon”: false,
    = core.device_registry … 114 377
    β€œintegration_created_addon”: false

β€œuse_addon”: was set at true; changed to false

(7) reboot
(8) done

if you do the same it is your risk! Do not mess up with core files!

For me after that all was fine.

Would appreciate if the config files were editable via HA UI.

To reconfigure the integration to use the zwavejs2mqtt addon instead of the official one:

In the HA UI, go to Configuration β†’ Integrations. Do not remove the existing Z-Wave JS integration. Click β€œAdd Integration”. Choose Z-Wave JS. Fill in the URL with the zwavejs2mqtt addon URl. Uncheck the box that mentions the supervisor or addon. If you don’t uncheck the check box, the official addon will continue to be started automatically. Click Submit. There will be an error message, but the existing Z-Wave JS integration will have been reconfigured with the new URL.

The integration will be re-configurable from the UI in a future release.

5 Likes

Did you solve this?

For a while I had openzwave but changed to zwave js. All is fine but two times per day I get the error message:

Serial port errored: The serial port closed unexpectedly!

It resolves when I either restart zwave js and reload the integration or reboot my raspberry pi.

I’m running 30 nodes with an Aeotec Zwave Gen 5 stick on a Raspberry4 (with USB2 hub).

Follow freshcoast’s instructions to fix it.

Thanks! Running for almost 24hrs now and no error from the serial port.

Another question: do I still need the zwave js add-on or is it enough with zwave js to mqtt?

Those two addons do the same exact thing, only difference is zjs2mqtt has a built in UI.
Keep zjs2mqtt for now.

Hi there, sorry for being a dolt…but where do I get the URL for zwavejs2mqtt add-on? Do i simply c/p the url out of the browser, or is it something different? Thanks for the help!

1 Like

Copy and paste it from the docs. https://github.com/hassio-addons/addon-zwavejs2mqtt/blob/38729339a3fc7b14a3d006cdda3a449886eac7c9/zwavejs2mqtt/DOCS.md#setting-up-the-home-assistant-z-wave-js-integration, or ws://a0d7b954-zwavejs2mqtt:3000.

2 Likes

The whole Zwave JS – ZwaveJS2mqtt squabble is a disaster. Just when I think it’s working, the port is reclaimed by Zwave JS. I know the group building HA is working to improve Zwave integration, but this should be a priority.

1 Like

A priority for what? The problem of having two add-ons installed is not an integration issue. You can only use one add-on at a time. Address that (solution in this thread and elsewhere) and you won’t have the problem anymore.

Auto-installing the add-on is really the root of the problem, but getting that removed seems like an uphill battle. The server reconfiguration could also be improved (doesn’t work if the server is offline), but there are no bugs submitted. So no one is currently looking to improve this.

Did you try to enable β€˜Disable DNS Discovery’ in the Zwave JS to MQTT add-on (Control Panel β†’ Settings β†’ Home Assistant)?

With 30 powered Z-Wave devices enabled, my entire Z-wave network has been down for several days. Z-Wave error 202. Nothing responds. I’m using a Zooz ZST10 with supposedly the latest firmware (7.17.2). Occasional β€œFailed to Connect” errors in the ZWaveJS Control panel. Unplugging, rebooting, moving around with extensions. I’ve done it all. Do I have a dud Zooz stick?

Do I tear down the ZWave network and start over. Start over from bare metal?

I’d much rather being playing with the fun stuff on HA, but I’m stuck on the basics of ZWave.

EDIT: Here’s a log of a recent error:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/zwave_js/switch.py:83
Integration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
First occurred: 6:50:56 PM (1 occurrences)
Last logged: 6:50:56 PM

[139752027216096] Z-Wave error 202: Failed to send the command after 1 attempts (Status Fail) (ZW0202)

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 193, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 1704, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1741, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 964, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 717, in _handle_entity_call await result File "/usr/src/homeassistant/homeassistant/components/zwave_js/switch.py", line 83, in async_turn_on await self.info.node.async_set_value(self._target_value, True) File "/usr/local/lib/python3.9/site-packages/zwave_js_server/model/node/__init__.py", line 446, in async_set_value result = await self.async_send_command( File "/usr/local/lib/python3.9/site-packages/zwave_js_server/model/node/__init__.py", line 403, in async_send_command result = await self.client.async_send_command(message, **kwargs) File "/usr/local/lib/python3.9/site-packages/zwave_js_server/client.py", line 103, in async_send_command return await future zwave_js_server.exceptions.FailedZWaveCommand: Z-Wave error 202: Failed to send the command after 1 attempts (Status Fail) (ZW0202)

And Another:

Source: components/zwave_js/__init__.py:188
Integration: Z-Wave JS (documentation, issues)
First occurred: 7:03:23 PM (1 occurrences)
Last logged: 7:03:23 PM

Failed to connect:

If you have both Z-Wave JS and Z-Wave JS UI addons installed, you need to turn off Z-Wave JS otherwise you’ll get this error.