Skip to content

andygmassey/rpi-smart-home-project

Repository files navigation

Raspberry Pi Smart Home Project

License: MIT Platform Docker GitHub Release GitHub Stars

A comprehensive smart home automation system running on Raspberry Pi CM4 with reTerminal display.

reTerminal Smart Home Dashboard

🎯 Perfect for: Home automation enthusiasts, Raspberry Pi tinkerers, and anyone wanting a self-hosted smart home hub with professional monitoring and network management.

🏠 Overview

This project provides a complete smart home solution featuring real-time monitoring, automation, network management, and hardware control - all running in a secure, containerized environment.

🌟 Why This Project?

  • 🏡 Complete Solution: Everything you need for home automation in one place
  • 🔒 Privacy-First: Self-hosted, no cloud dependencies
  • 📊 Professional Monitoring: Grafana dashboards rival enterprise solutions
  • 🎮 Hardware Integration: Custom GPIO button controls for the reTerminal
  • 💾 Disaster Recovery: Automated backup system with restore scripts
  • 🛡️ Network Protection: Built-in ad-blocking and DNS filtering
  • 🔧 Production-Ready: Watchdog systems, health checks, and auto-recovery

✨ Key Features

  • 🏡 Home Automation: Home Assistant with full supervisor support
  • 📊 Real-time Monitoring: Grafana + InfluxDB with custom dashboards
  • 🌐 Network Management: Pi-hole DNS filtering and MQTT broker
  • 📱 Unified Dashboard: Homepage with service overview
  • ⚡ Service Monitoring: Uptime Kuma for availability tracking
  • 🔧 Hardware Control: Custom Python scripts for reTerminal
  • 💾 Automated Backups: Comprehensive backup and restore system
  • 🛡️ System Health: Automated monitoring with email alerts
  • 🎮 Kiosk Mode: Full-screen display modes for dashboards

🏗️ System Architecture

Services Stack

┌─────────────────────────────────────────────────┐
│                 reTerminal Display               │
│        (Hardware Controls & Kiosk Mode)         │
├─────────────────────────────────────────────────┤
│              Homepage Dashboard                 │
│         (Unified Service Overview)              │
├─────────────────────────────────────────────────┤
│  Home Assistant  │  Grafana    │  Pi-hole      │
│  (Automation)    │ (Analytics) │  (DNS/AdBlock)│
├──────────────────┼─────────────┼───────────────┤
│   InfluxDB       │ Uptime Kuma │ MQTT Broker   │
│ (Time Series DB) │ (Monitoring)│ (IoT Messages)│
├─────────────────────────────────────────────────┤
│              Docker Container Layer             │
├─────────────────────────────────────────────────┤
│           Raspberry Pi OS (Debian)              │
└─────────────────────────────────────────────────┘

Hardware

  • Platform: Raspberry Pi CM4 with reTerminal
  • Storage: eMMC (no SD card dependencies)
  • Display: Built-in touchscreen with custom controls
  • Connectivity: Ethernet, WiFi, GPIO access

📋 Services Overview

Service Purpose Web Interface Port
Home Assistant Automation Hub http://YOUR_DEVICE_IP:8123 8123
Grafana Data Visualization http://YOUR_DEVICE_IP:3002 3002
InfluxDB Metrics Database - 8086
Pi-hole DNS + Ad Blocking http://YOUR_DEVICE_IP/admin 80
Homepage Unified Dashboard http://YOUR_DEVICE_IP:3002 3002
Uptime Kuma Service Monitoring http://YOUR_DEVICE_IP:3001 3001
MQTT Broker IoT Messaging - 1883
Fing Agent Network Discovery - -

🚀 Quick Start

Prerequisites

  • Raspberry Pi CM4 with reTerminal
  • Docker and Docker Compose installed
  • Git configured

Installation

# Clone repository
git clone https://github.com/andygmassey/rpi-smart-home-project.git
cd rpi-smart-home-project

# Setup environment
cp .env.example .env
nano .env  # Configure your passwords

# Deploy services
./scripts/system/deploy-all-services.sh

# Access main dashboard
open http://YOUR_DEVICE_IP:3002

📚 Documentation

📖 Complete Guides

🗂️ Quick References

🗂️ Directory Structure

📁 rpi-smart-home-project/
├── 📁 scripts/
│   ├── 📁 backup/          # Backup and restore automation
│   ├── 📁 monitoring/      # System health and metrics
│   ├── 📁 system/          # Service management utilities  
│   └── 📁 hardware/        # reTerminal hardware control
├── 📁 docker/              # Docker Compose configurations
│   ├── 📁 grafana-influx/  # Monitoring stack
│   ├── 📁 pihole/          # DNS and ad-blocking
│   ├── 📁 homepage/        # Unified dashboard
│   ├── 📁 uptime-kuma/     # Service monitoring
│   ├── 📁 mqtt-broker/     # IoT messaging
├── 📁 docs/                # Comprehensive documentation
├── 📄 .env.example         # Environment configuration template
└── 📄 .gitignore          # Security-focused exclusions

