This is not a final product and was created only for the learning porposes.
This project deffinetely has many vulnabilities and probably not safe to use at the moment.
The main purpose of the project was demonstrate ability to interact with IoT devices thought the network.
This is home security project that will include work with RaspberyPi, Raspberry Pico, Zigbee sensors and Mosquitto MQTT brocker.
The main purpose is to create a system that will use various sensors such as movement, presence, open(door/window) and send a screenshot/or short gif from the RaspberryPi Camera to the database and the Bot in the comunication application (Telegram) as well as question what to do: ignore or turn on alarm immediatelly.
The alarm function will be turned on automatically if:
-
There is noone at home (the users are not connected to the home WiFi)
-
It's later than 10PM.
Alarm will turn or lights everywhere on the ground floor, send barking sound of a big dog to the speaker and alarm sound in the bedroom.
The alarm can be turned off by pressing the button or sending the request in the Telegram bot.
RaspberyPi 3b
Picamera
Zigbee Sonoff Dongle-P USB3.0
Zigbee motion sensors
Zigbee door opening sensor
Ziggbe remote button
Python
MQTT
Zigbee
Telegram bot
github.com/KorneAlex/HSP_RPIZIG
Flash the Sonoff dondle with the latest firmware
https://dongle.sonoff.tech/sonoff-dongle-flasher/
sudo git clone https://github.com/KorneAlex/HSP_RPIZIG.git
cd HSP_RPIZIG
sudo install.sh
sudo git clone https://github.com/KorneAlex/HSP_RPIZIG.git
cd HSP_RPIZIG
sudo install.sh
sudo apt-get install -y curl
sudo curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs git make g++ gcc libsystemd-dev
corepack enable
node --version # Should output V20.x
mkdir /opt/zigbee2mqtt
chown -R ${SUDO_USER}: /opt/zigbee2mqtt
git clone --depth 1 https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
cd /opt/zigbee2mqtt
pnpm install --frozen-lockfile
sudo nano /etc/systemd/system/zigbee2mqtt.service
[Unit]
Description=zigbee2mqtt
After=network.target
[Service]
Environment=NODE_ENV=production
Type=notify
ExecStart=/usr/bin/node index.js
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit
StandardError=inherit
WatchdogSec=10s
Restart=always
RestartSec=10s
User=pi
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
sudo systemctl start zigbee2mqtt
systemctl status zigbee2mqtt.service
sudo systemctl enable zigbee2mqtt.service
sudo journalctl -u zigbee2mqtt.service -f
cd /opt/zigbee2mqtt
./update.sh
sudo apt install mosquitto mosquitto-clients
sudo systemctl enable --now mosquitto
nc -vz <rpi_ip> 1883
sudo mosquitto -c /etc/mosquitto/mosquitto.conf
listener 1883 0.0.0.0
allow_anonymous true
log_type all
sudo systemctl restart mosquitto
mosquitto_sub -h <rpi_ip> -t "zigbee2mqtt/#"
sudo nano /etc/systemd/system/my_python_app.service
sudo apt update
apt install -y python3-venv python3-pip python3-dev python3-setuptools meson pipx
git clone https://git.libcamera.org/libcamera/libcamera.git
cd libcamera
meson setup build
cd ..
sudo rm -rf libcamera
sudo apt install python3-paho-mqtt python3-telegram python3-picamera2 sudo apt install ffmpeg
python3 -m pip install --break-system-packages --force-reinstall --upgrade python-telegram-bot
echo "Copying files to /opt/hsp_rpizig..."
mkdir -p /opt/hsp_rpizig
cp -a ./* /opt/hsp_rpizig/
cd /opt/hsp_rpizig/
touch /etc/systemd/system/hsp.service
[Unit]
Description=HomeSecurityProgect_RaspberryPiZigbee
After=network.target mosquitto.service zigbee2mqtt.service
;Requires=mosquitto.service zigbee2mqtt.service
[Service]
Type=simple
User=<USER_NAME>
WorkingDirectory=/opt/hsp_rpizig/
ExecStart=/opt/hsp_rpizig/main.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
touch /etc/systemd/system/hsp_bot.service
[Unit]
Description=HomeSecurityProgect_RaspberryPiZigbee-bot
After=network.target mosquitto.service
[Service]
Type=simple
User=<USER_NAME>
WorkingDirectory=/opt/hsp_rpizig
ExecStart=/usr/bin/python3 /opt/hsp_rpizig/tg.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/hsp_bot.service
chown -R ${SUDO_USER}:${SUDO_USER} /opt/hsp_rpizig/*
systemctl daemon-reload
systemctl enable mosquitto.service zigbee2mqtt.service hsp.service hsp_bot.service
systemctl start mosquitto.service zigbee2mqtt.service hsp.service hsp_bot.service
cp /opt/hsp_rpizig/modules/config_example.py /opt/hsp_rpizig/modules/config.py
sudo chown -R ${SUDO_USER}:${SUDO_USER} /opt/hsp_rpizig/modules/config.py
go to your <RPI_IP>:8080 and chose your Sonoff dondle with Ember setting for E version (for other versions check the Sonoff oficial site https://sonoff.tech/)
in order for zigbee2mqtt to work it needs the port 1883 to be open, the dondle to be latest version (flashed) and mosquitto setvice up and running.
if it doesn't connect, check the mosquitto service for errors.
when connected, you can open the secound terminal and try to listen the broadcast with mosquitto:
mosquitto_sub -h <RPI_IP> -p 1883 -t "zigbee2mqtt/#"
if you see a lot of data then we are good. if not check if you can ping the <RPI_IP> and if the base_topick is correct in the /opt/zigbee2mqtt/data/configuration.yaml
To setup bot please use @BotFather
Add the required information to your /opt/hsp_rpizig/modules/config.py
When everything is fine before the last check retart the RPI.
Try to send commands to the bot.
