{"uuid":"14330f3c-e4ce-4334-8ecb-1045a4a9fbba","slug":"zigbee2mqtt","title":"zigbee2mqtt","author":"cedric@abonnel.fr","published":true,"published_at":"2024-06-22 17:27:02","created_at":"2024-06-22 17:27:02","updated_at":"2024-06-22 17:27:02","revisions":[],"cover":"","files_meta":[],"external_links":[],"seo_title":"","seo_description":"","og_image":"","category":"Informatique","content":"# zigbee2mqtt\n\n![Nom de la section](dummy.png)\n\nLe programme `zigbee2mqtt` permet de transposer les informations d'un réseau Zigbee à un bus de message MQTT.\n\nIl est nécessaire de disposer d'un bus de message MQTT et d'un récepteur Zigbee.\n\nReprise des éléments de la page https:*www.zigbee2mqtt.io/guide/installation/01_linux.html\n\n## Installation\nInstallation de **Zigbee2MQTT** sur un **Raspberry Pi 3** fonctionnant sur la distribution **Raspberry Pi OS Linux** fraîchement installée.\n\nAvant d'installer **Zigbee2MQTT**, nous vérifions que l'adaptateur Zigbee soit bien reconnu par **Raspberry Pi OS**. Il doit être reconnu en tant que périphérique USB avec la commande `lsusb`:\n```\nBus 001 Device 005: ID 1a86:55d4 QinHeng Electronics SONOFF Zigbee 3.0 USB Dongle Plus V2\n```\n\nLa communication s’effectuera par un port série émulé. On peut vérifier la disponibilité du port avec la commande `ls -l /dev/serial/by-id` :\n```\ntotal 0\nlrwxrwxrwx 1 root root 13 5 nov. 09:20 usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20220818080300-if00 -> ../../ttyACM0\n```\n\nEnfin, on lance l'installation de **Zigbee2 MQTT**\n\n```BASH\n# Set up Node.js repository and install Node.js + required dependencies\n# NOTE: Older i386 hardware can work with [unofficial-builds.nodejs.org](https:*unofficial-builds.nodejs.org/download/release/v16.15.0/ e.g. Version 16.15.0 should work.\nsudo curl -fsSL https:*deb.nodesource.com/setup_20.x | sudo -E bash -\nsudo apt-get install -y nodejs git make g++ gcc libsystemd-dev make\n\n# Verify that the correct nodejs and npm (automatically installed with nodejs)\n# version has been installed\nnode --version # Should output V18.x, V20.x, V21.X\nnpm --version # Should output 9.X or 10.X\n\n# Create a directory for zigbee2mqtt and set your user as owner of it\nsudo mkdir /opt/zigbee2mqtt\nsudo chown -R ${USER}: /opt/zigbee2mqtt\n\n# Clone Zigbee2MQTT repository\ngit clone --depth 1 https:*github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt\n\n# Install dependencies (as user \"pi\")\ncd /opt/zigbee2mqtt\nnpm ci\n```\n\nUn message peu vous annoncer une mise à jour mineure de `npm`\n\n![](20240622-192626.png)\n\nExécuter les commandes suivantes :\n```\nsudo npm install -g npm@10.8.1\n\nnpm ci\n```\n\n## Configuration\nLe fichier de configuration se trouve dans `/opt/zigbee2mqtt/data/configuration.yaml`\n\nPour une configuration de base, les paramètres par défaut sont suffisant.\n```YML\n# 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\n# Serial settings\nserial:\n # Location of the adapter (see first step of this guide)\n port: /dev/ttyACM0\n```\n\n--\n\nPour les clés **SONOFF Zigbee 3.0 USB Dongle Plus V2**, **ZBDongle-E** ajouter l'options suivante :\n\n```YML\nserial:\n adapter: ezsp\n```\n\n--\n\nVous pouvez ajouter une clé réseau. Elle sera générée au prochain démarrage du service.\n\n```YML\nadvanced:\n network_key: GENERATE\n```\n\n--\n\nVous pouvez activer le **frontend** :\n\n```YML\nfrontend:\n # Optional, default 8080\n port: 8080\n # Optional, default 0.0.0.0\n host: 0.0.0.0\n # Optional, enables authentication, disabled by default\n auth_token: your-secret-token\n # Optional, url on which the frontend can be reached, currently only used for the Home Assistant device configuration page\n url: 'https:*zigbee2mqtt.myhouse.org'\n```\n\nD'autres options sont disponibles :\n- \n- \n## Démarrer Zigbee2MQTT\nPour démarrer **Zigbee2MQTT**, il suffit de se rendre dans le dossier du programme et effectuer le `npm start`.\n\n```\ncd /opt/zigbee2mqtt\nnpm start\n```\n\nLe programme s'executera jusqu'à vous effectuiez une interruption de programme en appuyant simultanément sur Ctrl + c\n\n## Démarrer automatiquement Zigbee2MQTT\nPour démarrer automatiquement **Zigbee2MQTT**, il faut inscrire le programme en tant que service.\n\n1. Éditer une nouveau fichier `/etc/systemd/system/zigbee2mqtt.service`\n\n sudo nano /etc/systemd/system/zigbee2mqtt.service\n \n2. Écrivez les paramètres et instructions suivants\n\n```\n[Unit]\nDescription=zigbee2mqtt\nAfter=network.target\n\n[Service]\nEnvironment=NODE_ENV=production\nExecStart=/usr/bin/npm start\nWorkingDirectory=/opt/zigbee2mqtt\nStandardOutput=inherit\n# Ou utilisez StandardOutput=null si vous ne voulez pas que les messages de Zigbee2MQTT remplissent le SYSLOG\nStandardError=inherit\nRestart=always\nRestartSec=10s\nUser=pi\n# Modifiez le compte par le votre\n\n[Install]\nWantedBy=multi-user.target\n```\n\nInscrire le service en démarrage automatique : \n sudo systemctl enable zigbee2mqtt.service\n\nDémarrer le service :\n sudo systemctl start zigbee2mqtt\n\nVérifier l'état du service :\n systemctl status zigbee2mqtt.service\n \nConsulter le journal :\n sudo journalctl -u zigbee2mqtt.service -f\n\n## Mise à jour du programme\n```\n# 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 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```","featured":false,"tags":[]}