Custom Component: Nikobus

Those last few days, I’ve been receiving feedback from the user community.

Thanks a lot, it helped detect and solve bugs. Now that the custom integration is “stable”. I will no longer introduce new features, but still solve bugs if any.

Next step is to make it an official integration and go for the first production ready release.

I’m very open to contributors and any other help and guidance, I will be working on my next official major release as time allows.

PS/ why official ? cause it allows me to learn on how to code in Python and apply best practices.

keeping you posted

1 Like

Thanks for writing a integration for Nikobus.

I’m a Openhab user and try to get Nikobus work in home assistant. I’m new to Home Assistant and so not very experienced.

I’ts not clear to me in what directory to put het “nikobus_module_config.json.default” file and rename it?

And after adding the Nikobus integration with /dev//ttyUSB0 port I get a message “instellen mislukt” (setup failed).

What do I do wrong?

Welcome to HomeAssistant.

So first step is to have your Nikobus config files for modules placed in /config

Rename the file from .default to .json

Please mind that for module, the address is not the same as in openHAB. if the address of your module is ABCD in HomeAssistant config file discussed above it needs to be CDAB. The integration uses the very same address as defined in Nikobus software.

Get that step started, no need to test with all modules. once done revert here if the setup is still failing with a debuglog.

Debuglog,
go to settings - integration - nikobus - enable debuglog
restart HomeAssistant
go to settings - system - logs - put a filter with “niko” then copy/paste the log with error here

By default there is no \config directory in home assistant. So create it?

There is one, that’s the default directory where you find for example your “configuration.yaml” and others HA files.

Check for config directory or configuration.yaml location in HA documentation or forum.

from: Configuration.yaml - Home Assistant

To find the configuration directory

  1. To look up the path to your configuration directory, go to Settings > System > Repairs.
  • Select the three dots menu and select System information.Show system information option
  1. Find out the location of the Configuration directory.Screenshot showing the top of the system information panel
  • Unless you changed the file structure, the default is as follows: -
    • Home Assistant Operating System: the configuration.yaml is in the /config folder of the installation.
    • Home Assistant Container: the configuration.yaml is in the config folder that you mounted in your container.
    • Home Assistant Core: the configuration.yaml is in the config folder passed to the hass command (default is ~/.homeassistant).

When I look for the Configuration directory location as mentioned indeed it is /config.

But I did create this directory by myself:

And in this directory there’s only one file:
image

This error originated from a custom integration.

Logger: custom_components.nikobus
Source: custom_components/nikobus/__init__.py:35
integration: Nikobus (documentation, issues)
First occurred: 7:51:57 PM (1 occurrences)
Last logged: 7:51:57 PM

An error occurred during connection setup: An error occurred loading configuration files: Module configuration file not found: /config/nikobus_module_config.json
Logger: homeassistant.config_entries
Source: config_entries.py:635
First occurred: 7:51:57 PM (1 occurrences)
Last logged: 7:51:57 PM

Error setting up entry Nikobus - /dev/ttyUSB0 for nikobus
Traceback (most recent call last):
  File "/config/custom_components/nikobus/nkbconfig.py", line 25, in load_json_data
    async with aio_open(file_path, mode="r") as file:
  File "/usr/local/lib/python3.12/site-packages/aiofiles/base.py", line 63, in __aenter__
    return await self
           ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiofiles/base.py", line 59, in __await__
    self._obj = yield from self._coro.__await__()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiofiles/threadpool/__init__.py", line 92, in _open
    f = await loop.run_in_executor(executor, cb)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/config/nikobus_module_config.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/nikobus/nikobus.py", line 55, in connect
    self.dict_module_data = await self._nikobus_config.load_json_data(
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nikobus/nkbconfig.py", line 29, in load_json_data
    self._handle_file_not_found(file_path, data_type)
  File "/config/custom_components/nikobus/nkbconfig.py", line 72, in _handle_file_not_found
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Module configuration file not found: /config/nikobus_module_config.json

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/nikobus/__init__.py", line 33, in async_setup_entry
    await coordinator.connect()
  File "/config/custom_components/nikobus/coordinator.py", line 66, in connect
    self.api = await Nikobus.create(
               ^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nikobus/nikobus.py", line 45, in create
    if await instance.connect():
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nikobus/nikobus.py", line 99, in connect
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: An error occurred loading configuration files: Module configuration file not found: /config/nikobus_module_config.json

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 635, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nikobus/__init__.py", line 36, in async_setup_entry
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: An error occurred loading configuration files: An error occurred loading configuration files: Module configuration file not found: /config/nikobus_module_config.json

What is your installation type ? docker ? HAOS ? other ?

Move your nikobus_module_config.json to the same directory as configuration.yaml

It’s an install on a X86-64 NUC machine.

So an HAOS install Generic x86-64 - Home Assistant ? not docker

Yes, no docker.

HAOS install is a standard Home Assistant install?

Is it finding the configuration file now ? you could also install samba as an addons to access and browse HA directories.

The config directory with Samba

Nikobus file is in it

Strange. When I browse in de file editor in HA I don’t see a config folder. Looks like the configuration.yaml is in the root.
When browsing Samba there is a config folder with the same files as in the root of de HA file editor.

Still getting this error ? or not ?

This error originated from a custom integratio

n.

Logger: custom_components.nikobus
Source: custom_components/nikobus/__init__.py:35
integration: Nikobus (documentation, issues)
First occurred: 9:03:23 PM (1 occurrences)
Last logged: 9:03:23 PM

An error occurred during connection setup: An error occurred loading configuration files: Scene configuration file not found: /config/nikobus_scene_config.json

Ha good, that’s something else. Looks like I forgot the make the scene file optional.

Just create an empty, nikobus_scene_config.json till I update the integration code so the file is optional.

Create an empty text file? In the Samba-config directory? Or should I create it somewhere in HA?