Home Automation with Home Assistant - Complete Guide

Home Assistant is an open-source platform for smart home control that gives complete control over your devices. Compared to commercial solutions, it offers unlimited automation possibilities, support for nearly all IoT devices, and runs locally without cloud.
What is Home Assistant and Why Use It?
Home Assistant (HA) is a Python application that serves as a central control unit for all smart devices in your home. Key advantages:
Advantages Over Commercial Solutions
- Local operation - no cloud dependency
- Open source - transparency and security
- Unlimited integration - support for 2000+ components
- No monthly fees - buy hardware once
- Full control - you own your data
Device Support
- Zigbee/Z-Wave (via USB dongle)
- WiFi IoT (ESP8266/ESP32)
- Brands: Shelly, Sonoff, Tasmota, ESPHome
- Systems: Philips Hue, IKEA, Xiaomi
- Media: Chromecast, Spotify, Plex
Home Assistant Installation
Option 1: Home Assistant OS (Recommended)
Hardware Requirements:
- Raspberry Pi 4 (4GB RAM minimum)
- MicroSD card 32GB (Class 10)
- Power adapter 5V/3A
- USB dongles (Zigbee/Z-Wave)
Installation:
Download Image:
- home-assistant.io/installation
- Select Raspberry Pi 4
Flash to SD Card:
# Linux/Mac sudo dd if=haos_rpi4-64.img of=/dev/sdX bs=1M # Windows - use Raspberry Pi Imager
First Boot:
- Insert SD card into Pi
- Connect LAN cable
- Connect power
- Wait 5-10 minutes for boot
Web Interface:
- Open
http://IP_ADDRESS:8123
- Create admin account
- Name your home
- Open
Option 2: Docker on PC/NAS
# Docker Compose
version: '3'
services:
homeassistant:
container_name: homeassistant
image: ghcr.io/home-assistant/home-assistant:stable
volumes:
- ./config:/config
- /etc/localtime:/etc/localtime:ro
restart: unless-stopped
privileged: true
network_mode: host
Option 3: Home Assistant Green
Official HA hardware:
- Price: ~$100
- Plug & play solution
- Integrated Zigbee
- SkyConnect USB support
Basic Configuration
Initial Setup
Location Settings:
# configuration.yaml homeassistant: name: Home latitude: 40.7128 longitude: -74.0060 elevation: 10 unit_system: imperial time_zone: America/New_York currency: USD country: US
Users and Access:
- Settings → People
- Create family accounts
- Set permissions
Areas:
- Living room, bedroom, kitchen
- Assign devices to them
- Used for automations
Important Integrations
Weather:
# configuration.yaml
weather:
- platform: openweathermap
api_key: YOUR_API_KEY
name: New York
Mobile App:
mobile_app:
notify:
- name: mobile
platform: group
services:
- service: mobile_app_phone
Adding Devices
WiFi Devices (Shelly, Sonoff)
Automatic Detection:
- Settings → Devices & Services
- Click "Add Integration"
- HA automatically finds network devices
Manual Addition:
# configuration.yaml
switch:
- platform: shelly
host: 192.168.1.100
name: "Living Room Light"
Zigbee Devices
Required Hardware:
- ConBee II USB stick ($60)
- Or Sonoff Zigbee 3.0 USB ($32)
Adding Devices:
- Settings → Integrations
- Add Zigbee Home Automation
- Select USB port dongle
- Put device in pairing mode
ESPHome Devices
ESPHome is addon for custom ESP devices:
# example-device.yaml
esphome:
name: kitchen-light
platform: ESP8266
board: d1_mini
wifi:
ssid: "YourWiFi"
password: "YourPassword"
api:
password: "api-password"
ota:
password: "ota-password"
switch:
- platform: gpio
pin: GPIO5
name: "Kitchen Light"
id: kitchen_light
sensor:
- platform: dht
pin: GPIO4
temperature:
name: "Kitchen Temperature"
humidity:
name: "Kitchen Humidity"
update_interval: 60s
Creating Automations
Basic Automations
Example 1: Turn on lights when arriving home
automation:
- alias: "Lights on arrival"
trigger:
- platform: state
entity_id: person.john
from: "not_home"
to: "home"
condition:
- condition: sun
after: sunset
action:
- service: light.turn_on
entity_id: light.entryway
data:
brightness: 200
- service: switch.turn_on
entity_id: switch.living_room_light
Example 2: Night light in bathroom
automation:
- alias: "Bathroom night light"
trigger:
- platform: state
entity_id: binary_sensor.bathroom_motion
to: "on"
condition:
- condition: time
after: "22:00:00"
before: "06:00:00"
action:
- service: light.turn_on
entity_id: light.bathroom
data:
brightness: 50
color_name: red
- delay: "00:02:00"
- service: light.turn_off
entity_id: light.bathroom
Advanced Automations
Example: Vacation presence simulation
automation:
- alias: "Vacation simulation"
trigger:
- platform: sun
event: sunset
offset: "-00:30:00"
condition:
- condition: state
entity_id: input_boolean.vacation_mode
state: "on"
action:
- repeat:
count: 3
sequence:
- service: light.turn_on
entity_id: light.living_room
data:
brightness: !lambda "return random.randint(150, 255)"
- delay: !lambda "return random.randint(1800, 3600)"
- service: light.turn_off
entity_id: light.living_room
- delay: !lambda "return random.randint(600, 1800)"
Example: Smart thermostat by presence
automation:
- alias: "Heating by presence"
trigger:
- platform: state
entity_id: group.family
to: "not_home"
for: "00:30:00"
action:
- service: climate.set_temperature
entity_id: climate.thermostat
data:
temperature: 65
- alias: "Heating on return"
trigger:
- platform: state
entity_id: group.family
from: "not_home"
to: "home"
action:
- service: climate.set_temperature
entity_id: climate.thermostat
data:
temperature: 72
Dashboards and Visualization
Lovelace UI
Basic Card:
# ui-lovelace.yaml
views:
- title: Home
icon: mdi:home
cards:
- type: entities
title: Lighting
entities:
- light.living_room
- light.kitchen
- light.bedroom
- type: thermostat
entity: climate.living_room_thermostat
- type: weather-forecast
entity: weather.home
Advanced Cards:
# Card with graphs
- type: history-graph
title: Temperature 24h
entities:
- sensor.living_room_temperature
- sensor.bedroom_temperature
hours_to_show: 24
# Floor plan card
- type: picture-elements
image: /local/floor-plan.png
elements:
- type: state-icon
entity: light.living_room
style:
top: 50%
left: 30%
- type: state-label
entity: sensor.living_room_temperature
style:
top: 70%
left: 30%
Mobile App
Installation:
- Google Play / App Store: "Home Assistant"
- Configuration: Settings → Integrations → Mobile App
Features:
- Push notifications
- GPS tracking
- Quick actions
- Camera on lock screen
Popular Device Integration
Shelly Devices
# Automatic detection via mDNS
# Or manually:
switch:
- platform: shelly
host: 192.168.1.50
name: Shelly Plug
# For Shelly Plus series:
# Settings → Integrations → Shelly
Philips Hue
# Automatically detected
# Or:
hue:
bridges:
- host: 192.168.1.2
allow_hue_groups: false
allow_unreachable: true
Sonoff Devices (Tasmota)
# MQTT integration
mqtt:
broker: 192.168.1.100
username: mqtt_user
password: mqtt_pass
switch:
- platform: mqtt
name: "Sonoff Basic"
state_topic: "stat/sonoff1/POWER"
command_topic: "cmnd/sonoff1/POWER"
payload_on: "ON"
payload_off: "OFF"
Xiaomi Gateway
xiaomi_aqara:
discovery_retry: 5
gateways:
- key: GATEWAY_KEY
host: 192.168.1.30
Security and Remote Access
HTTPS and SSL Certificates
# configuration.yaml
http:
ssl_certificate: /ssl/fullchain.pem
ssl_key: /ssl/privkey.pem
server_port: 8123
Let's Encrypt Certificate:
- Add-ons → Let's Encrypt
- Configuration with your domain
- Start addon
Remote Access
Method 1: Nabu Casa (Paid)
- $5/month
- Simple configuration
- Supports HA development
Method 2: DuckDNS + Port forwarding
# DuckDNS Add-on
{
"lets_encrypt": {
"accept_terms": true,
"certfile": "fullchain.pem",
"keyfile": "privkey.pem"
},
"token": "your-duckdns-token",
"domains": ["yourdomain.duckdns.org"]
}
Method 3: Cloudflare Tunnel
- No port forwarding
- Free
- Higher security
Backup
Automatic Backups:
# Google Drive Backup add-on
{
"days_to_retain": 7,
"backup_time": "03:00",
"backup_name": "HA-{date}",
"exclude_folders": ["media", "tts"],
"exclude_addons": []
}
Advanced Features
Node-RED Automations
Installation: Add-ons → Node-RED
Advantages:
- Visual programming
- Complex logic
- Debug capabilities
AppDaemon for Python
# apps/hello.py
import appdaemon.plugins.hass.hassapi as hass
class HelloWorld(hass.Hass):
def initialize(self):
self.listen_state(self.motion_detected, "binary_sensor.motion")
def motion_detected(self, entity, attribute, old, new, kwargs):
if new == "on":
self.turn_on("light.hall")
self.run_in(self.turn_off_light, 300)
def turn_off_light(self, kwargs):
self.turn_off("light.hall")
Template Sensors
sensor:
- platform: template
sensors:
power_cost_today:
friendly_name: "Today's energy cost"
unit_of_measurement: "USD"
value_template: >-
{{ (states('sensor.daily_energy')|float * 0.12)|round(2) }}
home_occupancy:
friendly_name: "Home presence"
value_template: >-
{% set people = [
states('person.john'),
states('person.jane')
] %}
{{ 'home' if people|select('eq', 'home')|list|length > 0 else 'away' }}
Debugging and Problem Solving
Logs and Diagnostics
# configuration.yaml
logger:
default: info
logs:
homeassistant.components.shelly: debug
homeassistant.components.mqtt: debug
Access logs:
- Developer Tools → Logs
- SSH addon →
ha logs
Common Problems
Device disconnects:
- Check WiFi signal strength
- Router reboot
- Reserve IP address
Automation not working:
- Template tools for testing
- Check YAML syntax
- Trace automation
High RAM usage:
- Recorder configuration
- Limit history
- Database cleanup
Useful Add-ons
Basic Add-ons
- File editor - configuration editing
- Terminal & SSH - system access
- Samba share - folder sharing
- Mosquitto MQTT - MQTT broker
Advanced Add-ons
- Node-RED - visual automation
- Grafana - advanced graphs
- InfluxDB - time series database
- Frigate - AI camera detection
Complete Automation Examples
Smart Alarm
# Input helper
input_boolean:
alarm_home:
name: Home alarm
icon: mdi:shield-home
automation:
- alias: "Alarm - activation"
trigger:
- platform: state
entity_id: group.family
to: "not_home"
for: "00:05:00"
action:
- service: input_boolean.turn_on
entity_id: input_boolean.alarm_home
- service: notify.mobile_app_phone
data:
title: "Alarm activated"
message: "Home alarm was automatically turned on"
- alias: "Alarm - breach"
trigger:
- platform: state
entity_id: binary_sensor.door_sensor
to: "on"
condition:
- condition: state
entity_id: input_boolean.alarm_home
state: "on"
action:
- service: light.turn_on
entity_id: all
data:
brightness: 255
- service: notify.mobile_app_phone
data:
title: "🚨 ALARM!"
message: "Door opening detected!"
- service: media_player.play_media
entity_id: media_player.google_home
data:
media_content_id: "alarm_sound.mp3"
media_content_type: "music"
Energy Optimization
automation:
- alias: "Turn off standby appliances"
trigger:
- platform: time
at: "23:00:00"
action:
- service: switch.turn_off
entity_id:
- switch.tv_outlet
- switch.pc_outlet
- switch.printer_outlet
- alias: "EV charging at night"
trigger:
- platform: time
at: "01:00:00"
condition:
- condition: numeric_state
entity_id: sensor.car_battery
below: 80
action:
- service: switch.turn_on
entity_id: switch.ev_charger
- delay: "06:00:00"
- service: switch.turn_off
entity_id: switch.ev_charger
Conclusion
Home Assistant is a powerful tool for anyone who wants full control over their smart home. Yes, it has a learning curve, but the result is worth it. Start with simple automations and gradually expand according to your needs.
Getting started recommendations:
- Raspberry Pi 4 with Home Assistant OS
- Several Shelly outlets/switches
- Mobile app
- First simple automations
Investment of ~$200 gives you a foundation you can expand for years.