Zigbee2mqtt installation - systemctl

Good morning together,

I am (the noob) running dietpi on a raspberry pi 4 with pivpn, pihole, nextcloud, vaultwarden, mqtt and node red.
node. js and git are installed.
Bluetooth and wifi are not used or activated.
Next days i will receive a sonoff zigbee dongle and need some help by installation.

My questions are:
Must i activate serial/uart in dietpi config?
Both are deactivated. (ttyAMAO and ttySO)

Could someone please guide me through the installation of zigbee2mqtt?

Can i start with:

mkdir /opt/zigbee2mqtt

sudo git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt

sudo chown -R dietpi:dietpi /opt/zigbee2mqtt

cd /opt/zigbee2mqtt
npm ci

After the stick arrived, I installed it as indicated above.

However, now I get the following error message when starting.

dietpi@DietPi:~$ cd /opt/zigbee2mqtt
dietpi@DietPi:/opt/zigbee2mqtt$ npm start

> zigbee2mqtt@1.24.0 start
> node index.js

                Zigbee2MQTT requires node version ^10 || ^12 || ^14 || ^15 || ^16, you are running v17.6.0!

Zigbee2MQTT:info  2022-03-24 15:24:03: Logging to console and directory: '/opt/zigbee2mqtt/data/log/2022-03-24.15-24-02' filename: log.txt
Zigbee2MQTT:info  2022-03-24 15:24:03: Starting Zigbee2MQTT version 1.24.0 (commit #a73caa3e)
Zigbee2MQTT:info  2022-03-24 15:24:03: Starting zigbee-herdsman (0.14.20)
Zigbee2MQTT:error 2022-03-24 15:24:04: Error while starting zigbee-herdsman
Zigbee2MQTT:error 2022-03-24 15:24:04: Failed to start zigbee
Zigbee2MQTT:error 2022-03-24 15:24:04: Check https://www.zigbee2mqtt.io/guide/installation/20_zigbee2mqtt-fails-to-start.html for possible solutions
Zigbee2MQTT:error 2022-03-24 15:24:04: Exiting...
Zigbee2MQTT:error 2022-03-24 15:24:04: Error: Error while opening serialport 'Error: Error: Permission denied, cannot open /dev/ttyUSB0'
    at SerialPort.<anonymous> (/opt/zigbee2mqtt/node_modules/zigbee-herdsman/src/adapter/z-stack/znp/znp.ts:146:28)
    at SerialPort._error (/opt/zigbee2mqtt/node_modules/zigbee-herdsman/node_modules/@serialport/stream/lib/index.js:198:14)
    at /opt/zigbee2mqtt/node_modules/zigbee-herdsman/node_modules/@serialport/stream/lib/index.js:242:12
npm notice
npm notice New patch version of npm available! 8.5.1 -> 8.5.5
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.5.5
npm notice Run npm install -g npm@8.5.5 to update!
npm notice

As far as I understand it is probably because of the write permissions.

After i add user dietpi to groups tty and dialout it works!

sudo usermod -a -G tty dietpi
sudo usermod -a -G dialout dietpi

But only i start manual.
I have the following /etc/systemd/system/zigbee2mqtt.service


ExecStart=/opt/zigbee2mqtt/npm start
# StandardOutput=inherit
# Or use StandardOutput=null if you don't want Zigbee2MQTT messages filling syslog, for more option>


and then

sudo systemctl enable zigbee2mqtt.service

but i get

 sudo systemctl status zigbee2mqtt.service
● zigbee2mqtt.service - zigbee2mqtt
     Loaded: loaded (/etc/systemd/system/zigbee2mqtt.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-03-24 18:08:34 CET; 52s ago
    Process: 18255 ExecStart=/opt/zigbee2mqtt/npm start (code=exited, status=203/EXEC)
   Main PID: 18255 (code=exited, status=203/EXEC)
        CPU: 8ms

Mär 24 18:08:34 DietPi systemd[1]: zigbee2mqtt.service: Scheduled restart job, restart counter is at 5.
Mär 24 18:08:34 DietPi systemd[1]: Stopped zigbee2mqtt.
Mär 24 18:08:34 DietPi systemd[1]: zigbee2mqtt.service: Start request repeated too quickly.
Mär 24 18:08:34 DietPi systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'.
Mär 24 18:08:34 DietPi systemd[1]: Failed to start zigbee2mqtt.

Unfortunately, I only have rudimentary knowledge of Linux.

I would be very grateful for some help.

did you work out how to do it?

I have HA and Mosquito installed and now want to add ZIgbee2MQTT as well.

You can downgrade Node.js to the compatible v16 via “n” version management:

sudo npm -g i n
sudo n 16

This f*cked up my nearly working setup completely.

You mean downgrading to Node v16? To be true I don’t remember anymore where I got the info that this would help, probably posted to the wrong thread. E.g. Node-RED did not work on ARMv6 with latest Node for a while.

You can upgrade it again:

sudo n stable

The systemd unit above explicitly mutes output and errors. That way it is difficult to debug. If you use that, comment the StandoutOutput and StandardError lines, then do:

systemctl daemon-reload
systemctl restart zigbee2mqtt
sleep 5
journalctl -u zigbee2mqtt

That hopefully gives some hint why it is failing.

In case anyone is wondering if OP ever succeed in installing zigbee2mqtt, I was wondering that as well and decided to try and install zigbee2mqtt for myself.

Thankfully the installation process wasn’t all too complicated.
First you should visit Linux | Zigbee2MQTT and read the guide.

Before you get started however, be sure to downgrade to a supported node version. Then follow the instructions and deploy zigbee2mqtt as a service.

If you run into any problems, check out [Zigbee2MQTT fails to start | Zigbee2MQTT](https://Zigbee2mqtt fails to start.)

I faced two issues myself:

  1. I blindy copied the service config and did not change the USER to dietpi.
  2. I needed to change the permissions on /dev/ttyACM0
    and voila. it’s running.