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.
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.
“Set the light to cyan and turn the fan on a second later.”
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.
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
- You trigger it by saying “Hello Robot” or holding the push-to-talk button.
- The INMP441 records about three seconds of 16 kHz mono audio, and the red REC LED stays lit while it does.
- The board wraps the raw PCM in a 44-byte WAV header and streams it to
/uploadwhile it is still recording. - The server sends the clip to OpenRouter, where Whisper transcribes it into text.
- The server adds context by passing the model the transcript along with a snapshot of device state and sensor readings.
- 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.
- The server sends the command over MQTT and appends a row to the Google Sheet.
- 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”.
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.
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
- action: a single device change.
- sequence: ordered steps, each with delay_ms from the trigger moment.
- 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
-> {"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."}-> {"type":"action","device":"fan","action":"turn_on",
"response_text":"Fan on."}-> {"type":"action","device":"white_led","action":"set_brightness","value":70,
"response_text":"Brightness set to 70%."}-> {"type":"action","device":"auto_mode","action":"disable",
"response_text":"Auto-mode off."}-> {"type":"timer","device":"white_led","action":"turn_off",
"delay_seconds":600,"label":"10 min light off",
"response_text":"Light off in 10 min."}-> {"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."}-> {"type":"action","device":"none","action":"report",
"response_text":"443 m (1,454 ft) to the tip."}-> {"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.
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.

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.

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.




