Last updated on

Home Assistant - Domotique IoT Self-Hosted


🏠 Vue d’Ensemble

Home Assistant est le cerveau de ma domotique self-hosted. L’infrastructure complète tourne sur mon Raspberry Pi avec 7 dashboards dédiés, intégration Zigbee2MQTT, automatisations avancées et contrôle total de tous les appareils connectés.

URL: http://<SERVER_IP>:PORT

🎯 Objectifs

  1. Privacy First: Données 100% locales, aucun cloud
  2. Interopérabilité: Zigbee, WiFi, MQTT - tous protocoles supportés
  3. Automatisations Avancées: Logique complexe avec templates et conditions
  4. Dashboard UX: Interface intuitive par pièce
  5. Monitoring: Tracking consommation électrique et environnement

🏗️ Architecture

Stack

Core:            Home Assistant 2025.1.x (Docker)
MQTT Broker:     Eclipse Mosquitto (localhost:PORT)
Zigbee Gateway:  Zigbee2MQTT (USB ZStack coordinator)
Protocol:        MQTT (communication inter-services)
UI:              Lovelace YAML mode
Persistence:     Recorder (MariaDB futur)

Infrastructure

Container Home Assistant (homeassistant)

  • Image: ghcr.io/home-assistant/home-assistant:stable
  • Port: 8123
  • Volumes: /config persistant
  • Network: Host mode (mDNS discovery)
  • Devices: USB Zigbee stick (/dev/ttyUSB0)

Container Mosquitto (mosquitto)

  • Image: eclipse-mosquitto:latest
  • Port: 1883 (MQTT), 9001 (WebSocket)
  • Config: Persistence enabled, anonymous auth (LAN only)
  • Volume: Data + logs + config

Container Zigbee2MQTT (zigbee2mqtt)

  • Image: koenkk/zigbee2mqtt:latest
  • Port: 8080 (Web UI)
  • Devices: /dev/ttyUSB0 (coordinator)
  • MQTT: Connecté à Mosquitto

📱 Dashboards (7 Tabs)

1. 🏡 Home (Vue d’ensemble)

Widgets:

  • Météo locale (intégration OpenWeatherMap)
  • Résumé état maison (lumières ON/OFF, température)
  • Prochaines automatisations programmées
  • Alertes système (batterie faible, offline devices)
  • Quick actions (tout éteindre, mode nuit, mode absence)

Cartes:

- type: weather-forecast
  entity: weather.openweathermap
- type: entities
  entities:
    - binary_sensor.home_occupied
    - sensor.total_lights_on
    - sensor.average_temperature

2. 🛋️ Salon

Devices:

  • Lampe principale Ikea TRADFRI (Zigbee)
  • Ampoule LED RGB (WiFi)
  • Télévision (IR via Broadlink)
  • Thermomètre Aqara

Fonctionnalités:

  • Contrôle intensité lumière (slider)
  • Sélection couleur RGB (color picker)
  • Scènes prédéfinies (Détente, Film, Lecture)
  • Historique température 24h (graph)

Automatisations Associées:

  • Lever de soleil: Allumage progressif lampe 6h30-7h00
  • Coucher de soleil: Allumage automatique si présence détectée
  • Mode Film: Lumières tamisées + TV ON

3. 🍳 Cuisine

Devices:

  • Spot LED encastré (Zigbee)
  • Multiprise connectée (WiFi - Tasmota)
  • Capteur température/humidité (Zigbee)

Fonctionnalités:

  • ON/OFF spot
  • Contrôle prises individuelles multiprise
  • Monitoring température frigo (capteur externe)
  • Alerte si humidité > 70% (moisissure)

Automatisations:

  • Présence matin: Lumière ON si mouvement 6h-8h
  • Oubli appareils: Notification si multiprise ON > 2h

4. 🛏️ Chambre

Devices:

  • Lampe chevet gauche (Zigbee)
  • Lampe chevet droite (Zigbee)
  • Volets roulants motorisés (Zigbee)
  • Capteur température (Zigbee Aqara)
  • Interrupteur sans fil IKEA STYRBAR (Zigbee)

Fonctionnalités:

  • Contrôle individuel lampes
  • Scène “Lecture” (1 lampe 50%)
  • Contrôle volets (%, open/close)
  • Graph température nocturne

Automatisations:

  • Réveil Simulé: Volets + lumière progressive 7h00
  • Mode Nuit: Tout éteindre + volets fermés (22h30)
  • STYRBAR Remote:
    • Court press ↑: Lumières ON
    • Court press ↓: Lumières OFF
    • Long press ↑: Augmentation brightness graduelle
    • Long press ↓: Diminution brightness graduelle

Configuration STYRBAR (fix appliqué):

# automation.yaml
- id: styrbar_brightness_up_long
  alias: "STYRBAR - Long Press UP (Brightness +)"
  trigger:
    - platform: mqtt
      topic: "zigbee2mqtt/remote_chambre"
  condition:
    - condition: template
      value_template: "{{ trigger.payload_json.action == 'on' }}"
  action:
    - repeat:
        while:
          - condition: template
            value_template: "{{ repeat.index <= 10 }}"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.lampe_chevet_gauche
            data:
              brightness_step_pct: 10
          - delay:
              milliseconds: 300

5. 💼 Bureau

Devices:

  • Prise connectée déshumidificateur (Zigbee)
  • Lampe bureau LED (Zigbee)
  • Multi-capteur (température, humidité, pression)

Fonctionnalités:

  • Contrôle prise déshumidificateur
  • Monitoring humidité temps réel
  • Historique consommation électrique prise
  • Timer déshumidificateur (1h auto-off)

Automatisations:

  • Humidité Élevée: Déshumidificateur ON si > 65%
  • Humidité OK: Déshumidificateur OFF si < 50%
  • Timer Sécurité: Auto-off après 1h de fonctionnement continu
  • Oubli: Notification si ON à 23h

Configuration Timer (problème résolu):

# scripts.yaml
deshumidificateur_1h:
  alias: "Déshumidificateur - Timer 1h"
  sequence:
    - service: switch.turn_on
      target:
        entity_id: switch.prise_deshumidificateur_bureau
    - service: timer.start
      target:
        entity_id: timer.deshumidificateur
      data:
        duration: "01:00:00"
    - wait_for_trigger:
        - platform: event
          event_type: timer.finished
          event_data:
            entity_id: timer.deshumidificateur
    - service: switch.turn_off
      target:
        entity_id: switch.prise_deshumidificateur_bureau

# configuration.yaml
timer:
  deshumidificateur:
    duration: "01:00:00"
    restore: false

6. ⚙️ Systèmes

Monitoring:

  • État serveurs Docker (up/down)
  • CPU / RAM / Température Raspberry Pi
  • Espace disque disponible
  • Uptime système
  • Connexion Internet (ping test)

Intégrations:

  • Pi-hole (DNS stats)
  • UniFi (network stats)

Widgets:

- type: gauge
  entity: sensor.processor_use_percent
  min: 0
  max: 100
  severity:
    green: 0
    yellow: 70
    red: 90

- type: entities
  title: "Containers Docker"
  entities:
    - binary_sensor.jellyfin_running
    - binary_sensor.sonarr_running
    - binary_sensor.radarr_running

7. 🤖 Automations

Vue d’ensemble:

  • Liste toutes automatisations actives
  • Toggle ON/OFF par automation
  • Dernière exécution + état
  • Traces d’exécution (debug)
  • Statistiques (nombre déclenchements)

Catégories:

  • Éclairage: 12 automatisations
  • Sécurité: 5 automatisations
  • Confort: 8 automatisations
  • Énergie: 4 automatisations
  • Notifications: 6 automatisations

🔌 Intégration Zigbee2MQTT

Configuration

# zigbee2mqtt/data/configuration.yaml
homeassistant: true
permit_join: false
mqtt:
  base_topic: zigbee2mqtt
  server: mqtt://mosquitto:PORT
serial:
  port: /dev/ttyUSB0
  adapter: zstack
advanced:
  network_key: GENERATE
  pan_id: 6754
  channel: 11
  log_level: info
devices:
  '0x00124b001f8e5c3a':
    friendly_name: 'prise_deshumidificateur_bureau'
  '0xccccccfffea8b9c1':
    friendly_name: 'remote_chambre'
  '0x000d6f000a8c2e4f':
    friendly_name: 'lampe_chevet_gauche'

Devices Pairés (15)

DeviceTypeLocationZigbee ID
Prise bureauSmart PlugBureau0x00124b001f8e5c3a
Remote STYRBARControllerChambre0xccccccfffea8b9c1
Lampe chevet GBulbChambre0x000d6f000a8c2e4f
Lampe chevet DBulbChambre0x000d6f000a8c2e50
Capteur temp chambreSensorChambre0x00158d0004a2f1b3
Spot cuisineBulbCuisine0xccccccfffe89ab12
Lampe salonBulbSalon0x000d6f0012345678

Troubleshooting Résolu

Problème: Prise bureau pas reconnue (interview failed) Cause: Mauvaise configuration friendly_name dans Zigbee2MQTT Solution: Fix dans /zigbee2mqtt/data/configuration.yaml + re-interview device

📡 Architecture MQTT

Topics

zigbee2mqtt/
├── bridge/
│   ├── state (online/offline)
│   ├── devices (liste appareils)
│   └── info (version, coordinator)
├── prise_deshumidificateur_bureau/
│   ├── state ({"state": "ON"})
│   ├── availability (online/offline)
│   └── set (commandes)
├── remote_chambre/
│   ├── action ({"action": "on"})
│   └── battery (%)
└── ...

homeassistant/
├── sensor/
├── switch/
└── light/

Flow MQTT

┌──────────────┐      MQTT       ┌──────────────┐
│   Zigbee     │ ◄────publish────┤  Zigbee2MQTT │
│   Device     │                 └──────────────┘
└──────────────┘                        │
                                   subscribe

                               ┌────────▼─────────┐
                               │    Mosquitto     │
                               │  (MQTT Broker)   │
                               └────────┬─────────┘
                                   subscribe

                               ┌────────▼──────────┐
                               │  Home Assistant   │
                               │  (MQTT Integration)│
                               └───────────────────┘

🤖 Automatisations Avancées

Templates Jinja2

Condition complexe (allumer lumière uniquement si nuit + présence):

condition:
  - condition: template
    value_template: >
      {{ now().hour >= 20 or now().hour < 7 }}
  - condition: state
    entity_id: binary_sensor.motion_salon
    state: 'on'

Calcul dynamique (moyenne température maison):

sensor:
  - platform: template
    sensors:
      average_temperature:
        friendly_name: "Température Moyenne"
        unit_of_measurement: "°C"
        value_template: >
          {% set temps = [
            states('sensor.temp_salon') | float,
            states('sensor.temp_chambre') | float,
            states('sensor.temp_cuisine') | float,
            states('sensor.temp_bureau') | float
          ] %}
          {{ (temps | sum / temps | length) | round(1) }}

Notifications

Batterie faible:

- id: battery_low_notification
  alias: "Alerte Batterie Faible"
  trigger:
    - platform: numeric_state
      entity_id: sensor.remote_chambre_battery
      below: 20
  action:
    - service: notify.mobile_app
      data:
        title: "Batterie Faible"
        message: "Remote chambre: {{ states('sensor.remote_chambre_battery') }}%"

📊 Monitoring & Métriques

Recorder

# configuration.yaml
recorder:
  db_url: sqlite:////config/home-assistant_v2.db
  purge_keep_days: 7
  include:
    domains:
      - sensor
      - light
      - switch
    entities:
      - sensor.temp_*
      - sensor.processor_use_percent

History Graph

type: history-graph
entities:
  - sensor.temp_chambre
  - sensor.temp_salon
  - sensor.temp_cuisine
  - sensor.temp_bureau
hours_to_show: 24
refresh_interval: 60

🔐 Sécurité

  1. Réseau Isolé: IoT devices sur VLAN séparé (futur)
  2. Authentification: MFA activée pour Home Assistant
  3. Firewall: UFW block tous ports sauf 8123 (LAN only)
  4. MQTT: Pas d’auth car réseau local trusted (à améliorer)
  5. Zigbee Encryption: Network key unique

🚀 Prochaines Étapes

Court Terme

  • Migration DB vers MariaDB (performance)
  • Intégration ESPHome pour capteurs DIY
  • Caméras IP (Frigate NVR)
  • Détection présence (BLE trackers)

Moyen Terme

  • Voice Assistant (Rhasspy self-hosted)
  • Energy Dashboard (tarifs EDF, coûts)
  • Alarme maison (détecteurs ouverture)
  • VLAN IoT séparé

Long Terme

  • Chauffage intelligent (thermostat Zigbee)
  • Arrosage automatique jardin
  • Contrôle portail (relay)

📚 Ressources


Status: 🟢 Fonctionnel
Devices: 15 Zigbee pairés
Automatisations: 35 actives
Uptime: 99.8% (dernier mois)