Skip to main content

πŸ”Œ 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 Q output to know current state
  • Can override state via PRE/CLR lines (for MQTT commands and PIR automations)

Failure Modes​

FaultEffect 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:

DirectionPurpose
switch β†’ stationbutton_long_press, motion_detected, state_changed events for automations
light β†’ stationstate_changed after boot, brightness telemetry
station β†’ lightset_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:

  1. PIR β†’ light with timeout β€” motion detected β†’ if light is on, set brightness 100% and reset timer; no motion for N min β†’ set brightness 0%
  2. 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​