🔧 Script Reference

💾 Backup Scripts (scripts/backup/)

  • backup-manager.sh - Interactive backup management
  • create-app-backup.sh - Application data backup
  • create-master-backup.sh - Golden master backup
  • create-system-backup.sh - Full system backup
  • backup-to-external.sh - External drive backup

📊 Monitoring Scripts (scripts/monitoring/)

  • rpi_vitals_monitor.sh - System metrics collection
  • continuous_monitoring.sh - 24/7 health monitoring
  • timezone_monitoring_script.sh - Timezone change tracking

⚙️ System Scripts (scripts/system/)

  • manage-services.sh - Docker service management
  • launch-ha-kiosk.sh - Home Assistant kiosk mode
  • control-kiosk.sh - Display control utilities
  • setup-vnc-remote.sh - Remote access setup

🔧 Hardware Scripts (scripts/hardware/)

  • multi_button_handler.py - reTerminal button control

🛡️ Pi-hole Watchdog System

Pi-hole provides network-wide DNS and ad-blocking with a bulletproof 3-layer watchdog system:

Coordinated Protection Layers

Layer Responsibility Mechanism
Layer 1 Container crashes Docker restart policy
Layer 2 Service unhealthy Smart watchdog script (every 2 min)
Layer 3 System boot Systemd service

Features

  • Cooldown Protection: 5-minute minimum between restarts, max 3/hour
  • Escalation: Cleanup → Soft restart → Hard restart → Alert
  • Unlocator SmartDNS: Upstream DNS for geo-unblocking streaming services
  • Database Capped: 7-day retention prevents runaway growth

See docs/WATCHDOG_SYSTEM.md for full documentation.

🌐 VPN Routing Infrastructure

Dual VPN Architecture

The system runs two concurrent OpenVPN tunnels for geographic traffic routing:

Tunnel Interface Purpose Provider
Primary VPN tun0 Default traffic routing Unlocator (US)
UK VPN tun1 Streaming geo-access Unlocator (UK London)

Route Pinning

Both tunnels use route-nopull to prevent server-pushed routes, since Unlocator can assign the same IP pair to both tunnels, causing route confusion. Routes are added explicitly with dev tun0/dev tun1 by post-connect scripts:

  • Primary VPN: setup-main-vpn-routes.sh pins 0.0.0.0/1 and 128.0.0.0/1 to dev tun0 via OpenVPN route-up
  • UK VPN: setup-prime-routing.sh creates the ukvpn policy routing table for device-based routing through dev tun1

Policy-Based Routing (UK VPN)

Selective traffic routing uses Linux policy routing (ip rule / ip route) to send specific LAN devices through the UK tunnel:

  • Dedicated routing table (ukvpn): Separate routing table for UK-bound traffic
  • Source-based routing: Specific LAN devices are policy-routed through the UK tunnel via ip rule
  • NAT masquerade: Traffic from routed devices is NATed on tun1 for proper return routing

SOCKS5 Proxy

A SOCKS5 proxy (microsocks) runs on port 1080, bound to tun0's IP for VPN-routed access from other devices:

Service Port Description
vpn-proxy.service 1080 SOCKS5 proxy via VPN (microsocks)
vpn-proxy-watchdog.timer Health check every 2 min, auto-restarts on failure

Systemd Services

Service Config Description
unlocator-vpn.service /etc/openvpn/unlocator/client.ovpn Primary VPN tunnel (tun0)
uk-vpn-prime.service /etc/openvpn/client/uk-vpn.conf UK VPN tunnel + routing setup (tun1)
vpn-proxy.service SOCKS5 proxy bound to tun0

Routing scripts:

  • /usr/local/bin/setup-main-vpn-routes.sh — Pins default routes to tun0 (called by OpenVPN route-up)
  • /usr/local/bin/setup-prime-routing.sh — Creates policy routing table, ip rules, and NAT on UK VPN start
  • /usr/local/bin/cleanup-prime-routing.sh — Removes UK routing rules on VPN stop

Management

# Check status
sudo systemctl status unlocator-vpn uk-vpn-prime vpn-proxy

# Restart all VPN (order matters: main first, then UK, then proxy)
sudo systemctl restart unlocator-vpn && sleep 12 && sudo systemctl restart uk-vpn-prime && sleep 15 && sudo systemctl restart vpn-proxy

# Verify routing
ip route | grep tun           # Default routes should be dev tun0
ip rule list                  # Apple TV policy rule
ip route show table ukvpn     # UK routing table

🐳 Docker Services

All services run in isolated Docker containers with persistent data storage:

Core Stack

# Start monitoring stack
cd docker/grafana-influx && docker-compose up -d

# Start network services  
cd ../pihole && docker-compose up -d
cd ../mqtt-broker && docker-compose up -d

# Start dashboards
cd ../homepage && docker-compose up -d
cd ../uptime-kuma && docker-compose up -d

Service Health

# Check all services
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"

# Monitor resources
docker stats --no-stream

