HA to Z-Wave JS connection resets when changing log configuration

I have Z-Wave JS server running stand-alone by a manual install. It works with HA just fine.

I was curious about getting log output from the NodeJS server, so I wrote a python client to communicate directly with the Z-Wave Node JS server to set/change the logging configuration. HomeAssistant is not involved in this. This is done by “Update the logging information” described in: https://github.com/zwave-js/zwave-js-server

This works: I can get the logging information from the server.

However, when this client sets/changes the logging configuration in the NodeJS server, HA chokes a little, and disconnects from the server and then immediately reconnects. Examination of the HA log file indicates that it doesn’t like the log level that I supplied from my python client to the NodeJS server.

Here is the relevant output from the HA log.

2021-08-09 10:33:20 ERROR (MainThread) [homeassistant.components.zwave_js] Unexpected exception: 4 is not a valid LogLevel
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/zwave_js/__init__.py", line 476, in client_listen
    await client.listen(driver_ready)
  File "/usr/local/lib/python3.9/site-packages/zwave_js_server/client.py", line 218, in listen
    self._handle_incoming_message(data)
  File "/usr/local/lib/python3.9/site-packages/zwave_js_server/client.py", line 315, in _handle_incoming_message
    self.driver.receive_event(event)  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/zwave_js_server/model/driver.py", line 51, in receive_event
    self._handle_event_protocol(event)
  File "/usr/local/lib/python3.9/site-packages/zwave_js_server/event.py", line 60, in _handle_event_protocol
    handler(event)
  File "/usr/local/lib/python3.9/site-packages/zwave_js_server/model/driver.py", line 61, in handle_log_config_updated
    event.data["log_config"] = self.log_config = LogConfig.from_dict(
  File "/usr/local/lib/python3.9/site-packages/zwave_js_server/model/log_config.py", line 46, in from_dict
    LogLevel(data["level"]) if "level" in data else None,
  File "/usr/local/lib/python3.9/enum.py", line 360, in __call__
    return cls.__new__(cls, value)
  File "/usr/local/lib/python3.9/enum.py", line 678, in __new__
    raise ve_exc
ValueError: 4 is not a valid LogLevel
2021-08-09 10:33:20 INFO (MainThread) [homeassistant.components.zwave_js] Disconnected from server. Reloading integration


Looks like you’re setting the level to a number, instead of a string? Have you tried setting a string, such as "silly"? Despite the typing described in the server message, it looks to me like the HA python client library expects the level to be a string, and sets it with a string. The driver LogConfig field is also a string, but accepts a number and converts it internally to a string.

Yes, I tried setting it to a text string in the configuration I supplied to ZWave Node JS server. The server converts the string to a number anyway, with the result that HA also chokes on the converted number. For example, when I set it to a string “info”, server converts it “2”. Verified by getting a read of the current log configuration directly from the server, after setting it.

The ZWaveNodeJS server documentation states that it requires a number, without saying what all the numbers mean, but I do get more/less verbose output based on whether I set it to 4 or 5.

Are you setting an appropriate schema version? It only converts the level to a number when dealing with very old schema versions.

I’m not sure what implications that has for multiple clients with different schemas. HA 2021.8 uses api schema version 7. I would stick to that version for the least amount of hassle.

@freshcoast The schema setting was my problem. I set it to my server’s latest version and that seems to prevent HA from disconnect/reconnect to server. Thanks.

It’s a bug in the server, thanks for the report.