Zigbee2mqtt: Guide: Virtual environment

Created on 5 Feb 2019  路  2Comments  路  Source: Koenkk/zigbee2mqtt

If you want to run it in virtual environment:

Setup

# Clone zigbee2mqtt repository
sudo git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
sudo chown -R pi:pi /opt/zigbee2mqtt

# Enter folder
cd /opt/zigbee2mqtt

# Install python env
python3 -m venv .

# Activate environment 
source /opt/zigbee2mqtt/bin/activate

# Upgrade pip, wheel and setuptools
pip install --upgrade pip wheel setuptools

# Install node environment
pip install nodeenv

# Init node environment
nodeenv -p -n 10.15.1

# Exit and enter environment to be sure
deactivate
source /opt/zigbee2mqtt/bin/activate

# Install dependencies
cd /opt/zigbee2mqtt
npm install

# Exit environment 
deactivate

Config

Configure the zigbee2mqtt as the installation guide part 3 Running Zigbee2mqtt

Test that it works by starting zigbee2mqtt:

# Enter folder
cd /opt/zigbee2mqtt/
# Activate environment
source /opt/zigbee2mqtt/bin/activate
# Start
npm start

# ctrl + c to quit

# deactivate environment
deactivate

Autostart

Configure systemd:

# Create a systemctl configuration file for zigbee2mqtt
sudo nano /etc/systemd/system/zigbee2mqtt.service

Add the following to this file:

[Unit]
Description=zigbee2mqtt
After=network.target

[Service]
ExecStart=/bin/bash -c 'source /opt/zigbee2mqtt/bin/activate; /opt/zigbee2mqtt/bin/npm start'
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

Then make it autostart:

# Reload systemd
sudo systemctl daemon-reload

# Make zigbee2mqtt autostart
sudo systemctl enable zigbee2mqtt 

# Start
sudo systemctl start zigbee2mqtt

Other useful commands:

# Stop
sudo systemctl stop zigbee2mqtt

# Restart 
sudo systemctl restart zigbee2mqtt

# Status
sudo systemctl status zigbee2mqtt

# Remove zigbee2mqtt from autostart
sudo systemctl disable zigbee2mqtt 

Most helpful comment

You should make a pull request with this.

All 2 comments

You should make a pull request with this.

You should make a pull request with this.

I'll make one tomorrow

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andreasbrett picture andreasbrett  路  3Comments

pepp86 picture pepp86  路  4Comments

mpuff picture mpuff  路  4Comments

CodeFinder2 picture CodeFinder2  路  4Comments

Courty40 picture Courty40  路  4Comments