Compare commits

..

24 Commits

Author SHA1 Message Date
John Lancaster
e7a6a5ab1f script updates 2024-09-29 21:50:12 +00:00
John Lancaster
b2088dd656 submodule update 2024-08-02 12:24:56 -05:00
John Lancaster
4702afa467 script updates 2024-06-15 16:41:08 -05:00
John Lancaster
9ef7d4ec19 readme update 2024-06-15 16:30:03 -05:00
John Lancaster
ec4e5cc46a readme update 2024-06-15 16:29:11 -05:00
John Lancaster
53210d85e3 script updates 2024-06-15 16:25:26 -05:00
John Lancaster
4da1b20875 submodule update 2024-05-27 19:22:40 -05:00
John Lancaster
5483502675 updates to make better use of restic-scripts 2024-05-27 19:21:20 -05:00
John Lancaster
76efdb0274 readme update 2024-05-19 20:37:19 -05:00
John Lancaster
3d2da83452 readme updates 2024-05-19 20:34:59 -05:00
John Lancaster
a431216cfe added readme content 2024-05-19 20:20:16 -05:00
John Lancaster
29079011d7 added backup scripts 2024-05-19 20:11:37 -05:00
John Lancaster
b22f4a436b submodule updates 2024-05-19 19:46:12 -05:00
John Lancaster
d45ba97a8f some updates 2024-05-19 17:17:51 -05:00
root
ee7fa752bc removed permit_join true 2023-11-19 16:10:38 -06:00
root
36d7745289 keeping log folder 2023-11-18 17:29:41 -06:00
root
730f0cdf17 tweak 2023-11-17 11:24:07 -06:00
root
408b491ba1 changed terminal printout 2023-11-17 11:18:44 -06:00
root
4780bc887b changed permissions on secret.yaml 2023-11-17 11:16:46 -06:00
root
7a8ef0bd85 healthcheck is too intense 2023-11-17 11:15:07 -06:00
root
5ceae952a1 removed need for .env file 2023-11-17 10:58:21 -06:00
root
070ecf778a errors out if no env file is found 2023-11-17 10:55:31 -06:00
root
588de129eb more volumes mapped 2023-11-17 10:51:40 -06:00
root
d872f005af improved cleanup 2023-11-17 10:51:32 -06:00
15 changed files with 242 additions and 51 deletions

7
.gitmodules vendored Normal file
View File

@@ -0,0 +1,7 @@
[submodule "docker-observation"]
path = docker-observation
url = https://gitea.john-stream.com/john/docker-observation.git
branch = main
[submodule "restic-scripts"]
path = restic-scripts
url = https://gitea.john-stream.com/john/restic-scripts

1
.python-version Normal file
View File

@@ -0,0 +1 @@
json

View File

