Defining Voice Commands in Rhasspy and the JSON Output They Produce
Updated
You define voice commands in Rhasspy by writing them in a template language that describes a grammar of possible sentences. When Rhasspy recognizes speech that matches one of those sentences, it produces a JSON event containing the recognized text, the intent name, and any slots (variable parts) that were filled in. This approach is best suited to pre-specified commands that a grammar can describe well, though Rhasspy also supports open-ended speech recognition when you need it.
How the template language works
A command definition combines a sentence template with the values its variable parts can take. The documentation's example is:
[LightState]
states = (on | off)
turn (){state} [the] light
Reading this definition:
[LightState]names the intent.states = (on | off)declares a set of allowed values.turn (){state} [the] lightis the sentence pattern.(){state}marks a slot namedstatethat draws from thestatesset, and[the]is an optional word.
The grammar therefore accepts sentences such as "turn on the light" and "turn off the light," with or without "the."
What output the command produces
When spoken input matches the grammar, Rhasspy emits a JSON event. For "turn on the light" the documented output is:
{
"text": "turn on the light",
"intent": {
"name": "LightState"
},
"slots": {
"state": "on"
}
}
Three fields matter for downstream automation:
| Field | Meaning |
|---|---|
text |
The recognized sentence |
intent.name |
The intent label from your template (LightState) |
slots |
Named variable values extracted from the sentence (state: on) |
Home automation software can then trigger actions from this event—for example, a Node-RED flow that switches a light based on the state slot.
Where the output goes
Rhasspy is built to work with external services over MQTT, HTTP, and WebSockets, and it has built-in support for Home Assistant and Hass.io. You can send and receive Hermes MQTT messages, call Rhasspy's HTTP API, or connect a WebSocket to one of its endpoints. The web interface, which lets you configure, program, and test the assistant remotely, exposes all of its functionality through a comprehensive HTTP API.
When this grammar approach fits—and when it doesn't
Rhasspy is optimized for pre-specified voice commands that a grammar describes well, which keeps recognition focused and the resulting intents predictable. It also supports open-ended speech recognition, so you are not limited to fixed sentence patterns. For commands containing uncommon words or pronunciations, new words can be added phonetically with automated assistance.
A practical way to decide: if your commands are a known, bounded set (light states, timers, scene names), the template language gives you clean intents and slots with little ambiguity. If you need free-form dictation, plan on the open-ended recognition path instead of a grammar.
Getting from definition to working command
The documented getting-started sequence is:
- Confirm you have the necessary hardware.
- Choose an installation method.
- Access the web interface and download a profile.
- Author your custom voice commands and train Rhasspy.
- Connect Rhasspy to other software such as Home Assistant or a Node-RED flow via Hermes MQTT, the HTTP API, or a WebSocket.
Training is the step that turns your templates into a usable model, so expect to retrain after changing command definitions. If you run into problems, the Rhasspy community site and the GitHub issue tracker are the documented support channels.