Control Your Home with Raspberry Pi
Table of Contents
- 13Preface
Chapter 1: Introduction
- 141.1 What is home automation?
- 151.2 Why use a Raspberry Pi as a home automation gateway?
- 161.3 The properties of a good home automation system
- 171.3.1 Secure
- 181.3.2 Modular
- 191.3.3 Open-Source
- 201.3.4 Self-sufficient
- 231.4 How to use this book
- 251.5 Summary and further exploration
Chapter 2: The Raspberry Pi as a home automation gateway
- 272.1 Which Raspberry Pi models are suitable for home automation?
- 302.2 Requirements for a reliable home automation gateway
- 322.3 Installing Raspberry Pi OS
- 352.4 Setting up network connectivity with Ethernet or Wi-Fi
- 352.4.1 Ethernet
- 362.4.2 Wi-Fi
- 362.4.3 Setting a fixed IP address
- 372.5 Remote access using SSH
- 372.5.1 Enabling the SSH server
- 372.5.2 Connecting with the SSH client
- 392.6 Basic setup
- 402.7 The tmux terminal multiplexer
- 402.7.1 The basics of tmux: windows
- 412.7.2 Working with tmux sessions
- 422.7.3 Seeing more at the same time with panes
- 432.7.4 Copying and pasting text
- 432.8 Python
- 442.8.1 Virtual environments
- 452.8.2 Package requirements
- 462.9 Docker
- 462.9.1 Installing Docker
- 482.9.2 Installing Docker Compose
- 492.9.3 Creating a Docker Compose YAML file
- 512.10 Summary and further exploration
Chapter 3: Secure your home automation system
- 533.1 Some general computer security principles
- 553.2 Isolate your home automation devices
- 553.2.1 Physical isolation
- 573.2.2 VLANs
- 583.2.3 Firewalls
- 623.3 User management
- 623.3.1 Permissions
- 633.3.2 Passwords
- 653.3.3 Lifecycle
- 653.4 Encryption
- 653.4.1 Your threat model
- 663.4.2 TLS
- 673.4.3 Setting up your own CA with mkcert
- 683.4.4 Creating a CA
- 703.4.5 Creating and signing a certificate
- 713.4.6 Keeping your root CA key secure
- 723.5 Keeping your software up-to-date
- 723.5.1 Update apt packages
- 763.5.2 Update Docker images
- 773.5.3 Update pip packages
- 773.5.4 Update manually installed packages
- 783.5.5 Update your home automation devices
- 783.6 Summary and further exploration
Chapter 4: MQTT (Message Queuing Telemetry Transport)
- 804.1 What is MQTT?
- 804.1.1 Central intermediary
- 814.1.2 Hierarchical names
- 824.1.3 Using wildcards
- 834.2 Installing and configuring the Mosquitto MQTT broker
- 834.2.1 A basic Mosquitto setup
- 854.2.2 Testing your setup with the Mosquitto clients
- 864.2.3 A secure Mosquitto setup
- 904.2.4 Testing your secure setup with the Mosquitto clients
- 924.2.5 Default options for Mosquitto clients
- 934.3 Using graphical MQTT clients
- 934.3.1 MQTT.fx
- 954.3.2 MQTT Explorer
- 974.4 Using MQTT in Python
- 1004.5 Direct communication between other containers and Mosquitto
- 1034.6 Summary and further exploration
Chapter 5: TCP/IP
- 1055.1 Wake other network devices
- 1075.2 Remote control with SSH
- 1085.2.1 Run commands on other devices
- 1095.2.2 Secure passwordless logins using SSH keys
- 1115.3 Collecting information from devices using SNMP
- 1115.3.1 Walking through the MIB tree
- 1135.3.2 Collecting your router's version using SNMP
- 1145.3.3 Collecting your printer's ink levels
- 1165.4 Using devices with a HTTP/REST API
- 1175.4.1 Setting up a Shelly device for secure remote control
- 1185.4.2 Using Shelly's HTTP API with curl
- 1195.4.3 Using the HTTP API in Python
- 1215.5 Creating a video surveillance system
- 1235.5.1 Turn your Raspberry Pi into an IP camera
- 1255.5.2 Turn your Raspberry Pi into a camera controller
- 1285.5.3 Viewing your remote cameras
- 1295.5.4 Motion detection
- 1315.5.5 Notifications on motion
- 1335.6 Summary and further exploration
Chapter 6: Bluetooth
- 1346.1 An introduction to Bluetooth Low Energy
- 1346.1.1 Broadcasting data
- 1356.1.2 Connecting to services
- 1376.2 Enabling Bluetooth
- 1386.3 Investigating Bluetooth Low Energy devices
- 1396.3.1 Scanning for Bluetooth Low Energy devices
- 1406.3.2 Dumping raw Bluetooth broadcast data
- 1416.3.3 Discovering device characteristics
- 1426.3.4 Reading device characteristics
- 1436.4 Reading BLE sensor values in Python
- 1436.4.1 RuuviTag Sensor
- 1466.4.2 Miflora
- 1486.5 Relaying Bluetooth sensor values with bt-mqtt-gateway
- 1486.5.1 Configuring bt-mqtt-gateway
- 1506.5.2 Running bt-mqtt-gateway
- 1526.6 Presence detection with Bluetooth
- 1526.6.1 Presence detection with monitor.sh
- 1536.6.2 Configuring and running monitor.sh
- 1556.6.3 Trigger arrival and departure scans in monitor.sh
- 1566.7 Summary and further exploration
Chapter 7: 433.92 MHz
- 1577.1 433.92 MHz protocols
- 1587.2 Hardware requirements
- 1587.2.1 Receiver
- 1597.2.2 Antenna
- 1607.3 Receiving sensor values with rtl_433
- 1617.3.1 Installing rtl_433toMQTT
- 1637.3.2 Configuring rtl_433
- 1657.4 Publishing 433.92 MHz sensor values to MQTT
- 1667.5 Summary and further exploration
Chapter 8: Z-Wave
- 1688.1 An introduction to Z-Wave
- 1688.1.1 The specification
- 1698.1.2 How does Z-Wave work?
- 1708.2 Choosing a Z-Wave transceiver
- 1718.2.1 Transceiver on the GPIO header: RaZberry
- 1728.2.2 USB Transceiver
- 1738.3 OpenZWave and Zwave2Mqtt
- 1748.3.1 Installing Zwave2Mqtt
- 1758.3.2 Configuring Zwave2Mqtt
- 1798.3.3 Using the Zwave2Mqtt Control Panel
- 1838.4 Using your Z-Wave devices with MQTT
- 1848.4.1 Reading sensor values
- 1858.4.2 Controlling switches
- 1868.5 Summary and further exploration
Chapter 9: Zigbee
- 1889.1 An introduction to Zigbee
- 1889.1.1 The specification
- 1899.1.2 How does Zigbee work?
- 1899.2 Creating a Zigbee transceiver
- 1909.2.1 Connect the downloader cable
- 1929.2.2 Install the flashing software
- 1929.2.3 Flash the firmware
- 1939.3 Zigbee2mqtt and Zigbee2MqttAssistant
- 1949.3.1 Connecting the CC2531
- 1959.3.2 Installing Zigbee2mqtt and Zigbee2MqttAssistant
- 1969.3.3 Configuring Zigbee2mqtt and Zigbee2MqttAssistant
- 1989.3.4 Using Zigbee2MqttAssistant
- 2009.4 Using our Zigbee devices with MQTT
- 2019.4.1 Reading sensor values
- 2019.4.2 Controlling switches
- 2029.5 Summary and further exploration
Chapter 10: Automating your home
- 20310.1 Node-RED
- 20410.1.1 Installing Node-RED
- 20510.1.2 Adding authentication to Node-RED
- 20710.1.3 Using Node-RED over HTTPS
- 20910.1.4 Creating Node-RED flows
- 21310.1.5 Installing extra nodes in Node-RED
- 21510.1.6 Creating a dashboard in Node-RED
- 21910.2 Home Assistant
- 21910.2.1 Installing Home Assistant
- 22110.2.2 Integrating MQTT
- 22410.2.3 Creating automation rules
- 22610.3 AppDaemon
- 22610.3.1 Installing AppDaemon
- 22910.3.2 Creating an AppDaemon app with MQTT: the time
- 23110.3.3 Creating an AppDaemon app with MQTT: garage door alert
- 23310.4 Summary and further exploration
Chapter 11: Notifications
- 23411.1 Forwarding local email
- 23411.1.1 Installing Nullmailer
- 23611.1.2 Testing Nullmailer
- 23711.1.3 Using Nullmailer
- 23711.2 Forwarding emails from Docker containers
- 23711.2.1 Installing docker-postfix
- 23911.2.2 Sending emails to docker-postfix
- 24111.3 Push notifications with Gotify
- 24211.3.1 Installing the Gotify server
- 24311.3.2 Adding applications to Gotify
- 24411.3.3 Using Gotify applications
- 24711.3.4 Using Gotify clients
- 24811.4 Notifications on receiving MQTT messages
- 24811.4.1 Installing mqttwarn
- 25111.4.2 Sending emails with mqttwarn
- 25211.4.3 Transforming and filtering payloads
- 25511.5 Summary and further exploration
Chapter 12: Voice control
- 25612.1 A basic Rhasspy setup
- 25712.1.1 Hardware requirements
- 25712.1.2 Configure audio hardware
- 26012.1.3 Installing Rhasspy
- 26112.1.4 Rhasspy's settings
- 26212.1.5 Configuring audio
- 26312.1.6 Configuring the wake word
- 26312.1.7 Configuring text to speech
- 26412.1.8 Configuring speech to text
- 26512.1.9 Configuring intent recognition
- 26612.1.10 Configuring dialogue management
- 26612.1.11 Testing your Rhasspy setup
- 26712.2 A Rhasspy base with satellites
- 26812.2.1 Hardware requirements
- 26912.2.2 Setting up the satellites
- 27012.2.3 Setting up the base
- 27112.2.4 Testing your base and satellites
- 27312.2.5 Enable UDP audio streaming
- 27412.3 Train your sentences
- 27612.3.1 Rhasspy's template language
- 27712.3.2 Slots
- 27812.4 Intent handling
- 27812.4.1 Intent handling with MQTT
- 28012.4.2 Intent handling with AppDaemon and MQTT
- 28212.4.3 Intent handling with WebSocket in Node-RED
- 28712.5 Summary and further exploration
Chapter 13: Remote access
- 28913.1 Three ways for remote access
- 28913.1.1 Port forwarding
- 29313.1.2 A localhost tunneling solution
- 29513.1.3 A virtual private network (VPN)
- 29713.2 Updating your dynamic DNS with ddclient
- 29813.3 Running WireGuard on your Raspberry Pi
- 29913.3.1 Installing PiVPN
- 30013.3.2 Adding a VPN client
- 30213.3.3 Connecting with a VPN client
- 30413.3.4 Managing your VPN clients
- 30513.4 Summary and further exploration
Chapter 14: Conclusion
- 30614.1 A dashboard for all your services
- 31014.2 More about home automation
Appendix
- 31215.1 Getting the name and ID of a serial device
- 31315.2 Switching USB ports
- 31315.3 Disabling the onboard radio chips
- 31415.3.1 Disabling onboard Bluetooth
- 31415.3.2 Disabling onboard Wi-Fi
- 31415.4 Disabling the on-board LEDs
- 31515.4.1 Raspberry Pi Zero (W)
- 31515.4.2 The big Raspberry Pi models
- 31515.4.3 Ethernet models
- 31615.4.4 Raspberry Pi Camera Module
- 31715.5 Securing insecure web services with a reverse proxy
- 31715.5.1 Using nginx as a reverse proxy with HTTPS
- 32115.5.2 Adding basic authentication to nginx
- 32315.6 Bridging two MQTT brokers securely
- 327Index