Star Trek Comm Badge for Home Assistant Voice Control
by SpannerSpencer in Circuits > Wearables
88 Views, 1 Favorites, 0 Comments
Star Trek Comm Badge for Home Assistant Voice Control
Tap the badge, speak to the computer, control your home - just like in Star Trek!
This project turns the wonderful M5StickC PLUS2 into a wearable voice controller for Home Assistant. The device uses tap detection, Voice Activity Detection, and AI transcription (via Groq or OpenAI Whisper) to send natural language commands directly to Home Assistant so you can control your home automation from anywhere.
It's got a built-in config panel accessed view a web access point, to make it easy to set up. From here you can add your WiFi credentials, and the requred API keys (these are like complex passwords that let the comm badge - and nothing else, so don't ever share them - to Home Assistant and your AI provider).
I went with Groq, as its Whisper API - which transcribes speech into text - is very generous. I've been using the comm badge all day, and I haven't hit the limit of the free tier yet. But you can use OpenAI or a custom provider if you want.
The M5StickC PLUS2's built-in magnet pairs perfectly with magnetic Star Trek comm badges, making this a genuinely wearable smart home controller that feels like the real thing.
Total cost: Under £25
Build time: ~30 minutes
Difficulty: Beginner-friendly
Supplies
Hardware
- M5StickC PLUS2 (~£20)
- Magnetic Star Trek Comm Badge (~£5)
- USB-C cable for programming
Software & Services
- Arduino IDE (free)
- Home Assistant instance with Conversation/Assist enabled
- Groq account with API key (free tier) or OpenAI account
- WiFi network (2.4GHz)
Skills Required
- Basic Arduino IDE familiarity
- Ability to create Home Assistant long-lived access tokens
Check the Magnet Polarity (Optional)
The M5StickC PLUS2 has a magnet built into the back of its case. Depending on which comm badge you buy, you may need to flip this magnet to match the polarity of the badge's magnet. I needed to, with my comm badge, which is a very nice metal one with some real shine and substance!
To flip the magnet:
- Carefully peel the sticker off the back of the M5StickC PLUS2 case
- Very carefully pry up the small circular magnet. It's held on with double sided tape, so it removed pretty easily.
- Flip it over.
- Stick it back down (maybe you'll need to replace the sticky tape, but I didn't).
I also left the sticker off, for that tiny bit of extra strength, though I doubt it makes much of a difference to the magnet.
How to know if you need to do this: Hold the badge and M5Stick near each other. If they attract, you're good. If they repel, flip the magnet.
Set Up Arduino IDE
Install the Arduino IDE:
- Download and install the Arduino IDE (version 2.0 or later recommended)
Add M5StickC PLUS2 Board Support:
- Open Arduino IDE
- Go to File → Preferences
- In "Additional Boards Manager URLs", add:
- Click OK
- Go to Tools → Board → Boards Manager
- Search for "M5Stack"
- Install "M5Stack" by M5Stack official
Install Required Libraries:
- Go to Tools → Manage Libraries
- Search for and install:
- M5Unified
- ArduinoJson
(The other required libraries - WiFiClientSecure, HTTPClient, WebServer, Preferences, and Wire - are included with the ESP32 board package)
Upload the Sketch
You're welcome to modify the code as much as you like. I tried to label it as best I could, but I might not have done a great job. Note that you don't have to add any details directly to the sketch - things like your WiFi credentials or API keys. That can all be done later through the comm badge's config panel.
So you should just be able to upload this code exactly as it is with no changes (unless you want to tweak/improve things).
Get the Code:
- Visit the GitHub repository
- Open HA_Comm_Badge_V1.ino
- Copy all the code
Upload to M5StickC PLUS2:
- Connect your M5StickC PLUS2 via USB-C cable
- In Arduino IDE, create a new sketch and paste the code
- Go to Tools → Board → M5Stack Arduino and select M5StickC PLUS2
- Go to Tools → Port and select the port showing your M5StickC PLUS2
- Click the Upload button (right arrow icon in the toolbar)
- Wait for "Done uploading" message
The device will restart automatically when upload is complete.
Initial Configuration
When the device first boots (or if you hold the front button during reset), it enters configuration mode.
Connect to the Device:
- On your phone or computer, look for a WiFi network called: CommBadge-Config
- Password: starfleet
- Connect to this network
- Open a web browser and go to 192.168.4.1
Configure the Settings:
You'll see a Star Trek LCARS-style interface. Fill in:
WiFi Settings:
- Your home WiFi SSID
- Your WiFi password
Home Assistant:
- Your HA URL (e.g., https://homeassistant.local:8123, Nabu Casa cloud URL, or your Home Assistant's local IP address)
- Long-lived access token (create this in HA: Profile → Security → Long-Lived Access Tokens → Create Token)
LLM Provider:
- Select Groq (recommended - free tier), OpenAI, or Custom
- Enter your API key:
- For Groq: Sign up at groq.com, get API key from console
- For OpenAI: Get API key from platform.openai.com
- The API URL will auto-populate based on your provider choice
Advanced Settings (optional - defaults work well):
- Tap sensitivity: 3.4 (lower = more sensitive)
- Max recording time: 4 seconds
- VAD sensitivity: 5 (how quickly it stops after silence)
- Sleep timeout: 60 seconds
Save and Restart:
- Click E
- The device will restart and connect to your WiFi
- You're done with setup!
Attach the Badge
- Take your magnetic Star Trek comm badge
- Place it on the front of your shirt where you want it
- Place the M5StickC PLUS2 behind your shirt, directly behind the badge
- The magnets will hold them together through the fabric
Note: The tap detection works really well through the badge, so you tap the badge itself, not the M5Stick. And the mic doesn't seem to struggle through the fabric either, since it's quite close to your mouth anyway.
Use Your Comm Badge
Basic Operation:
- Tap the badge - You'll hear an activation beep
- Speak your command - e.g., "Turn on the living room lights"
- Wait - The device stops recording automatically when you finish speaking
- Success! - You'll hear a success beep when the command executes
Example Commands:
- "Turn on the living room lights"
- "Set bedroom temperature to 20 degrees"
- "Make the kitchen light turn red"
- "Turn the TV on"
Basically anything you can say to Home Assistant Assist works! You might need to assign areas, names or aliases to devices and/or entities in Home Assistant to ensure it knows which devices you're talking about, but that's more of a Home Assistant config than anything to do with making the comm badge.
Power Management: The device automatically enters deep sleep after 60 seconds of inactivity to save battery. It wakes (more or less) instantly when you tap it. It's adjustable in the config though.
Entering Config Mode Again: Hold the front button for 5 seconds (or hold it down during reset) to re-enter configuration mode if you need to change settings. The screen is turned off during normal operation, but turns on in config mode, so you can see if you successfully activated it.
How It Works
The Technical Flow:
- Tap Detection - The MPU6886 accelerometer detects your tap and wakes the device from deep sleep if needed
- Audio Recording - Starts recording at 16kHz through the built-in microphone
- Voice Activity Detection - Monitors audio levels and automatically stops recording when you finish speaking (minimum 0.8 seconds to avoid cutting you off)
- Transcription - Audio is converted to WAV format and sent to Groq/OpenAI Whisper API for speech-to-text
- Home Assistant - The transcribed text goes to HA's Conversation API where Assist interprets it as a natural language command
- Feedback - Different beep patterns confirm success or indicate errors
Why It's Fast:
- HTTP keep-alive connections to the transcription service
- Efficient VAD reduces unnecessary recording time
- Direct API integration with Home Assistant
Customisation
The code is well-commented and easy to modify if you want to change:
- Audio feedback tones - Modify the play*Beep() functions
- Display behaviour - Update LCD rendering (though with the badge, you won't see the screen!)
- Recording settings - Adjust VAD constants at the top of the sketch
- Config interface styling - Modify the LCARS_CSS section (but why would you?!)
Full code with documentation: https://github.com/graffitiwriter/Home-Assistant-Comm-Badge
Credits
Inspired by: This was inspired by Shay Moradi's (@organised) excellent M5Stick with OpenAI Access project. It just builds on that foundation with Home Assistant integration, VAD, power management, and multi-provider support, and I wouldn't have done it if he hadn't boldly gone there first!
Not affiliated with Paramount or Star Trek brands, obvs.
Final Thoughts
This has genuinely become my favourite way to control the house. I just made it for a bit of fun, not expecting it to work all that well, but it's actually a really interesting concept carrying a Wyoming-style mic satellite around with you, rather than installing static ones all around the house.
Plus, there's something deeply satisfying about tapping your chest and issuing commands like you're on the Enterprise. The TNG activation been is just delivious! The combination of the M5Stick's magnet and a cheap comm badge makes it actually wearable and practical for daily use.
If you build one, I'd love to see it! Share your builds, improvements, and modifications.