@@ -2,14 +2,48 @@
Zigbee smarthome stack
- Mosquitto ([eclipse-mosquitto](https://hub.docker.com/_/eclipse-mosquitto))
- Zigbee2MQTT (koenkk/[zigbee2mqtt](https://hub.docker.com/r/koenkk/zigbee2mqtt/))
| Service | Name | Image |
|---------|-------------|----------------------|
| mqtt | mosquitto | [eclipse-mosquitto] |
| z2m | zigbee2mqtt | [koenkk/zigbee2mqtt] |
[eclipse-mosquitto]: https://hub.docker.com/_/eclipse-mosquitto
[koenkk/zigbee2mqtt]: https://hub.docker.com/r/koenkk/zigbee2mqtt
## Setup
1. Create `.env` file with `MOSQUITTO_PASSWORD`.
2. Run setup script
### 1. Create LXC in Proxmox
```
./scripts/setup.sh
```
```title="Proxmox helper script"
bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/ct/docker.sh)"
```
### 2. Clone repo
```bash
git clone https://gitea.john-stream.com/john/zigbee-stack
```
### 3. Setup script
```bash
./zigbee-stack/scripts/setup.sh
```
Process:
- clears all the existing data, except certain files
- asks for a new MQTT password, which gets saved in `./zigbee2mqtt/secret.yaml`
- runs `docker compose up ...`
### 4. Mount backup
Mount from within Proxmox using the `pct` tool.
```bash
pct set $VMID -mp0 $BACKUP_DIR,mp=/mnt/backups
```
### 5. Set env variables
Follow [instructions](https://gitea.john-stream.com/john/restic-scripts#environment-variables) as part of `restic-scripts`

View File

@@ -1,4 +1,6 @@
version: "3"
include:
- ./docker-observation/docker-compose.yml
services:
mqtt:
container_name: mosquitto
@@ -7,24 +9,18 @@ services:
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./mosquitto:/mosquitto
- ./mosquitto/config:/mosquitto/config
- ./mosquitto/data:/mosquitto/data
- ./mosquitto/log:/mosquitto/log
ports:
- 1883:1883
healthcheck:
test: ["CMD", "mosquitto_sub", "-t", "$$SYS/#", "-C", "1", "-i", "healthcheck", "-W", "3", "--port", "1880"]
start_period: 15s
start_interval: 1s
interval: 5s
timeout: 10s
retries: 5
z2m:
container_name: zigbee2mqtt
image: koenkk/zigbee2mqtt
restart: unless-stopped
depends_on:
mqtt:
condition: service_healthy
- mqtt
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro

1
docker-observation Submodule

Submodule docker-observation added at 1ee44b7b80

0
mosquitto/log/.gitkeep Normal file
View File

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
pydantic>=2,<3

1
restic-scripts Submodule

Submodule restic-scripts added at 0086878d57

20
scripts/backup.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -e
if [ -z "$BACKUP_DIR" ]; then
echo "Error: BACKUP_DIR is not set."
exit 1
fi
if [ -z "$RESTIC_REPOSITORY" ]; then
echo "Error: RESTIC_REPOSITORY is not set."
exit 1
fi
if [ -z "$RESTIC_PASSWORD" ]; then
echo "Error: RESTIC_PASSWORD is not set."
exit 1
fi
python -m restic.backup --project zigbee-stack --services mqtt,z2m "$@"

View File

@@ -1,13 +1,34 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
REPO_DIR=$(dirname $SCRIPT_DIR)
cleanup_except() {
local directory=$1
local except_file=$2
rm -rf \
$REPO_DIR/mosquitto/config/pwfile \
$REPO_DIR/mosquitto/data/mosquitto.db \
$REPO_DIR/zigbee2mqtt/secret.yaml \
$REPO_DIR/zigbee2mqtt/*.json \
$REPO_DIR/zigbee2mqtt/log/* \
$REPO_DIR/zigbee2mqtt/database.db \
# Check if the directory exists
if [[ ! -d "$directory" ]]; then
echo "Directory does not exist: $directory"
return 1
fi
# Loop over each file in the directory
for file in "$directory"/*
do
if [[ "$(basename "$file")" != "$except_file" ]]; then
# Delete the file
rm -rf "$file"
echo "Removed $file"
fi
done
}
readonly SCRIPT_DIR=$(dirname $(readlink -f "${BASH_SOURCE[0]}"))
readonly REPO_DIR=$(cd $(dirname $SCRIPT_DIR) && pwd)
docker compose down
cleanup_except "$REPO_DIR/mosquitto/config" mosquitto.conf
cleanup_except "$REPO_DIR/mosquitto/data" .gitkeep
cleanup_except "$REPO_DIR/mosquitto/log"
cleanup_except "$REPO_DIR/zigbee2mqtt" configuration.yaml

View File

@@ -1,22 +1,16 @@
#!/bin/bash
#!/usr/bin/env bash
SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
REPO_DIR=$(dirname $SCRIPT_DIR)
COMPOSE_FILE=$REPO_DIR/docker-compose.yml
ENV_FILE=$REPO_DIR/.env
set -e
if [ ! -f "$ENV_FILE" ]; then
echo "Error: .env file not found."
exit 1
else
source "$ENV_FILE"
fi
readonly SCRIPT_DIR=$(dirname $(readlink -f "${BASH_SOURCE[0]}"))
readonly REPO_DIR=$(cd $(dirname $SCRIPT_DIR) && pwd)
if [ -z "$MOSQUITTO_PASSWORD" ]; then
echo "MOSQUITTO_PASSWORD is not set. Exiting."
exit 1
fi
echo "Please input the mosquitto password:"
read -s MOSQUITTO_PASSWORD
docker compose -f $COMPOSE_FILE run -it --rm mqtt mosquitto_passwd -b -c /mosquitto/config/pwfile homeassistant $MOSQUITTO_PASSWORD
docker compose run -it --rm mqtt mosquitto_passwd -b -c /mosquitto/config/pwfile homeassistant $MOSQUITTO_PASSWORD
chown root:root $REPO_DIR/mosquitto/config/pwfile
echo "password: $MOSQUITTO_PASSWORD" > $REPO_DIR/zigbee2mqtt/secret.yaml
chmod 600 $REPO_DIR/zigbee2mqtt/secret.yaml

7
scripts/forget.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
python -m restic.forget \
--keep-last 5 \
--keep-weekly 8 \
--keep-monthly 12 \
--keep-yearly 7

View File

@@ -1,10 +1,11 @@
#!/bin/bash
#!/usr/bin/env bash
SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
REPO_DIR=$(dirname $SCRIPT_DIR)
COMPOSE_FILE=$REPO_DIR/docker-compose.yml
set -e
readonly SCRIPT_DIR=$(dirname $(readlink -f "${BASH_SOURCE[0]}"))
readonly REPO_DIR=$(cd $(dirname $SCRIPT_DIR) && pwd)
$SCRIPT_DIR/clear_data.sh
$SCRIPT_DIR/create_password.sh
docker compose -f $COMPOSE_FILE up -d
docker compose up -d

13
scripts/update.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
REPO_DIR=$(dirname $SCRIPT_DIR)
cd $REPO_DIR
git submodule update --remote --init
alias compose="compose -f $REPO_DIR/docker-compose.yml"
docker compose pull
docker compose up -d

View File

@@ -1,5 +1,4 @@
homeassistant: true
permit_join: true
mqtt:
base_topic: zigbee2mqtt
client_id: Zigbee2MQTT
@@ -16,3 +15,98 @@ advanced:
device_options:
legacy: false
frontend: true
devices:
'0x54ef4410005ca806':
friendly_name: Bathroom Motion
'0x00158d0006ca3f53':
friendly_name: Bedroom Motion
'0x00158d000894fb3a':
friendly_name: Closet Motion
'0x00158d0006c49d5f':
friendly_name: Kitchen Motion
'0x00158d0007e22931':
friendly_name: Cube 1
'0x7cb03eaa00a698a6':
friendly_name: Server Lamp
'0x7cb03eaa00a68979':
friendly_name: Desk Lamp
'0xa4c138f4c2fce2ed':
friendly_name: Couch Corner
'0xa4c1388ed789ca18':
friendly_name: Kitchen
description: Under cabinet lights
'0xf0d1b8000001ccc4':
friendly_name: Bedside 2
'0xf0d1b80000021416':
friendly_name: Bedside 1
description: Nearest to the door
'0x00158d0006ba2970':
friendly_name: Living Room Button
legacy: false
'0x00158d0006f3a190':
friendly_name: Bedroom Button 1
description: Nearest to the door
'0x00158d0006ba47e9':
friendly_name: Bedroom Button 2
'0x00158d0007004bc5':
friendly_name: Bathroom Button
'0x00158d0006ba29fb':
friendly_name: Kitchen Button
'0x00158d0006ca405f':
friendly_name: Laundry Motion
'0x7cb03eaa00a69ad3':
friendly_name: Patio
'0xf0d1b8000001d920':
friendly_name: Laundry
'0x001788010ce41962':
friendly_name: Closet Back
'0x001788010ce41939':
friendly_name: Closet Front
'0x001788010cdfb112':
friendly_name: Bathroom Middle
'0x001788010c752d04':
friendly_name: Bathroom Right
'0x001788010cdfb05e':
friendly_name: Bathroom Left
'0x00124b0022305984':
friendly_name: Overhead 1
'0x00124b0022305ad5':
friendly_name: Overhead 2
'0x00124b0022305735':
friendly_name: Overhead 3
'0x00158d0007ef801d':
friendly_name: Back
'0x00158d00067960ef':
friendly_name: Front
'0xa4c1385e575697be':
friendly_name: RGBCCT Strip
'0x00158d0006a0cebe':
friendly_name: Living Room Motion
groups:
'1':
friendly_name: living_room
devices:
- 0x7cb03eaa00a698a6/3
- 0x7cb03eaa00a68979/3
'2':
friendly_name: bedroom
devices:
- 0xf0d1b80000021416/1
- 0xf0d1b8000001ccc4/1
'3':
friendly_name: closet
devices:
- 0x001788010ce41962/11
- 0x001788010ce41939/11
'4':
friendly_name: bathroom
devices:
- 0x001788010cdfb05e/11
- 0x001788010cdfb112/11
- 0x001788010c752d04/11
'5':
friendly_name: overhead
devices:
- 0x00124b0022305984/1
- 0x00124b0022305ad5/1
- 0x00124b0022305735/1