Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Add Zigbee2MQTT install script #207

Merged
merged 3 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Hassbian-scripts

These are the scripts used in the [Hassbian][hassbian] image.
These are the scripts used in the [Hassbian][hassbian] image.
The scripts in this repository where made to be used with the Hassbian image
and the included Home Assistant instance.
and the included Home Assistant instance.

## The included scripts

Expand All @@ -29,6 +29,7 @@ below for usage and instructions.
- [Samba](/docs/samba.md)
- [Trådfri](/docs/tradfri.md)
- [Webterminal](/docs/webterminal.md)
- [Zigbee2mqtt](/docs/zigbee2mqtt.md)
- [Changelog][changelog]

***
Expand Down
37 changes: 37 additions & 0 deletions docs/zigbee2mqtt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Zigbee2mqtt

This script installs the [Zigbee2mqtt bridge][zigbee2mqtt].
After installation some further configuration is required. Instructions can be found [here][zigbee2mqttdocs].

## Installation

```bash
sudo hassbian-config install zigbee2mqtt
```

## Upgrade

No script available, maybe you could write one?
If so, add an PR here when you are done:
[homeassistant/hassbian-scripts][repo]

## Additional info

Description | Command/value
:--- | :---
Running as: | pi
Configuration file: | /opt/zigbee2mqtt/data/configuration.yaml
Start service: | `sudo systemctl start zigbee2mqtt.service`
Stop service: | `sudo systemctl stop zigbee2mqtt.service`
Restart service: | `sudo systemctl restart zigbee2mqtt.service`
Service status: | `sudo systemctl status zigbee2mqtt.service`

***

This install script was originally contributed by [@Landrash][landrash]

<!--- Links --->
[zigbee2mqtt]: https://github.com/Koenkk/zigbee2mqtt/
[zigbee2mqttdocs]: https://github.com/Koenkk/zigbee2mqtt/wiki/Running-the-bridge#3-configuring
[landrash]: https://github.com/landrash
[repo]: https://github.com/home-assistant/hassbian-scripts/pulls
73 changes: 73 additions & 0 deletions package/opt/hassbian/suites/zigbee2mqtt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
function zigbee2mqtt-show-short-info {
echo "Setup for Zigbee2mqtt bridge."
}

function zigbee2mqtt-show-long-info {
echo "This script installs the Zigbee2mqtt bridge"
}

function zigbee2mqtt-show-copyright-info {
echo "Original concept by Landrash <https://github.com/landrash>."
}

function zigbee2mqtt-install-package {
echo -n "Installing dependencies : "
node=$(which npm)
if [ -z "${node}" ]; then #Installing NodeJS if not already installed.
printf "Downloading and installing NodeJS...\\n"
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt install -y nodejs
fi

echo "Cloning Zigbee2mqtt git repository"
git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
chown -R pi:pi /opt/zigbee2mqtt

echo "Running install. This might take a while and can produce som expected errors"
cd /opt/zigbee2mqtt || exit
su pi -c "npm install"

echo "Creating service file zigbee2mqtt.service"
service_path="/etc/systemd/system/zigbee2mqtt.service"

echo "[Unit]
Description=zigbee2mqtt
After=network.target

[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target" > $service_path

echo "Checking the installation..."
if [ ! -f /opt/zigbee2mqtt/data/configuration.yaml ]; then
validation=""
else
validation="ok"
fi

if [ ! -z "${validation}" ]; then
echo
echo -e "\\e[32mInstallation done..\\e[0m"
echo -e "Update of configuration.yaml is required found at /opt/zigbee2mqtt/data/"
echo -e "Some further configuration is required and details can be found here https://github.com/Koenkk/zigbee2mqtt/wiki/Running-the-bridge "
echo
echo -e "Service can be started after configuration but running sudo systemctl start zigbee2mqtt"
echo
else
echo
echo -e "\\e[31mInstallation failed..."
echo
return 1
fi
return 0
}

[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead"
2 changes: 1 addition & 1 deletion package/usr/local/bin/hassbian-config
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function raspberry_pi_zero_check {
if [ "$FORCE" != "true" ]; then
REVCODE=$(sudo cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^ *//g' | sed 's/ *$//g')
if [ "$REVCODE" = "90092" ] || [ "$REVCODE" = "90093" ] || [ "$REVCODE" = "0x9000C1" ] || [ "$REVCODE" = "9000c1" ]; then
if [[ "$1" =~ ^(mosquitto|cloud9)$ ]]; then
if [[ "$1" =~ ^(mosquitto|cloud9|zigbee2mqtt)$ ]]; then
echo "This suite can't be installed on Raspberry Pi Zero..."
exit 0
fi
Expand Down