Two ESP8266 firmwares for an Apple-HomeKit kitchen setup:
radar_kitchen/— a LD2410B mmWave presence radar on a D1 Mini that exposes a HomeKit OccupancySensor, and acts as the ESP-NOW hub for a separate CO2 desk-lamp monitor (relaying its temp/humidity/CO2 into HomeKit and forwarding HomeKit light on/off commands back to it).light_relay/— an ESP-01S relay that exposes a HomeKit Switch to drive a light. One codebase, two build variants:kitchenandworkdesk.
Both are working. Presence-driven lighting is done with HomeKit automations (Apple Home), not direct device-to-device control: the radar publishes occupancy, the relay exposes a switch, and Home ties them together.
┌──────────────────────────┐ ESP-NOW (ch 6)
│ radar_kitchen (D1 Mini) │◄───────────────────────────┐
│ LD2410B mmWave radar │ │
│ HomeKit OccupancySensor │ ┌─────────────────────┴─────────┐
│ + ESP-NOW hub │ │ CO2 desk lamp (ESP32) │
│ • relays CO2 sensors │ │ SCD41 + BME280 + NeoPixel │
│ • forwards light cmds │─────►│ (separate repo: CO2) │
└────────────┬─────────────┘ └────────────────────────────────┘
│ HomeKit (Wi-Fi / mDNS)
▼
Apple Home ──automation──► light_relay (ESP-01S) → relay → light
The CO2 desk-lamp monitor that pairs with radar_kitchen over ESP-NOW lives
in its own repository (it's an ESP32 project). radar_kitchen is the HomeKit
bridge for it: the lamp has no Wi-Fi/HomeKit of its own.
Note:
light_relayis independent — it has no ESP-NOW or MQTT link to the radar. It's a plain HomeKit switch; the radar→light behaviour is an Apple Home automation.
Board: D1 Mini (ESP8266) · Lib: Arduino-HomeKit-ESP8266
| Signal | GPIO | D-pin |
|---|---|---|
| LD2410B RX (SoftwareSerial) | 4 | D2 |
| LD2410B TX (SoftwareSerial) | 5 | D1 |
LD2410B runs at 115200 baud (firmware force-switches it on boot via the radar's config command, sent at 256000 then 115200).
| Service | Source |
|---|---|
| OccupancySensor "Kitchen Presence" | local LD2410B radar |
| TemperatureSensor / HumiditySensor | CO2 lamp, via ESP-NOW |
| AirQualitySensor + CO2 level | CO2 lamp, via ESP-NOW |
| Switch "CO2 Light" | forwards on/off to the CO2 lamp |
Setup code: 382-95-164 (change in src/my_accessory.c).
- Receives
CO2Packet{ int16 co2, float temp, float hum, uint8 lightOn }from the lamp; peer MAC is learned at runtime. - Sends
TimePacket(Unix time for the lamp's clock, throttled ≤ once/60 s) andLightCommand(on/off) when HomeKit toggles the switch.
- 700 ms presence debounce on the radar signal.
- HomeKit pushes throttled: occupancy every 3 s / on change; sensor data ≤ every 30 s (4 notifies every 3 s was overloading the HomeKit TLS sessions).
- ESP-NOW receive callback only memcpy's + sets flags; all WiFi/ESP-NOW/HomeKit
calls are deferred to
loop()(calling them in the ISR context crashes ESP8266). - On WiFi reconnect the device reboots — calling
arduino_homekit_setup()twice leaks heap and crashes. - NTP timezone hardcoded to
CET-1CEST(the clock is sent on to the CO2 lamp).
cd radar_kitchen
pio run -e d1_mini -t upload # USB
pio run -e d1_mini_ota -t upload # OTA → upload_port in platformio.iniBoard: ESP-01S (ESP8266, 1 MB) · Lib: Arduino-HomeKit-ESP8266
A minimal HomeKit Switch: the ON characteristic drives a relay on GPIO0
(D3). Includes a 5 s WiFi watchdog that reconnects and re-advertises HomeKit
after a dropout.
| Env | Device name | HomeKit setup code | setupId |
|---|---|---|---|
kitchen |
Kitchen Light | 681-18-397 |
KL01 |
workdesk |
Workdesk Light | 527-31-846 |
WD01 |
Selected at compile time via -DDEVICE_KITCHEN / -DDEVICE_WORKDESK.
cd light_relay
pio run -e kitchen -t upload
pio run -e workdesk -t uploadRelay polarity: both variants are currently defined active-HIGH in
main.cpp(RELAY_ON = HIGH). Theplatformio.inicomment calling workdesk "active-LOW" is stale — flipRELAY_ON/RELAY_OFFfor that variant if your relay module is active-LOW.
WiFi credentials are kept out of git. Each firmware reads src/secrets.h
(gitignored). Before building, copy the template in each subfolder:
cp radar_kitchen/src/secrets.example.h radar_kitchen/src/secrets.h
cp light_relay/src/secrets.example.h light_relay/src/secrets.hHomeKit setup codes are left in my_accessory.c (they require local-network
access and an unpaired device to be useful) — change them for your own units.
No license specified — personal/reference projects.