Luligu / matterbridge-zigbee2mqtt

Matterbridge zigbee2mqtt plugin
https://github.com/Luligu/matterbridge-zigbee2mqtt/blob/main/README.md
Apache License 2.0
63 stars 8 forks source link

Problems with matterbridge-zigbee2mqtt.config.json on Docker installation #15

Closed KC-inDomus closed 4 months ago

KC-inDomus commented 4 months ago

Hi, installed Matterbridge using docker with this configuration:

  matterbridge:
    container_name: matterbridge
    image: luligu/matterbridge:latest # Matterbridge image with the latest tag
    network_mode: host # Ensures the Matter mdns works
    restart: always # Ensures the container always restarts automatically
    volumes:
      - "${HOME}/Matterbridge:/root/Matterbridge" # Mounts the Matterbridge plugin directory
      - "${HOME}/.matterbridge:/root/.matterbridge" # Mounts the Matterbridge storage directory

It works. Then, I installed matterbridge-zigbee2mqtt plugin, restarted Matterbridge, and it works too.

Problems arise when trying to configure the plugin. I created a matterbridge-zigbee2mqtt.config.json file on the correct path (${HOME}/.matterbridge) with this contents:

{
  "name": "matterbridge-zigbee2mqtt",
  "type": "DynamicPlatform",
  "unregisterOnShutdown": false,
  "host": "192.168.1.98",
  "port": 1883,
  "topic": "zigbee2mqtt",
  "username": "mqtt_user",
  "password": "MY_PASSWORD",
  "whiteList": [],
  "blackList": []
}

The mqtt broker address, username and password are right. When starting, matterbridge-zigbee2mqtt plugin gives:

[08:50:59.846] [Zigbee2MQTT] Error connecting to mqtt://localhost:1883: Connection refused: Not authorized

which suggests that config file hasn't be loaded. After checking paths, contents and so on, I tried several time: every time he uses "localhost" - not the right configuration. So I tried with:

docker exec -it matterbridge sh

and, in /root/.matterbridge, I found out the matterbridge-zigbee2mqtt.config.json which the plusin is using (despite my configuration), with this own contents:

{
  "name": "matterbridge-zigbee2mqtt",
  "type": "DynamicPlatform",
  "host": "localhost",
  "port": 1883,
  "topic": "zigbee2mqtt",
  "username": "",
  "password": "",
  "whiteList": [],
  "blackList": []
}

so I manually changed this configuration, saved the file, restarted the plugin... and again, "localhost" is used, because the file turns back to the original configuration as above.

No way to make the plugin use a different config. KC

Luligu commented 4 months ago

Hi, thank you for your interest.

The config files always "turn back to the original configuration" because you need to shutdown Matterbridge before.

The file inside and outside are the same.

From the readme.MD: You can edit the config file (shutdown Matterbridge before):

On windows:

cd $HOME\.matterbridge
notepad matterbridge-zigbee2mqtt.config.json

On linux:

cd ~/.matterbridge
nano matterbridge-zigbee2mqtt.config.json

Beside this I tried on my test machine with docker and I reproduced the error you described.

I will update you as soon as I understand...

KC-inDomus commented 4 months ago

Yes you're right: the configuration has been made with the Docker container stopped, so when you run it Matterbridge-zsigbee2mqtt should be able to load it up at startup, but it seems not working.

Luligu commented 4 months ago

I don't understand if is a mosquitto issue or a docker problem in general ... Try to run Matterbridge standalone.

KC-inDomus commented 4 months ago

I don't understand if is a mosquitto issue or a docker problem in general ... Try to run Matterbridge standalone.

It's not a mosquitto issue: the problem is that matterbridge-zigbee2mqtt@docker is not loading user personal, custom configuration, to let application uses the correct broker address/username/password.

Luligu commented 4 months ago

Hi, I found the problem. The image is made with Alpine, apparently it cannot resolve names. I made different tests and if you put the ip address it connects from inside like from outside the container. If you stop matterbridge and changes the config, when you start it again it reads the new parameters. So that's all.

KC-inDomus commented 4 months ago

