LUMEN cover art for a smart-home assistant built with OpenAI Whisper and DeepSeek
Back to projects
School project

LUMEN

LUMEN is a voice-controlled assistant for a smart room, which you use by saying “Hello Robot” or holding a button and speaking. An ESP32 records the audio, a server transcribes it and has an LLM turn it into one JSON command, and MQTT carries that command to the lights, fan, servo and buzzer. The hardest part was fitting all of this onto a board with about 33 KB of free RAM.

Built with
ESP32PythonDockerVS Code

Overview

LUMEN was my mini project for NYP's IoT Programming module, where the brief was simply to build a connected device that does something useful. I wanted to see what a cheap ESP32 could do with real language understanding instead of a fixed list of commands.

It listens for a wake word, records what you say and turns it into actions: “dim the light a bit”, “turn the fan on in ten minutes”, “set the brightness to match the humidity”, “good night”. The language work runs on a small server, so the ESP32 only has to record audio and run commands.

The wake word, a few spoken commands and the room responding.

Try it

This demo follows the same path as the real system on a smaller scale, from a trigger to Whisper for speech-to-text, then to a DeepSeek LLM that parses the text into one JSON command (both through OpenRouter), and finally over MQTT to the devices. You can pick a phrase below or let it cycle through them.

LUMEN consolepush-to-talk
Trigger
Whisper
DeepSeek
MQTT
Heard

“Set the light to cyan and turn the fan on a second later.”

Parsed
Say "Hello Robot" or hold the button to talk.
The roomAuto mode on
White LED
off
NeoPixeloff
Fanoff
Servo90°
24.3°C69% RHmotiondark

The temperature question and the sandwich request show the guardrails, because a question is answered from live sensor data without any action and an impossible request is refused. The ESP32 only ever acts on validated JSON.

How it works

The ESP32 does almost no thinking, because its only jobs are to record audio and carry out commands. Speech-to-text, the language model and logging all run on a FastAPI server in Docker on my homelab, which the board reaches over the local network.

On the ESP32
Trigger and micA wake word or push-to-talk starts the INMP441 capturing 16 kHz mono audio.
FastAPI server, OpenRouter
Whisper, DeepSeek and validationWhisper turns speech into text and a DeepSeek model parses it into one JSON command, which the server checks against the schema, retrying once before a no-op.
In the room
Devices and OLEDThe LED, RGB, fan, servo and buzzer respond, and the OLED shows the reply.
The path a voice command takes from the ESP32 through the server to the devices in the room

A trigger (the “Hello Robot” wake word, or a push-to-talk button as the fallback) starts an INMP441 microphone capturing 16 kHz mono audio. The board wraps it as a WAV and streams it to the server's /upload endpoint. The server uses one OpenRouter API key for both steps, first having Whisper transcribe the audio and then having a DeepSeek model turn the text into one JSON command under a strict system prompt. It then validates the JSON, publishes it to an MQTT topic that the ESP32 subscribes to, and appends each result to a Google Sheet with an estimated cost per request.

The server also subscribes to the room's state and sensor topics, caches the latest values and passes them to the LLM as context, which is how questions like “what's the temperature?” and “is the fan on?” get answered from real readings.

The voice pipeline

  1. You trigger it by saying “Hello Robot” or holding the push-to-talk button.
  2. The INMP441 records about three seconds of 16 kHz mono audio, and the red REC LED stays lit while it does.
  3. The board wraps the raw PCM in a 44-byte WAV header and streams it to /upload while it is still recording.
  4. The server sends the clip to OpenRouter, where Whisper transcribes it into text.
  5. The server adds context by passing the model the transcript along with a snapshot of device state and sensor readings.
  6. A DeepSeek model, also through OpenRouter, parses it into one JSON command, which the server checks against the schema, retrying once before falling back to a no-op.
  7. The server sends the command over MQTT and appends a row to the Google Sheet.
  8. The ESP32 executes the command and shows the reply on its OLED.

The command parser

The model never controls a device directly, and instead converts each sentence into exactly one of three JSON shapes:

  • action is a single change, such as “turn the fan on” or “set it to cyan”.
  • sequence is a set of ordered steps, each with a delay from the moment you spoke, such as “lights off, then fan off a second later”.
  • timer is one change after a countdown, such as “light off in ten minutes”.