💾 Backup System

Automated Backups

  • System Health Monitoring: Every 6 hours with email alerts
  • Vitals Collection: Every minute to InfluxDB
  • Application Backup: Weekly automated backup
  • Configuration Backup: Continuous Git versioning

Manual Backup

# Quick application backup
./scripts/backup/create-app-backup.sh

# Full system backup
./scripts/backup/create-master-backup.sh

# Interactive backup manager
./scripts/backup/backup-manager.sh

Restore Operations

# List available backups
ls ~/backups/

# Restore from backup
./scripts/backup/backup-manager.sh restore

⚡ Hardware Control

reTerminal Integration

# Start button handler
python3 scripts/hardware/multi_button_handler.py

# Launch kiosk mode
./scripts/system/launch-ha-kiosk.sh

# Control display
./scripts/system/control-kiosk.sh [start|stop|restart]

Hardware Features

  • Multi-button Control: Custom actions for hardware buttons
  • Display Management: Automatic brightness and power control
  • GPIO Integration: Full access to Raspberry Pi GPIO
  • Touch Interface: Direct touchscreen interaction

🛡️ Security Features

Data Protection

  • 🔐 Environment Variables: No hardcoded passwords
  • 🗂️ Comprehensive .gitignore: Sensitive files excluded
  • 🔒 Private Repository: Code safely stored
  • 🛡️ Container Isolation: Services run in isolated containers

Network Security

  • 🌐 Pi-hole DNS Filtering: Network-wide ad and malware blocking
  • 🔒 Local Network Only: No external dependencies required
  • 📊 Traffic Monitoring: Full network visibility

System Monitoring

  • 📊 Real-time Metrics: System health dashboards
  • 📧 Email Alerts: Automated problem notifications
  • 📈 Historical Data: Long-term performance tracking

📊 Monitoring & Alerts

System Health Monitoring

The system automatically monitors:

  • Memory Usage: Alerts at >90%
  • Swap Usage: Alerts at >50%
  • CPU Temperature: Alerts at >80°C
  • Load Average: Alerts at >8.0
  • Service Status: Container health checks
  • Disk Space: Storage monitoring

Alert Destinations

  • Email Notifications: Configurable SMTP alerts
  • Dashboard Alerts: Grafana alert rules
  • Service Monitoring: Uptime Kuma notifications

🔄 Development & Maintenance

Version Control

# Make changes
git add .
git commit -m "Update configuration"
git push

# Create feature branch
git checkout -b new-feature

Maintenance Tasks

# System updates
sudo apt update && sudo apt upgrade -y

# Docker cleanup
docker system prune -f

# Service restart
./scripts/system/manage-services.sh restart

🆘 Support & Troubleshooting

Common Commands

# Check system health
./scripts/monitoring/system-health-check.sh

# View service logs
docker logs <service-name>

# Restart all services
./scripts/system/manage-services.sh restart

# Emergency backup
./scripts/backup/create-app-backup.sh

Documentation

Getting Help

  1. Check service logs: docker logs <service>
  2. Run system health check: ./scripts/monitoring/system-health-check.sh
  3. Review documentation in docs/ directory
  4. Check GitHub issues for known problems

🏆 Project Status

✅ Production Ready

  • All services deployed and monitored
  • Comprehensive backup system active
  • Full documentation complete
  • Security hardening implemented
  • Hardware integration functional

🎯 Use Cases

This project is ideal for:

  • 🏠 Home Automation Enthusiasts: Complete control over your smart home
  • 🔐 Privacy-Conscious Users: Keep your data on your own hardware
  • 📊 Data Nerds: Beautiful real-time dashboards for system monitoring
  • 🎓 Learning Projects: Great for understanding Docker, networking, and automation
  • 🏢 Home Lab: Professional-grade monitoring for your home network
  • 🌐 Network Administrators: Family network management with ad-blocking and DNS control

🗺️ Roadmap

Future enhancements being considered:

  • Zigbee/Z-Wave device integration examples
  • Energy monitoring dashboards
  • Automated offsite backup to cloud storage
  • Mobile app companion
  • Voice assistant integration (Alexa/Google Home)
  • Advanced automation examples
  • Kubernetes deployment option
  • Multi-device support documentation

Have an idea? Open an issue or discussion to suggest new features!

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Thanks to everyone who has contributed to this project!

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Third-party Docker images and services retain their respective licenses. See LICENSE for full details.

🙏 Acknowledgments

  • Pi-hole - Network-wide ad blocking
  • Home Assistant - Open source home automation
  • Grafana - Beautiful monitoring dashboards
  • SeeedStudio - reTerminal hardware platform
  • Raspberry Pi Foundation - Amazing single-board computers

💬 Community & Support


⬆ Back to Top

Made with ❤️ for the home automation community

⭐ Star this repo if you find it useful!

About

Smart home automation system for Raspberry Pi CM4 with reTerminal display. Features Home Assistant, Grafana monitoring, Pi-hole ad-blocking, and unified dashboard - all self-hosted and containerized.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors