# h-mc/home-assistant-with-esp32cam architecture

> Architecture diagram of the GitHub repository h-mc/home-assistant-with-esp32cam, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/h-mc/home-assistant-with-esp32cam
- Repository: https://github.com/h-mc/home-assistant-with-esp32cam

## Overview

##### Project type and purpose
- This is an IoT/embedded-integration project whose goal is to turn an ESP32-Cam + sensors + servos into a security camera that plugs into Home Assistant via the ESPHome add-on.
- The repository contains documentation (README.md), the ESPHome YAML config (esp32cam-security-camera.yaml), and supporting images (img/).

##### File structure
- Top-level files:
- README.md – project overview and step-by-step guide
- esp32cam-security-camera.yaml – the ESPHome firmware configuration
- No separate “src” or “backend/frontend” directories; this is a single-device integration driven by a YAML configuration.

##### README for architectural insights
- Components mentioned: Home Assistant, ESPHome add-on, ESP32-Cam board, USB-TTL adapter (for first flash), Wi-Fi network, DHT22 sensor, two SG90 servos, external antenna option, 5 V power supply.
- Workflow:
a. Initial firmware flash over USB-TTL
b. Configure Wi-Fi via ESPHome web UI
c. Runtime operation over Wi-Fi with Home Assistant

a. Main components
- Hardware layer:
– ESP32-Cam board
– DHT22 temperature/humidity sensor (GPIO14)
– Two SG90 servos (GPIO13 & GPIO15)
– USB-TTL adapter (only during provisioning)
– 5 V power supply (e.g., phone charger)
– Wi-Fi network & optional external antenna
- Software & services:
– ESPHome add-on (running inside Home Assistant)
– esp32cam-security-camera.yaml (configuration)
– Home Assistant core (dashboard, UI, state machine)
- User interfaces:
– Home Assistant web UI (view camera stream, control servos)
– ESP32-Cam’s own web UI (after install)

b. Relationships & data flows
– User PC → USB-TTL → ESPHome add-on → ESP32-Cam (initial firmware)
2. Configuration flow:
– YAML config in ESPHome → flashes over USB-TTL (first time) then over-the-air (OTA)
– ESP32-Cam → Wi-Fi → Home Assistant (sensor readings & camera stream)
– Home Assistant → Wi-Fi → ESP32-Cam (servo commands)
– User interacts via Home Assistant web UI or mobile
– Optionally “Visit” ESP32-Cam’s own web endpoint

c. Architectural patterns & design principles
- Edge computing: sensor processing and camera capture on the ESP32
- Client-server: ESP32 acts as a client to Home Assistant’s ESPHome server interface
- Declarative configuration: YAML drives firmware generation
- OTA updates: separates initial provisioning from day-to-day operation

d. Key technologies
– ESP32-Cam (microcontroller + camera module)
– ESPHome (YAML-driven firmware builder & OTA server)
– Home Assistant (open-source smart home platform)
– DHT22 (digital temperature/humidity sensor)
– SG90 servos for pan/tilt
– USB-TTL serial adapter (FTDI/CH340)
– Wi-Fi (802.11 b/g/n)
– YAML, MQTT or native API (abstracted by ESPHome)

##### Final advice
- Be exhaustive: break the system into hardware layer, network layer, and application layer.
- Configuration artifacts (the YAML file) as part of the control plane.
- External dependencies (power supply, router).
- Don’t overthink—it’s a single-device integration, so clarity is more important than complexity.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interfaces
    UserPC["User PC"]:::service
    HAUI["Home Assistant Web UI"]:::service
    EdgeUI["ESP32-Cam Web UI"]:::service

    %% Software & Services Layer
    subgraph "Home Assistant & ESPHome Services"
        direction TB
        HA["Home Assistant Core"]:::service
        ESPHome["ESPHome Add-on"]:::service
        Config["esp32cam-security-camera.yaml"]:::firmware
    end

    %% Network Layer
    Router["Wi-Fi Network"]:::hardware

    %% Hardware Layer
    subgraph "Edge Device"
        direction TB
        ESP32["ESP32-Cam Board"]:::firmware
        Camera["Camera Module"]:::hardware
        DHT22["DHT22 Sensor (GPIO14)"]:::hardware
        Servo1["SG90 Servo 1 (GPIO13)"]:::hardware
        Servo2["SG90 Servo 2 (GPIO15)"]:::hardware
        Antenna["External Antenna (optional)"]:::hardware
    end

    Power["5 V Power Supply"]:::hardware
    USBTTL["USB-TTL Adapter"]:::hardware

    %% Provisioning Flow (dashed)
    UserPC ---|Provision firmware over USB-TTL| USBTTL
    USBTTL ---|Serial flash| ESPHome
    ESPHome ---|Initial firmware flash| ESP32

    %% Configuration Flow (dashed)
    Config ---|YAML drives firmware| ESPHome
    ESPHome ---|OTA/USB flash| ESP32

    %% Runtime Flow (solid)
    ESP32 -->|Sensor data & video stream over Wi-Fi| HA
    HA -->|Servo control commands over Wi-Fi| ESP32
    UserPC -->|Interact| HAUI
    UserPC -->|Optional visit| EdgeUI

    ESP32 -->|Connects via| Router
    HA -->|Connects via| Router

    %% Hardware connections inside Edge Device
    ESP32 --> Camera
    ESP32 --> DHT22
    ESP32 --> Servo1
    ESP32 --> Servo2
    ESP32 --> Antenna
    Power --> ESP32

    %% Documentation & Images
    Doc["Project Documentation (README.md)"] 
    Img["Supporting Images (img/)"]
    Doc -.->|Reference| Config
    Doc -.->|Reference| ESPHome
    Img -.->|Illustrations| Doc

    %% Click Events
    click Doc "https://github.com/h-mc/home-assistant-with-esp32cam/blob/main/README.md"
    click Config "https://github.com/h-mc/home-assistant-with-esp32cam/blob/main/esp32cam-security-camera.yaml"
    click Img "https://github.com/h-mc/home-assistant-with-esp32cam/tree/main/img/"

    %% Styles
    classDef hardware fill:#AED6F1,stroke:#21618C,color:#1B4F72
    classDef firmware fill:#ABEBC6,stroke:#196F3D,color:#186A3B
    classDef service fill:#F5CBA7,stroke:#B9770E,color:#6E2C00
```