Transcribed text and sensor contextWhisper transcript plus a live room snapshot from the MQTT cacheMultilingual inputWhisper handles many languagesDeepSeek LLM (through OpenRouter)Parses the request into one JSON commandJSONJSON schemavalid?YesRoute by command typeaction, sequence or timeractionsequencetimeractionSingle device changesequenceSteps with delaystimerOne change after a delayNoRetry oncere-prompt the LLMfailsSafe no-opreply only, no action
Transcribed text and sensor contextWhisper transcript plus a live room snapshot from the MQTT cacheSpeaks many languages
DeepSeek LLM (through OpenRouter)Parses the request into one JSON command
JSON
JSON schema valid?
if invalid
Failure path
Retry onceRe-prompt the LLM
still fails
Safe no-opReply only, no action on the room
if valid
Route by command typeaction, sequence or timer
by type
actionSingle device change
sequenceSteps with delays
timerOne change after a delay
How a voice command moves through the parser, where every path ends as an action, a sequence, a timer or a refusal that takes no action

It also works in other languages, because Whisper transcribes many languages and the parser maps each one to the same JSON vocabulary. A command spoken in Malay or Mandarin produces the same action as the English version.

A long, strict system prompt fixes the device vocabulary (white LED, NeoPixel RGB, fan, servo, buzzer, comfort range, auto mode), forces valid JSON with numbers as numbers, and has the model map colour names to RGB itself. The server checks every response against a schema, and if one fails it retries once and then falls back to a no-op instead of sending the board something it cannot trust.

The system prompt LUMEN sends the model

You are LUMEN, the command parser for a voice-controlled smart-room system. Your only job: convert one natural-language request into ONE JSON command object. Output JSON and nothing else: no prose, no code fences, no explanation.

