Initial setup with zigbee2mqtt
This commit is contained in:
parent
06df8aefe0
commit
9a692e4c01
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
docker-compose.yml
|
||||||
# ---> Linux
|
# ---> Linux
|
||||||
*~
|
*~
|
||||||
|
|
||||||
|
26
Makefile
Normal file
26
Makefile
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
DOCKER_COMP = sudo docker-compose
|
||||||
|
|
||||||
|
help:
|
||||||
|
echo Help is not yet implemented...
|
||||||
|
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(DOCKER_COMP) build
|
||||||
|
|
||||||
|
up: ## Starts the docker hub
|
||||||
|
$(DOCKER_COMP) up -d
|
||||||
|
|
||||||
|
down: ## Stops the docker hub
|
||||||
|
$(DOCKER_COMP) down --remove-orphans
|
||||||
|
|
||||||
|
restart: ## Restarts the docker hub
|
||||||
|
$(DOCKER_COMP) restart
|
||||||
|
|
||||||
|
shell_%: ## Connects to the application container
|
||||||
|
$(DOCKER_COMP) exec $(subst shell_,,$@) bash
|
||||||
|
|
||||||
|
logs_%: ## Displays the logs of the application container
|
||||||
|
$(DOCKER_COMP) logs -f $(subst logs_,,$@)
|
||||||
|
|
||||||
|
cleanall:
|
||||||
|
sudo docker system prune -a
|
3
template/Dockerfile
Normal file
3
template/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM debian:bookworm
|
||||||
|
RUN echo $TESTVAR_1 > /root/test.txt
|
||||||
|
COPY start.sh /root
|
14
template/docker-compose.template
Normal file
14
template/docker-compose.template
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#version: '3'
|
||||||
|
#services:
|
||||||
|
|
||||||
|
template:
|
||||||
|
restart: always
|
||||||
|
build: template
|
||||||
|
container_name: template
|
||||||
|
#network_mode: host
|
||||||
|
#privileged: true
|
||||||
|
#devices:
|
||||||
|
# - /dev/ttyACM0:/dev/ttyACM0
|
||||||
|
#volumes:
|
||||||
|
# - /opt/zigbee2mqtt:/opt/zigbee2mqtt
|
||||||
|
command: bash -c "/root/start.sh"
|
10
template/start.sh
Executable file
10
template/start.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
echo "************************************"
|
||||||
|
echo "* This is a template only! *"
|
||||||
|
echo "* No Application has been started. *"
|
||||||
|
echo "************************************"
|
||||||
|
for (( ; ; ))
|
||||||
|
do
|
||||||
|
sleep 60
|
||||||
|
done
|
13
zigbee/Dockerfile
Normal file
13
zigbee/Dockerfile
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
FROM debian:bookworm
|
||||||
|
RUN apt update
|
||||||
|
RUN apt upgrade -y
|
||||||
|
RUN apt install curl git -y
|
||||||
|
# INSTALL nodejs
|
||||||
|
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
||||||
|
RUN apt install nodejs -y
|
||||||
|
# INSTALL yarn
|
||||||
|
RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null
|
||||||
|
RUN echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list
|
||||||
|
RUN apt update
|
||||||
|
RUN apt install yarn -y
|
||||||
|
COPY start.sh /root
|
28
zigbee/README
Normal file
28
zigbee/README
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
Install intruction:
|
||||||
|
===================
|
||||||
|
|
||||||
|
Configuration:
|
||||||
|
--------------
|
||||||
|
* Append the docker-compose.template to your docker-compose.yml
|
||||||
|
* Edit the volumes section, to have a persistant zigbee2mqtt instance
|
||||||
|
at your local filesystem (fist entry is your local filesystem;
|
||||||
|
leave the second entry ontouched)
|
||||||
|
* Edit the environment variable of the added service, if you need to
|
||||||
|
create a zigbee2mqtt instance or
|
||||||
|
delete the variables, if you want to run an existing instance.
|
||||||
|
* Check and edit (if needed) the device section (first entry is your host filesystem)
|
||||||
|
* You might want to set differing versions for the needed software:
|
||||||
|
* The base operating system is defined in the Dockerfile (very top entry)
|
||||||
|
* The nodejs is defined in the Dockerfile (curl after #INSTALL nodejs)
|
||||||
|
* The zigbee2mqtt is already defined via the docker-compose.yml
|
||||||
|
|
||||||
|
Installation:
|
||||||
|
-------------
|
||||||
|
* Execute make build up logs_zigbee
|
||||||
|
|
||||||
|
Post-Installation actions:
|
||||||
|
--------------------------
|
||||||
|
* You should remove the environments section espacially the credentials
|
||||||
|
from docker-compose.yml
|
||||||
|
* You should "chmod go-rwx" for ...zigbee2mqtt/data/configuration.yaml
|
||||||
|
|
20
zigbee/docker-compose.template
Normal file
20
zigbee/docker-compose.template
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#version: '3'
|
||||||
|
#services:
|
||||||
|
|
||||||
|
zigbee:
|
||||||
|
restart: always
|
||||||
|
build: zigbee
|
||||||
|
container_name: zigbee
|
||||||
|
volumes:
|
||||||
|
- /opt/zigbee2mqtt:/opt/zigbee2mqtt
|
||||||
|
environment:
|
||||||
|
APP_GIT_VERSION: 1.31.2
|
||||||
|
#APP_MQTT_SERVER: mqtt_server
|
||||||
|
#APP_MQTT_USER: mqtt_user
|
||||||
|
#APP_MQTT_PASSWORD: mqtt_password
|
||||||
|
network_mode: host
|
||||||
|
#privileged: true
|
||||||
|
devices:
|
||||||
|
- /dev/ttyACM0:/dev/ttyACM0
|
||||||
|
command: bash -c "/root/start.sh"
|
||||||
|
|
73
zigbee/start.sh
Executable file
73
zigbee/start.sh
Executable file
@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
|
||||||
|
APP_TARGET_PATH=/opt/zigbee2mqtt
|
||||||
|
|
||||||
|
my_print()
|
||||||
|
{
|
||||||
|
echo `date` $HOST [$$]: $1
|
||||||
|
}
|
||||||
|
|
||||||
|
fail_loop()
|
||||||
|
{
|
||||||
|
my_print "Start script failed..."
|
||||||
|
for (( ; ; ))
|
||||||
|
do
|
||||||
|
sleep 60
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
check_environment()
|
||||||
|
{
|
||||||
|
fail=0
|
||||||
|
# returns 0 if environment is not okay
|
||||||
|
if [[ -z $APP_GIT_VERSION ]]; then
|
||||||
|
my_print "Environment variable APP_GIT_VERSION does not exist!"
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
|
if [[ -z $APP_MQTT_SERVER ]]; then
|
||||||
|
my_print "Environment variable APP_MQTT_SERVER does not exist!"
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
|
#
|
||||||
|
if [[ $fail -ne 0 ]]; then
|
||||||
|
fail_loop
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if [[ ! -d $APP_TARGET_PATH ]]; then
|
||||||
|
my_print "Directory \"$APP_TARGET_PATH\" does not exist."
|
||||||
|
fi
|
||||||
|
if [[ ! -d $APP_TARGET_PATH/.git ]]; then
|
||||||
|
check_environment
|
||||||
|
my_print "Cloning zigbee2mqtt repository..."
|
||||||
|
git clone https://github.com/Koenkk/zigbee2mqtt.git $APP_TARGET_PATH
|
||||||
|
my_print "Changing to directory $APP_TARGET_PAT"
|
||||||
|
cd $APP_TARGET_PATH
|
||||||
|
my_print "Changing to git version $APP_GIT_VERSION"
|
||||||
|
git checkout $APP_GIT_VERSION
|
||||||
|
my_print "Replacing MQTT servername in $APP_TARGET_PATH/data/configuration.yaml"
|
||||||
|
sed -i "s|mqtt://localhost|mqtt://$APP_MQTT_SERVER|g" $APP_TARGET_PATH/data/configuration.yaml
|
||||||
|
if [[ ! -z $APP_MQTT_USER ]]; then
|
||||||
|
my_print "Adding MQTT username in $APP_TARGET_PATH/data/configuration.yaml"
|
||||||
|
sed -i "s|# user: my_user|user: $APP_MQTT_USER|g" $APP_TARGET_PATH/data/configuration.yaml
|
||||||
|
fi
|
||||||
|
if [[ ! -z $APP_MQTT_PASSWORD ]]; then
|
||||||
|
my_print "Adding MQTT password in $APP_TARGET_PATH/data/configuration.yaml"
|
||||||
|
sed -i "s|# password: my_password|password: $APP_MQTT_PASSWORD|g" $APP_TARGET_PATH/data/configuration.yaml
|
||||||
|
fi
|
||||||
|
my_print "Preparing application (npm ci)"
|
||||||
|
npm ci
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $APP_TARGET_PATH
|
||||||
|
my_print "Starting zigbee2mqtt..."
|
||||||
|
npm start
|
||||||
|
|
||||||
|
my_print "**********************************************************"
|
||||||
|
my_print "* Start of zigbee2mqtt failed. *"
|
||||||
|
my_print "* Check running npm ci and npm start in /opt/zigbee2mqtt *"
|
||||||
|
my_print "**********************************************************"
|
||||||
|
fail_loop
|
Loading…
x
Reference in New Issue
Block a user