π Hardware
The first commercial product is a switch+light kit β two ESP32 devices that replace a regular wall switch and ceiling light, paired automatically via kit_tag over BLE.
Positioningβ
- Market: premium / smart-home enthusiasts (priced between Shelly/Sonoff and Lutron Caseta).
- Install path: electrician-installed, not DIY. End-user just sees a normal switch that also has app/voice control.
- Closest competitors: Aqara H1, Philips Hue (with comparable positioning, but local-first and open-source).
Kit Compositionβ
esp32-switch-pirβ
- Mounts in a standard in-wall box, replaces a regular wall switch
- Latching 220V relay (Omron G5RL-K or Hongfa HFD3) β physically switches mains to the lamp fixture
- Tactile button (momentary, not toggle) β lit by an LED indicator on the front face
- PIR sensor (HC-SR501) β motion detection
- Hardware T-flip-flop between button and relay driver (74HC74 + 74HC123 edge detector) β keeps button β light working even if the ESP32 dies
- Powered by HLK-PM03 isolated AC/DC module (220V β 5V)
esp32-lightβ
- Mounts inside the lamp fixture
- SELV-only board (no 220V inside) β fed by external 12V brick
- MP1584EN buck (12V β 5V) + LDO for ESP32 (3.3V)
- 3Γ MOSFET (IRLZ44N) for 3-channel CCT LED strip (Warm/Neutral/Cool white)
- No RGB in this revision (would need different LED strip)
Architectural Principle: Local-Firstβ
The physical toggle of the switch must not depend on the network or the microcontroller.
The path button β light is purely hardware:
button β RC debounce β 74HC74 T-flip-flop β 74HC123 edge detector
β dual MOSFET driver β latching relay coil β 220V to lamp
ESP32 sits in parallel to this path:
- Reads the button GPIO for long-press detection and MQTT events
- Reads the flip-flop's
Qoutput to know current state - Can override state via
PRE/CLRlines (for MQTT commands and PIR automations)
Failure Modesβ
| Fault | Effect on basic on/off |
|---|---|
| Wi-Fi router down | β Switch works locally |
| Station (RPi + MQTT) down | β Switch works locally |
| ESP32 in light dies | β Relay still feeds 220V β lamp on at default brightness |
| ESP32 in switch dies | β Button works (flip-flop is hardware); only MQTT features lost |
| HLK-PM03 (AC/DC) dies | β Light freezes in last state β single weak link |
| Mains breaker off | β Everything off (expected) |
This is roughly as reliable as a dumb mechanical switch β modulo one AC/DC module.
Topology Decision: Variant A (switch physically toggles 220V)β
When the wall switch is "off", the lamp fixture is fully de-energized β same UX as a regular dumb switch.
Rejected alternatives:
- B (always-on, MQTT-only toggle) β violates local-first (network latency on toggle, station outage breaks lights).
- C (NC relay default ON) β inverted logic; ESP reset desyncs from physical state.
What MQTT Adds (post local-first)β
Network is not needed for basic on/off. What MQTT enables:
| Direction | Purpose |
|---|---|
| switch β station | button_long_press, motion_detected, state_changed events for automations |
| light β station | state_changed after boot, brightness telemetry |
| station β light | set_brightness (0β100%), set_cct (2700Kβ6500K mix across WW/NW/CW channels) |
Single short presses stay fully local β never sent as commands.
The switch-light Presetβ
The kit auto-creates automations from a preset. Useful presets that use MQTT:
- PIR β light with timeout β motion detected β if light is on, set brightness 100% and reset timer; no motion for N min β set brightness 0%
- Long press β night mode β
button_long_pressβset_brightness(30%)or cycle through brightness presets
Single press stays untouched (relay handles it directly).
See station/backend/domain β kits for how presets become automations.
Open Questionsβ
- PIR behaviour when light is off β three options: (a) PIR passive, only publishes events; (b) PIR auto-closes the relay (motion β light); (c) preset config switch. Leaning towards (c) with default off.
- Production form β hand-soldered prototype (THT) vs JLCPCB SMT.
- Certification β for resale, EN 60669 (switches) and EN 60950 (PSU) apply. Not blocking for prototype.
Referenceβ
- Full hardware design notes:
docs/hardware/README.mdβ - KiCad schematics:
firmware/esp32-switch-pir/hardware/,firmware/esp32-light/hardware/ - LED strip: Biom ST-12-2835-120-DCCT-20 3CCT (1500 lm/m, 17 W/m, 4-wire +12V/WW/NW/CW)
- Competitor analysis:
docs/hardware/competitors.mdβ