Context you are given each call

  • CURRENT_TIME: {iso8601_local} (timezone UTC+8 / Asia/Singapore)
  • STATE: a JSON snapshot of current device state plus a “sensors” object with live readings (temp in °C, humidity %, motion, dark) and the comfort range. Use it to resolve relative requests (“a bit dimmer”, “make it warmer”) and to answer questions about the room (“what's the temperature”, “is it dark”).

Output: exactly one of these three shapes

  1. action: a single device change.
  2. sequence: ordered steps, each with delay_ms from the trigger moment.
  3. timer: one device change after delay_seconds.

Every object MUST include a “response_text”: one short spoken-style sentence confirming what you did, suitable for an OLED line (<= 40 chars ideal).

Devices and allowed actions (never invent others)

  • white_led: turn_on | turn_off | set_brightness(value 0-100)
  • rgb_led: turn_on | turn_off | set_rgb(r,g,b 0-255)
  • fan: turn_on | turn_off
  • servo: set_angle(angle 0-180)
  • buzzer: turn_on | turn_off | beep(count, duration_ms)
  • comfort_range: update(min, max) # degrees C
  • auto_mode: enable | disable
  • timers: cancel_all | cancel(timer_id)
  • none: report | noop # report = answer a question (no action); noop = impossible/invalid (no action)

Rules

  • RGB: map any colour name to r,g,b yourself. cyan=0,255,255; warm white=255,200,100; purple=128,0,128. No fixed list.
  • “Dimmer”/“brighter”/“warmer light”: read current value from STATE and adjust by ~20 (clamp 0-100).
  • SENSOR → PARAMETER: if asked to set a device's numeric value TO a live sensor reading (“set the brightness to the humidity”, “set the light to the temperature”), read that reading from STATE.sensors, round to a whole number, clamp it to the field's valid range, and emit the matching set action. This IS doable: do not refuse it. E.g. humidity 69.5 → white_led set_brightness value 70.
  • FAN vs COMFORT RANGE: keep these separate:
    • “it's getting warm” / “i'm hot” / “turn on the fan” → action, fan, turn_on. This does NOT change comfort_range.
    • “set comfortable range to X to Y” / “make the room target warmer” → action, comfort_range, update. This does NOT touch the fan.
  • AUTO MODE: the room's automatic behaviour (motion+dark turns the light on; the fan follows the comfort range). “turn automatic/auto mode on|off”, “enable/disable auto mode”, “stop running the room automatically”, “stop the automatic lights/fan”, “let me control it manually” → action, auto_mode, enable|disable. This only arms/disarms the automation: it does NOT itself switch any device on or off.
  • Sequences: first step delay_ms=0, later steps offset from the trigger moment (not cumulative gaps unless that's clearly intended).
  • Timers: convert “in 10 minutes” → delay_seconds 600. Give a human label.
  • Questions & general knowledge → device “none”, action “report”: put the answer in response_text and take NO device action.
    • device/sensor status (“what's the temperature”, “is the fan on”) → answer from STATE.
    • general knowledge (“how tall is the Empire State Building”) → answer from your own knowledge. Keep it brief (the OLED wraps ~16 chars/line).
  • Invalid / impossible / unsupported, or input you can't parse into any device action (“fly to the moon”, gibberish) → device “none”, action “noop”, with a short response_text saying it can't be done. Take NO action.
  • Both “report” and “noop” take no device action; their response_text is shown on screen and the system simply continues.
  • Output valid JSON. Numbers are numbers, not strings.

Examples

“set the light to cyan and turn on the fan one second later”
-> {"type":"sequence","steps":[
     {"delay_ms":0,"device":"rgb_led","action":"set_rgb","r":0,"g":255,"b":255},
     {"delay_ms":1000,"device":"fan","action":"turn_on"}],
    "response_text":"Cyan now, fan in 1s."}
“it's getting warm”
-> {"type":"action","device":"fan","action":"turn_on",
    "response_text":"Fan on."}
“set the brightness to the humidity percentage” (STATE.sensors.humidity = 69.5)
-> {"type":"action","device":"white_led","action":"set_brightness","value":70,
    "response_text":"Brightness set to 70%."}
“turn off automatic mode”
-> {"type":"action","device":"auto_mode","action":"disable",
    "response_text":"Auto-mode off."}
“turn the light off in 10 minutes”
-> {"type":"timer","device":"white_led","action":"turn_off",
    "delay_seconds":600,"label":"10 min light off",
    "response_text":"Light off in 10 min."}
“good night”
-> {"type":"sequence","steps":[
     {"delay_ms":0,"device":"white_led","action":"turn_off"},
     {"delay_ms":0,"device":"rgb_led","action":"turn_off"},
     {"delay_ms":0,"device":"fan","action":"turn_off"},
     {"delay_ms":0,"device":"auto_mode","action":"disable"}],
    "response_text":"Good night."}
“how tall is the Empire State Building”
-> {"type":"action","device":"none","action":"report",
    "response_text":"443 m (1,454 ft) to the tip."}
“make me a sandwich”
-> {"type":"action","device":"none","action":"noop",
    "response_text":"Sorry, I can't do that."}

The model can also use the room's readings as inputs, so when I ask it to “set the brightness to the humidity percentage”, it reads the live humidity from the cached sensor state, rounds it, clamps it to the LED's 0 to 100 range and emits a real set_brightness command.

Hardware

Everything hangs off one ESP32-WROOM running MicroPython, with the inputs on one side and the outputs on the other. One non-blocking main loop serves all of them, so trigger detection never stalls.

Sensors and inputsOutputsI2C bus (SDA 21, SCL 22) and UI buttonsESP32WROOM, MicroPythonone non-blocking loopG14, 23, 32INMP441 micI2S microphoneG4DHT22temperature and humidityG35PIRmotionG34LDR modulelight or darkG19PTT buttonpush-to-talkG25White LEDPWM brightnessG27NeoPixelWS2812 RGBG26Fanon or offG13Servo0 to 180°G33Buzzerbeeps and alertsG17REC LEDrecordingI2COLEDSSD1306, 0x3CI2CDF2301Qwake word, 0x64G18Nav ApageG16Nav Bpage
ESP32-WROOMMicroPython, one non-blocking loop
Sensors and inputs
INMP441 micI2S microphone
G14, 23, 32
DHT22temperature and humidity
G4
PIRmotion
G35
LDR modulelight or dark
G34
PTT buttonpush-to-talk
G19
Outputs
White LEDPWM brightness
G25
NeoPixelWS2812 RGB
G27
Fanon or off
G26
Servo0 to 180°
G13
Buzzerbeeps and alerts
G33
REC LEDrecording
G17
I2C bus (SDA 21, SCL 22) and UI buttons
OLEDSSD1306, 0x3C
I2C
DF2301Qwake word, 0x64
I2C
Nav Apage
G18
Nav Bpage
G16
Every component and the GPIO it uses, with the OLED and the DF2301Q sharing one I2C bus

The LDR is a digital light module with its own sensitivity potentiometer, so there are no analog reads, which avoids the ESP32's ADC conflict with WiFi. A red LED lights only while the microphone is recording, and an SSD1306 OLED with two navigation buttons shows the status and the last command across four pages. The DF2301Q wake-word module is wired in and its driver is written, but on the bench I demo with the push-to-talk button.

Close-up of the INMP441 I2S microphone wired to the ESP32
The INMP441 I2S microphone.

Fitting it in memory

The ESP32-WROOM has no PSRAM, and with WiFi up MicroPython left me about 33 KB of usable RAM. A voice clip is about 96 KB, so the audio cannot fit in memory all at once.

To get around that, nothing ever holds the whole clip. The microphone is one persistent, pre-warmed instance, the capture buffers are small and allocated lazily, and the upload is streamed over a raw socket as it records, sending a preamble, the WAV header, the PCM chunk by chunk and then a tail. This keeps peak memory during an upload to about 10 KB. Building one big bytes object instead makes the garbage collector take a ~26 KB block from the same heap that WiFi and the I2S microphone need, which starves the network stack until the upload times out.

The current firmware ships a lean four-page status screen on the OLED, because a richer version with live-refreshing sensor values and a recording splash grew the heap enough to break boot. With it, the board could no longer connect to MQTT (ENOBUFS) or open the microphone (ENOMEM). To make room I also removed the real-time clock and clock-time schedules, so timers now run off a monotonic tick count and need no clock.

Auto mode

Auto mode runs locally on the board. When it detects motion while the room is dark, it turns the white LED on and switches it off again after five minutes without motion. When the temperature rises above the comfort range, it turns the fan on, with a hysteresis gap so the fan does not keep toggling around the threshold.

Any spoken command takes priority and clears the automatic state, so auto mode never overrides a light you just set.

Dashboard and deployment

The server is a Dockerised FastAPI app with a web dashboard: device controls (white LED, RGB picker, fan, servo, buzzer, auto-mode toggle, comfort-range editor), a live state readout, a temperature and humidity history chart, a log of recent commands, a player for the last few voice recordings, and a text box that feeds the same LLM path. The text box is my backup in case the microphone fails during a live demo, and a reset clears the chart, log and recordings.

It runs on my homelab behind Nginx Proxy Manager and Cloudflare, which serve the dashboard on an HTTPS hostname. The MQTT broker is reached directly rather than through Cloudflare, and the ESP32 only talks to a LAN address instead of the public hostname, which keeps the firmware small.

The LUMEN web dashboard: device controls, live readout, history chart and activity log
The LUMEN web dashboard

Slides

This is the deck I presented at the module review, which covers the brief, the pipeline, the memory work and the demo.

What I'd add next

An ESP32-S3 with PSRAM would bring back most of what I cut, because the WROOM is already at its limit streaming microphone audio while it runs WiFi and MQTT.

  • A richer OLED with the live-refreshing sensor pages and the recording splash that I had to remove.
  • Clock-time schedules (“every day at 8 am”), which need the real-time clock I removed to save memory.
  • Durable history, so the dashboard's charts and the timers survive a reboot, because today the last couple of hours live only in RAM.
  • A working wake word on the hardware, so push-to-talk becomes the fallback instead of the main trigger.
More to explore

Other projects

Personal
OCR Reader with DrumNet, an OCR water meter solution

OCR Reader

A battery-powered water meter reader where a 693K-parameter DrumNet pipeline on an ESP32-S3 reads the drums and reports over LoRaWAN, built on a custom KiCad PCB inside a 3D-printed shell.

Personal
Project June rover

Project June

A 5G rover with three live camera feeds, GPS, a laser pointer and seven sensors, driven from a web console.

Internship
Pip, a cyan desk pet, on the M5Stack Tab5

Pip

A desk pet on an M5Stack Tab5 whose brain is the DeepSeek Harness on my server, so it can drive a browser, build its own apps and watch my other agents.