Venv documentation (#1033)

* Added guide for virtual environment

* grammer

* Update virtual_environment.md

* Update virtual_environment.md

* Update index.md
This commit is contained in:
orrpan
2019-02-06 21:12:23 +01:00
committed by Koen Kanters
parent c68790f2c4
commit 314ab1b705
3 changed files with 118 additions and 1 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
# Running Zigbee2mqtt
These instructions explain how to run Zigbee2mqtt on bare-metal Linux.
Other ways to run Zigbee2mqtt are [Docker](../information/docker.md) and the [Hass.io Zigbee2mqtt add-on](https://github.com/danielwelch/hassio-zigbee2mqtt).
Other ways to run Zigbee2mqtt are [Docker](../information/docker.md), the [Hass.io Zigbee2mqtt add-on](https://github.com/danielwelch/hassio-zigbee2mqtt) and [Virtual Enviroment](../information/virtual_environment.md).
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.
+1
View File
@@ -43,3 +43,4 @@ Welcome to the Zigbee2mqtt documentation!
* [3D cases](information/3d_cases.md)
* [CC sniffer devices](information/cc_sniffer_devices.md)
* [Alternative flashing methods](information/alternative_flashing_methods.md)
* [Running Zigbee2mqtt in Virtual Environment](information/virtual_environment.md)
+116
View File
@@ -0,0 +1,116 @@
# Running Zigbee2mqtt in Virtual Environment
It is possible to run Zigbee2mqtt in a virtual environment, this has been tested with a Raspberry Pi 3B+.
This guide is similar to the [Running zigbee2mqtt guide](../information/running_zigbee2mqtt.md), follow the steps from there by replacing the steps with the ones from below.
## 2. Installing
```bash
# 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
# Deactivate and activate environment to be sure
deactivate
source /opt/zigbee2mqtt/bin/activate
# Install dependencies
cd /opt/zigbee2mqtt
npm install
# Deactivate environment
deactivate
```
## 4. Starting zigbee2mqtt
```bash
# Enter folder
cd /opt/zigbee2mqtt
# Activate environment
source /opt/zigbee2mqtt/bin/activate
# Start
npm start
# ctrl + c to quit
# Deactivate environment
deactivate
```
## 5. (Optional) Running as a daemon with systemctl
To run zigbee2mqtt as daemon (in background) and start it automatically on boot we will run Zigbee2mqtt with systemctl.
```bash
# Create a systemctl configuration file for zigbee2mqtt
sudo nano /etc/systemd/system/zigbee2mqtt.service
```
Add the following to this file:
```bash
[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
```
Now continue with *Verify that the configuration works:* from the *Running Zigbee2mqtt guide*.
## 6. (For later) Update Zigbee2mqtt to the latest version
To update Zigbee2mqtt to the latest version, execute:
```sh
# Stop zigbee2mqtt and go to directory
sudo systemctl stop zigbee2mqtt
cd /opt/zigbee2mqtt
# Activate environment
source /opt/zigbee2mqtt/bin/activate
# Backup configuration
cp -R data data-backup
# Update
git checkout HEAD -- npm-shrinkwrap.json
git pull
rm -rf node_modules
npm install
# Restore configuration
cp -R data-backup/* data
rm -rf data-backup
# Deactivate environment
deactivate
# Start zigbee2mqtt
sudo systemctl start zigbee2mqtt
```