I made different tests and if you put the ip address it connects from inside like from outside the container. If you stop matterbridge and changes the config, when you start it again it reads the new parameters.

that's precisely what I tried, but with no results: if you read on top in this thread, I placed the mqtt broker IP in the config: the prolem is that the application in the container seems not reading (and using) this configuration

Luligu commented 4 months ago

I have 3 MQTT broker, I switched between each of them running inside docker compose and standalone. It always changed the configuration and connected to the correct MQTT broker. BTW I added a debug in the next release that log the whole config. Any chance that you have an old raspberry arm/v7 or arm/v7? I need to test the image the arch...

KC-inDomus commented 4 months ago

Yes, got one. Tomorrow will do some tests

snakuzzo commented 4 months ago

I confirm what @KC-inDomus says. When I edit plugin config file, after a container restart, config file turns to original state and all changes are lost

This is my test... I've just changed the mqtt broker listen port...

snakuzzo@herobox ~/prova/provaAle $ docker exec -it matterbridge sh
/usr/src/app # cat /root/.matterbridge/matterbridge-zigbee2mqtt.config.json  | grep port
  "port": 1884,
/usr/src/app # 

Then...when I restart the container

snakuzzo@herobox ~/prova/provaAle $ docker-compose restart
[+] Restarting 1/1
 ✔ Container matterbridge  Started                                                                     5.4s 
snakuzzo@herobox ~/prova/provaAle $ docker exec -it matterbridge sh
/usr/src/app # cat /root/.matterbridge/matterbridge-zigbee2mqtt.config.json  | grep port
  "port": 1883,
/usr/src/app # 

My config file is overwrited and I've lost alla changes in my config file

Luligu commented 4 months ago

Hi, thank you for your message.

I will try to explain better:

This means that (as reported in the readme.MD) to modify the config you have to:

The command: docker exec -it matterbridge sh that you use implies that the container is running and so whatever you do on the config from inside the container or from outside (there is no difference) will be overwritten on shutdown.

This is the correct sequence:

docker stop matterbridge
cd ~/.matterbridge
nano matterbridge-zigbee2mqtt.config.json
docker start matterbridge

In the next releases will be possible to edit the config from frontend.

KC-inDomus commented 4 months ago

Hi,

This is the correct sequence:


docker stop matterbridge

cd ~/.matterbridge

nano matterbridge-zigbee2mqtt.config.json


docker start matterbridge

That's what I did, but the config won't load.

snakuzzo commented 4 months ago

I've tried just now... It didn't work. Config file is overwritten

snakuzzo commented 4 months ago

Ok...It works...my mistake. You have to:

If you edit file and then restart container, every change will be lost

So...you have to change file when software is not running

KC-inDomus commented 4 months ago

Ok...It works...my mistake. You have to:

  • stop container
  • change config file
  • start container

If you edit file and then restart container, every change will be lost

So...you have to change file when software is not running

yes, same here. Need to STOP, change, START. This could be misleading @Luligu

Luligu commented 4 months ago

I'm glad we solved the problem.

Can I ask to make a test please?

The image: luligu/matterbridge:dev is build with a new technique from the 20-bullseye-slim for linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6.

If you have any linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 can you try if it loads?

The dev contains already all the plugins installed (dev too for zigbee2mqtt) so do not install them just add them eventually.

Thanks

snakuzzo commented 4 months ago

On linux/amd64 ...

Attaching to matterbridge
matterbridge  | exec /usr/local/bin/docker-entrypoint.sh: exec format error
matterbridge exited with code 1
Luligu commented 4 months ago

Hi, thanks. With latest it works regularly on the same machine in the same conditions ?

snakuzzo commented 4 months ago

Yes... with latest I have no problems

Luligu commented 4 months ago

Hi, can you test again please?

snakuzzo commented 4 months ago

ok...now dev branch starts. I just added plugin (it is already installed, as you said)...but on restart it overwrites mqtt parameters in config file.

Luligu commented 4 months ago

image Now with the dev you see more info so there is no doubt about config. Thanks for the test.