Zigbee2MQTT @ OpenHab

Flashed firmware from Zigbee binding page, same things
Controller works, but I can’t find how to search for new devices (or its all working and my Aqara device doesn’t match or something.

Installed Z2M on test RPI and its able to pair devices.
So, I guess i’ll go this path

Hi! You dont need Zigbee binding…
Install openHAB, mqtt, Z2M, add Z2M user to tty and dialout groups so it can use your usb dongle.
Then configure openHAB and Z2M to use same mqtt broker, all guides on how to configure Z2M(mqtt, adding devices, flashing dongle) are avaliable at https://www.zigbee2mqtt.io/
After that you will be able to see devices in mqtt topics via MQTT Explorer and configure openHAB to control them.
Zigbee binding is cool, but it was not able to work with many devices(xiaomi, aqara, mija) when i gave it a try.
If you are stuck with something specific, feel free to ask, i use it for year and a half, it works quite good.

I actually just finished re-installing everything on Rpi4 last night, with dockers

Hi Everybody,
I set up OpenHab 3.4.1 with a Sonoff Zigbee Dongel.
Everything was working fine Zigbee2MQTT, MQTT Explorer, Mosquitto and I was able to connect all my Zigbee Devices.

Then I had a power outage and my Raspberry Pi 4B hat to restart. Now I am not able to open the Zigbee2MQTT Mask anymore over http://IP:8081

If i ask for the status of zigbee2mqtt.service or mosquitto.service via putty it both gives me the status “active”.
Also MQTT Explorer shows state “online” via Listener 1883.

Does anybody had the same issue and knows a solution?
Thanks

Check your Zigbee2MQTT configuration.yaml for fontend settings: Frontend | Zigbee2MQTT

Restart and check the logs.

# Stopping Zigbee2MQTT
sudo systemctl stop zigbee2mqtt

# Starting Zigbee2MQTT
sudo systemctl start zigbee2mqtt

# View the log of Zigbee2MQTT
sudo journalctl -u zigbee2mqtt.service -f

To run Zigbee2MQTT as daemon (in background) and start it automatically on boot we will run Zigbee2MQTT with systemctl

I second that @anon71759204 said. Zigbee2mqtt has a frontend that you can view in a browser.

To enable the frontend add the following to your configuration.yaml

Add below to your configuration

frontend:
  #  default 8080 change as required 
  port: 8080

Hey Thanks for the quick reply I think I am already a step closer to finding the solution.

So I adjusted my “zigbee2mqtt.service” as described in the link.

My “configuration.yaml” has the input

"
frontend:
  port: 8081
"

I think this is ok right? Because this is my Port for zigbee2mqtt.
With Port 8080 I open the openHAB UI.

After viewing the log as described I got the following error message:
sudo journalctl -u zigbee2mqtt.service -f


Started Zigbee2MQTT.
> zigbee2mqtt@1.30.0 start
 > node index.js
Error: EACCES: permission denied, mkdir '/var/log/zigbee2mqtt'
at Object.mkdirSync (node:fs:1382:3)
at mkdirSyncRecursive (/opt/zigbee2mqtt/node_modules/mkdir-recursive/index.js:199:16)
at mkdirSyncRecursive (/opt/zigbee2mqtt/node_modules/mkdir-recursive/index.js:197:12)
at mkdirSyncRecursive (/opt/zigbee2mqtt/node_modules/mkdir-recursive/index.js:197:12)
at Object.mkdirSync (/opt/zigbee2mqtt/node_modules/mkdir-recursive/index.js:82:10)
at Object.init (/opt/zigbee2mqtt/lib/util/logger.ts:43:12)
at new Controller (/opt/zigbee2mqtt/lib/controller.ts:53:16)
at start (/opt/zigbee2mqtt/index.js:106:18)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
zigbee2mqtt.service: Main process exited, code=exited, status=1/FAILURE
zigbee2mqtt.service: Failed with result 'exit-code'.
zigbee2mqtt.service: Consumed 6.411s CPU time.
zigbee2mqtt.service: Scheduled restart job, restart counter is at 7.
Stopped Zigbee2MQTT.
zigbee2mqtt.service: Consumed 6.411s CPU time.

So I guessed zigbee2mqtt.service had no permission to create a folder.
I created the Folder ‘/var/log/zigbee2mqtt’ by hand.
Afterwards the Error Message changed to

Error: EACCES: permission denied, mkdir '/var/log/zigbee2mqtt/2023-02-02.17-06-53al'

So one step closer I guess. I hope granting permission to zigbee2mqtt.service should do the trick?!
But how? My guess is:

cd /etc/systemd/system/
sudo chown openhab:openhab zibgee2mqtt.service

I did not try it jet because I was not sure. Can anybody confirm that I will not further damage my system :slight_smile:

Thanks in advance

This is not much help but i installed Zigbee2Mqtt via openhabian today and it installed straight away and even recognised the type of dongle i had. It was super easy. No configuration required.

Are you on openhabian.

What user are you user in the service?

User=pi

Or

User=openhabian

user=openhabian

Whole file:


[Unit]
Description=Zigbee2MQTT
After=network.target

[Service]
Environment=NODE_ENV=production
ExecStart=/usr/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit
# Or use StandardOutput=null if you don't want Zigbee2MQTT messages filling syslog, for more options see systemd.exec(5)
StandardError=inherit
Restart=always
RestartSec=10s
User=openhabian

[Install]
WantedBy=multi-user.target

Can you try

chmod -R 777 /opt/zigbee2mqtt
  • so it is the “same” error again but now one level deeper into the directory
  • who is the owner of /var/log/zigbee2mqtt ?
    Needs to be chown openhabian:openhab /var/log/zigbee2mqtt

What should be the epxected result ? All files will be writeable for everyone.

Thank you so much. I changed the ownership of the direcotry as you said and it worked.

So my steps were:

$ sudo systemctl stop zigbee2mqtt
$ sudo systemctl start zigbee2mqtt
$ sudo journalctl -u zigbee2mqtt.service -f

I got the Error Message: “Error: EACCES: permission denied, mkdir ‘/var/log/zigbee2mqtt’”

I created the folder myself with
$ sudo mkdir /var/log/zigbee2mqtt’

Then changed the ownership of the directory as @Wolfgang_S suggested with:
$ chown openhabian:openhab /var/log/zigbee2mqtt

Now Zigbee2MQTT runs again.

Hope this helps anybody who has the same problem after a reboot.

2 Likes

I was able to fix my Zigbee2MQTT with the fix I described.
But anytime I power down my raspi and restart it I have to make the same fix.
It is not a big deal but I was wondering if it is possible to let a script start with the fix whenever I boot the raspi.
Even better would be if the folder wouldn’t be deleted by every reboot.
Anybody an idea?
Thanks

@Sleugner : First i would recommend to search for the root cause instead of investing time in a workaround. Missing folders are not a normal behavior.
Although not knowing your system my guess about your problem is the following:
In many systems /var/log is on zram to avoid continuous writing to sd-card. E.g. the zigbee2mqtt-installation routine in openhabian uses zram (I wrote it;).
But: This zram is written to sd during a proper shut down or reboot. If there was no time to write zram to sd the last available is recovered (your broken one).
If i want to reboot my sequence is
sudo systemctl stop zigbee2mqtt ; sudo systemctl stop openhab ; sudo systemctl stop mosquitto; sleep 10; sudo shutdown -r now
I’m not sure if all of those steps are really necessarily but never had a problem with that.
Remember that sudden power losses can be a problem for any Linux systems so I recommend a UPS (I use a simple waveshare).
Hope that helps a bit.

I also saw this behavior for an other service. At that time I just made sure that zram is not running and reinstalled the package that I was using at that time.
A workaround would be to add a few lines of code to the service description of zigbee2mqtt. During start of the service the directory would be generated. But this shouldn’t be necessary as the folder is created when the package is installed.

Hey thanks for the quick reply.
Honestly I never rebootet my Raspi controlled. It was always only Power Outages.
So I did you routine and after the reboot Zigbee was still working. Also InfluxDB where I had a simular problem.

@Sleugner: Then please get yourself a UPS. Because frequent power outages will almost surely kill your system (sd-card, file-system etc). They’re just not designed for that. For me a UPS is one of the first must-haves of a smart home system. You can configure it so that you get a safe shutdown when the battery gets low (and they start from around 20€).

You mentioned this in your original post a couple of months ago, but I think it was overlooked in the responses. As @Larsen says, a corrupt SD card resulting from the sudden power loss may be the root issue. If you don’t have a recent backup, I’d suggest starting a fresh installation and then importing your configuration data. Otherwise, you might just keep running into new issues all stemming from that initial corruption.

I also recommend a UPS. You just need a small one that can keep your RPi running long enough to shut down smoothly, with a USB port for Network UPS Tools.

You can also get onboard battery backups for RPis. I recently picked up a couple of Red Reactors on Kickstarter. They arrived in February, but I haven’t found time to install them.