A custom version of a Smart Mirror
- Raspberry Pi con Raspberry Pi OS (Debian-based)
- Python 3.9+
- Conexión a internet
# Tkinter (interfaz gráfica), fuentes y dependencias para OpenCV con soporte de ventanas
sudo apt-get update
sudo apt-get install -y python3-tk python3-venv fonts-roboto libgtk2.0-dev pkg-configgit clone https://github.com/<tu-usuario>/smart_mirror.git
cd smart_mirrorpython3 -m venv .venv
source .venv/bin/activate
# Asegúrate de NO tener instalada la versión headless de OpenCV:
pip uninstall -y opencv-python-headless
# Instala la versión normal de OpenCV (con soporte de ventanas):
pip install opencv-python
pip install -r requirements.txtCopy the configuration template and edit it with your credentials:
cp configuration_template.json configuration.json
nano configuration.jsonFill in:
- mqtt: Your MQTT broker address, user, and password
- homeAssistant: Your Home Assistant URL and long-lived access token
- openWeather: Your coordinates and OpenWeatherMap API key
Important: This is a GUI app (tkinter). It must run from a desktop session with a display. It will NOT work over SSH unless you forward the display (see below).
Open a terminal on the Pi (physically or via VNC) and run:
cd ~/smart_mirror
source .venv/bin/activate
python3 smartmirror.py# From the Pi's SSH session, set DISPLAY to the local screen:
export DISPLAY=:0
cd ~/smart_mirror
source .venv/bin/activate
python3 smartmirror.pyThe mirror should start automatically when the Pi boots into the desktop.
sudo raspi-config
# Navigate to: System Options → Boot / Auto Login → Desktop Autologinmkdir -p ~/.config/autostart
cp services/smartmirror.desktop ~/.config/autostart/
# Edit the Exec path in the .desktop file if your install path differs from ~/smart_mirrorThe mirror will launch fullscreen after the desktop loads on every reboot.
If you have a USB camera connected and want to expose it as an RTSP stream (for Frigate or the Smart Mirror face detection), use MediaMTX via Docker.
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
newgrp docker
# Verify:
docker run hello-world
docker compose versionmkdir -p ~/mediamtx
cd ~/mediamtxCreate docker-compose.yml:
# docker-compose.yml
version: "3.8"
services:
mediamtx:
image: bluenviron/mediamtx:latest
container_name: mediamtx
restart: unless-stopped
network_mode: host
volumes:
- ./mediamtx.yml:/mediamtx.ymlCreate mediamtx.yml:
# mediamtx.yml
rtmp: no
paths:
live:
source: publishercd ~/mediamtx
docker compose up -d
# Verify it started correctly:
docker logs -f mediamtxMake sure your user has access to the video device:
ls -l /dev/video0
sudo usermod -aG video $USER
# Log out and back in (or run: newgrp video)Install ffmpeg if not present:
sudo apt-get install -y ffmpegStart publishing the USB camera to MediaMTX:
ffmpeg -f v4l2 -s 640x480 -i /dev/video0 \
-c:v h264_v4l2m2m -b:v 2M -r 15 -g 30 -an \
-f rtsp rtsp://localhost:8554/liveThe stream will be available at:
- RTSP:
rtsp://<PI_IP>:8554/live
cameras:
smartmirror_usb:
ffmpeg:
inputs:
- path: rtsp://<PI_IP>:8554/live
roles:
- detectFaceDetectorApp(source="rtsp://localhost:8554/live")These systemd services run background scripts for TV control and temperature monitoring:
# Edit the paths in the .service files to match your install location and username
sudo cp services/checkTv.service /etc/systemd/system/
sudo cp services/tempChecker.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable checkTv.service tempChecker.service
sudo systemctl start checkTv.service tempChecker.serviceTo ensure the USB camera RTSP stream is always available after boot, use the provided systemd service:
# Edit the service file if your user is not 'pi':
nano services/usbcam_stream.service
# (Change User=pi to your username if needed)
sudo cp services/usbcam_stream.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable usbcam_stream.service
sudo systemctl start usbcam_stream.service
# Check status:
sudo systemctl status usbcam_stream.serviceThis will automatically start the ffmpeg stream to MediaMTX on every boot, so the camera is always available for Frigate and the Smart Mirror.
| Package | Purpose |
|---|---|
requests |
HTTP requests (weather, Home Assistant) |
paho-mqtt |
MQTT communication |
pytz |
Timezone handling |
ephem |
Astronomical calculations (moon, sun) |
psutil |
System resource monitoring |
Pillow |
Image processing (PIL) |
opencv-python |
Camera and face detection (con soporte de ventanas) |
RPi.GPIO |
Raspberry Pi GPIO pins |
Nota importante sobre OpenCV: Si ves errores como "The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support...", asegúrate de:
- Tener instaladas las dependencias del sistema:
libgtk2.0-dev pkg-config- Usar la versión normal de OpenCV (
opencv-python), no la versión headless.- Desinstalar
opencv-python-headlesssi está presente.
Note:
tkinteris required but is a system package — installed viapython3-tkin step 1.
- Datetime
- Forecast
- Events
- Moon Phase
- Sunset / Sunrise
- Picture Slide
- Face recognition
- Home Assistant Connection
- Mqtt Connection
Zarus Smart Mirror is an open source code. All files are licenced under Creative Commons Reconocimiento-NoComercial-CompartirIgual 4.0 Internacional

