{"id":299,"date":"2020-12-13T22:35:17","date_gmt":"2020-12-13T21:35:17","guid":{"rendered":"http:\/\/sebabu-it.de\/?p=299"},"modified":"2020-12-21T20:58:13","modified_gmt":"2020-12-21T19:58:13","slug":"zigbee2mqtt-running-zigbee2mqtt","status":"publish","type":"post","link":"https:\/\/sebabu.landau-software.de\/?p=299","title":{"rendered":"Zigbee &#8211; Running Zigbee2MQTT (Teil 2\/3)"},"content":{"rendered":"\n<!--more-->\n\n\n\n<p>Quelle: <a href=\"https:\/\/www.zigbee2mqtt.io\/getting_started\/running_zigbee2mqtt.html\">zigbee2mqtt.io<\/a><\/p>\n\n\n\n<p>Stand: 13.12.2020<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"running-zigbee2mqtt\">Running Zigbee2MQTT<\/h1>\n\n\n\n<p>These instructions explain how to run Zigbee2MQTT on bare-metal Linux.<\/p>\n\n\n\n<p>You can also run Zigbee2MQTT in a&nbsp;<a href=\"https:\/\/www.zigbee2mqtt.io\/information\/docker.html\">Docker container<\/a>, as the&nbsp;<a href=\"https:\/\/github.com\/danielwelch\/hassio-zigbee2mqtt\">Home Assistant Zigbee2MQTT add-on<\/a>, in a&nbsp;<a href=\"https:\/\/www.zigbee2mqtt.io\/information\/virtual_environment.html\">Python Virtual Enviroment<\/a>&nbsp;or even on&nbsp;<a href=\"https:\/\/www.zigbee2mqtt.io\/information\/windows.html\">Windows<\/a>.<\/p>\n\n\n\n<p>For the sake of simplicity this guide assumes running on a Raspberry Pi 3 with Raspbian Stretch Lite, but will work on any Linux machine.<\/p>\n\n\n\n<p>Before starting make sure you have an MQTT broker installed on your system. There are many tutorials available on how to do this,&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/how-to-install-mosquitto-broker-on-raspberry-pi\/\">example<\/a>. Mosquitto is the recommended MQTT broker but others should also work fine.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-determine-location-of-cc2531-usb-sniffer-and-checking-user-permissions\">1. Determine location of CC2531 USB sniffer and checking user permissions&nbsp;<a href=\"https:\/\/www.zigbee2mqtt.io\/getting_started\/running_zigbee2mqtt.html#1-determine-location-of-cc2531-usb-sniffer-and-checking-user-permissions\">#<\/a><\/h2>\n\n\n\n<p>We first need to determine the location of the CC2531 USB sniffer. Connect the CC2531 USB to your Raspberry Pi. Most of the times the location of the CC2531 is&nbsp;<code>\/dev\/ttyACM0<\/code>. This can be verified by:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberry:~ $ ls -l \/dev\/ttyACM0\ncrw-rw---- 1 root dialout 166, 0 May 16 19:15 \/dev\/ttyACM0  # &lt;-- CC2531 on \/dev\/ttyACM0\n<\/code><\/pre>\n\n\n\n<p>As an alternative, the device can also be mapped by an ID. This can be handy if you have multiple serial devices connected to your Raspberry Pi. In the example below the device location is:&nbsp;<code>\/dev\/serial\/by-id\/usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B0018ED3DDF-if00<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberry:\/ $ ls -l \/dev\/serial\/by-id\ntotal 0\nlrwxrwxrwx. 1 root root 13 Oct 19 19:26 usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B0018ED3DDF-if00 -&gt; ..\/..\/ttyACM0\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-installing\">2. Installing&nbsp;<a href=\"https:\/\/www.zigbee2mqtt.io\/getting_started\/running_zigbee2mqtt.html#2-installing\">#<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Setup Node.js repository\nsudo curl -sL https:\/\/deb.nodesource.com\/setup_12.x | sudo -E bash -\n\n# NOTE 1: If you see the message below please follow: https:\/\/gist.github.com\/Koenkk\/11fe6d4845f5275a2a8791d04ea223cb.\n# ## You appear to be running on ARMv6 hardware. Unfortunately this is not currently supported by the NodeSource Linux distributions. Please use the 'linux-armv6l' binary tarballs available directly from nodejs.org for Node.js 4 and later.\n# IMPORTANT: In this case instead of the apt-get install mentioned below; do: sudo apt-get install -y git make g++ gcc\n\n# NOTE 2: On x86, Node.js 10 may not work. It's recommended to install an unofficial Node.js 12 build which can be found here: https:\/\/unofficial-builds.nodejs.org\/download\/release\/ (e.g. v12.16.3)\n\n# Install Node.js;\nsudo apt-get install -y nodejs git make g++ gcc\n\n# Verify that the correct nodejs and npm (automatically installed with nodejs)\n# version has been installed\nnode --version  # Should output v12.X or v10.X\nnpm --version  # Should output 6.X\n\n# Clone Zigbee2MQTT repository\nsudo git clone https:\/\/github.com\/Koenkk\/zigbee2mqtt.git \/opt\/zigbee2mqtt\nsudo chown -R pi:pi \/opt\/zigbee2mqtt\n\n# Install dependencies (as user \"pi\")\ncd \/opt\/zigbee2mqtt\nnpm ci --production\n<\/code><\/pre>\n\n\n\n<p>If everything went correctly the output of&nbsp;<code>npm ci<\/code>&nbsp;is similar to (the number of packages and seconds is probably different on your device):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node-pre-gyp info ok\nadded 383 packages in 111.613s\n<\/code><\/pre>\n\n\n\n<p>Note that the&nbsp;<code>npm ci<\/code>&nbsp;produces some&nbsp;<code>warning<\/code>&nbsp;which can be ignored.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-configuring\">3. Configuring&nbsp;<a href=\"https:\/\/www.zigbee2mqtt.io\/getting_started\/running_zigbee2mqtt.html#3-configuring\">#<\/a><\/h2>\n\n\n\n<p>Before we can start Zigbee2MQTT we need to edit the&nbsp;<code>configuration.yaml<\/code>&nbsp;file. This file contains the configuration which will be used by Zigbee2MQTT.<\/p>\n\n\n\n<p>Open the configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/opt\/zigbee2mqtt\/data\/configuration.yaml\n<\/code><\/pre>\n\n\n\n<p>For a basic configuration, the default settings are probably good. The only thing we need to change is the MQTT server url and authentication (if applicable). This can be done by changing the section below in your&nbsp;<code>configuration.yaml<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># MQTT settings\nmqtt:\n  # MQTT base topic for Zigbee2MQTT MQTT messages\n  base_topic: zigbee2mqtt\n  # MQTT server URL\n  server: 'mqtt:\/\/localhost'\n  # MQTT server authentication, uncomment if required:\n  # user: my_user\n  # password: my_password\n<\/code><\/pre>\n\n\n\n<p>Save the file and exit.<\/p>\n\n\n\n<p>It is recommended to use a custom network key. This can be done by adding the following to your&nbsp;<code>configuration.yaml<\/code>. With this Zigbee2MQTT will generate a network key on next startup.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>advanced:\n    network_key: GENERATE\n<\/code><\/pre>\n\n\n\n<p>This can be done with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"\\n\\nadvanced:\\n    network_key: GENERATE\" &gt;&gt; \/opt\/zigbee2mqtt\/data\/configuration.yaml\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-starting-zigbee2mqtt\">4. Starting Zigbee2MQTT&nbsp;<a href=\"https:\/\/www.zigbee2mqtt.io\/getting_started\/running_zigbee2mqtt.html#4-starting-zigbee2mqtt\">#<\/a><\/h2>\n\n\n\n<p>Now that we have setup everything correctly we can start Zigbee2MQTT.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/opt\/zigbee2mqtt\nnpm start\n<\/code><\/pre>\n\n\n\n<p>When started successfully, you will see something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Zigbee2MQTT:info  2019-11-09T13:04:01: Logging to directory: '\/opt\/zigbee2mqtt\/data\/log\/2019-11-09.14-04-01'\nZigbee2MQTT:info  2019-11-09T13:04:01: Starting Zigbee2MQTT version 1.6.0 (commit #720e393)\nZigbee2MQTT:info  2019-11-09T13:04:01: Starting zigbee-herdsman...\nZigbee2MQTT:info  2019-11-09T13:04:03: zigbee-herdsman started\nZigbee2MQTT:info  2019-11-09T13:04:03: Coordinator firmware version: '{\"type\":\"zStack30x\",\"meta\":{\"transportrev\":2,\"product\":2,\"majorrel\":2,\"minorrel\":7,\"maintrel\":2,\"revision\":20190425}}'\nZigbee2MQTT:info  2019-11-09T13:04:03: Currently 0 devices are joined:\nZigbee2MQTT:warn  2019-11-09T13:04:03: `permit_join` set to  `true` in configuration.yaml.\nZigbee2MQTT:warn  2019-11-09T13:04:03: Allowing new devices to join.\nZigbee2MQTT:warn  2019-11-09T13:04:03: Set `permit_join` to `false` once you joined all devices.\nZigbee2MQTT:info  2019-11-09T13:04:03: Zigbee: allowing new devices to join.\nZigbee2MQTT:info  2019-11-09T13:04:03: Connecting to MQTT server at mqtt:\/\/localhost\nZigbee2MQTT:info  2019-11-09T13:04:03: Connected to MQTT server\n<\/code><\/pre>\n\n\n\n<p>Zigbee2MQTT can be stopped by pressing&nbsp;<code>CTRL + C<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5-optional-running-as-a-daemon-with-systemctl\">5. (Optional) Running as a daemon with systemctl&nbsp;<a href=\"https:\/\/www.zigbee2mqtt.io\/getting_started\/running_zigbee2mqtt.html#5-optional-running-as-a-daemon-with-systemctl\">#<\/a><\/h2>\n\n\n\n<p>To run Zigbee2MQTT as daemon (in background) and start it automatically on boot we will run Zigbee2MQTT with systemctl.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Create a systemctl configuration file for Zigbee2MQTT\nsudo nano \/etc\/systemd\/system\/zigbee2mqtt.service\n<\/code><\/pre>\n\n\n\n<p>Add the following to this file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Unit]\nDescription=zigbee2mqtt\nAfter=network.target\n\n&#91;Service]\nExecStart=\/usr\/bin\/npm start\nWorkingDirectory=\/opt\/zigbee2mqtt\nStandardOutput=inherit\nStandardError=inherit\nRestart=always\nUser=pi\n\n&#91;Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n\n\n\n<p><strong>NOTE:<\/strong>&nbsp;If you are using a Raspberry Pi 1 or Zero AND if you followed this&nbsp;<a href=\"https:\/\/gist.github.com\/Koenkk\/11fe6d4845f5275a2a8791d04ea223cb\">guide<\/a>, replace&nbsp;<code>ExecStart=\/usr\/bin\/npm start<\/code>&nbsp;with&nbsp;<code>ExecStart=\/usr\/local\/bin\/npm start<\/code>.<\/p>\n\n\n\n<p>Save the file and exit.<\/p>\n\n\n\n<p>Verify that the configuration works:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Start Zigbee2MQTT\nsudo systemctl start zigbee2mqtt\n\n# Show status\nsystemctl status zigbee2mqtt.service\n<\/code><\/pre>\n\n\n\n<p>Output should look like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberry:\/opt\/zigbee2mqtt $ systemctl status zigbee2mqtt.service\n\u25cf zigbee2mqtt.service - zigbee2mqtt\n   Loaded: loaded (\/etc\/systemd\/system\/zigbee2mqtt.service; disabled; vendor preset: enabled)\n   Active: active (running) since Thu 2018-06-07 20:27:22 BST; 3s ago\n Main PID: 665 (npm)\n   CGroup: \/system.slice\/zigbee2mqtt.service\n           \u251c\u2500665 npm\n           \u251c\u2500678 sh -c node index.js\n           \u2514\u2500679 node index.js\n\nJun 07 20:27:22 raspberry systemd&#91;1]: Started zigbee2mqtt.\nJun 07 20:27:23 raspberry npm&#91;665]: &gt; zigbee2mqtt@1.6.0 start \/opt\/zigbee2mqtt\nJun 07 20:27:23 raspberry npm&#91;665]: &gt; node index.js\nJun 07 20:27:24 raspberry npm&#91;665]: Zigbee2MQTT:info  2019-11-09T13:04:01: Logging to directory: '\/opt\/zigbee2mqtt\/data\/log\/2019-11-09.14-04-01'\nJun 07 20:27:25 raspberry npm&#91;665]: Zigbee2MQTT:info  2019-11-09T13:04:01: Starting Zigbee2MQTT version 1.6.0 (commit #720e393)\n<\/code><\/pre>\n\n\n\n<p>Now that everything works, we want systemctl to start Zigbee2MQTT automatically on boot, this can be done by executing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable zigbee2mqtt.service\n<\/code><\/pre>\n\n\n\n<p>Done! \ud83d\ude03<\/p>\n\n\n\n<p>Some tips that can be handy later:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Stopping Zigbee2MQTT\nsudo systemctl stop zigbee2mqtt\n\n# Starting Zigbee2MQTT\nsudo systemctl start zigbee2mqtt\n\n# View the log of Zigbee2MQTT\nsudo journalctl -u zigbee2mqtt.service -f\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6-for-later-update-zigbee2mqtt-to-the-latest-version\">6. (For later) Update Zigbee2MQTT to the latest version&nbsp;<a href=\"https:\/\/www.zigbee2mqtt.io\/getting_started\/running_zigbee2mqtt.html#6-for-later-update-zigbee2mqtt-to-the-latest-version\">#<\/a><\/h2>\n\n\n\n<p>To update Zigbee2MQTT to the latest version, execute:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Stop Zigbee2MQTT and go to directory\nsudo systemctl stop zigbee2mqtt\ncd \/opt\/zigbee2mqtt\n\n# Backup configuration\ncp -R data data-backup\n\n# Update\ngit checkout HEAD -- npm-shrinkwrap.json\ngit pull\nnpm ci\n\n# Restore configuration\ncp -R data-backup\/* data\nrm -rf data-backup\n\n# Start Zigbee2MQTT\nsudo systemctl start zigbee2mqtt\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"whats-next\">What\u2019s next?&nbsp;<a href=\"https:\/\/www.zigbee2mqtt.io\/getting_started\/running_zigbee2mqtt.html#whats-next\">#<\/a><\/h1>\n\n\n\n<p><a href=\"https:\/\/www.zigbee2mqtt.io\/getting_started\/pairing_devices.html\">Pairing devices<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[33],"tags":[],"class_list":["post-299","post","type-post","status-publish","format-standard","hentry","category-zigbee"],"_links":{"self":[{"href":"https:\/\/sebabu.landau-software.de\/index.php?rest_route=\/wp\/v2\/posts\/299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sebabu.landau-software.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sebabu.landau-software.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sebabu.landau-software.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sebabu.landau-software.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=299"}],"version-history":[{"count":4,"href":"https:\/\/sebabu.landau-software.de\/index.php?rest_route=\/wp\/v2\/posts\/299\/revisions"}],"predecessor-version":[{"id":324,"href":"https:\/\/sebabu.landau-software.de\/index.php?rest_route=\/wp\/v2\/posts\/299\/revisions\/324"}],"wp:attachment":[{"href":"https:\/\/sebabu.landau-software.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sebabu.landau-software.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sebabu.landau-software.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}