Custom Voice Control Sentences in Home Assistant

Create your OWN sentences for LOCAL VOICE CONTROL in Home Assistant with Node-RED or basic YAML configurations.

Custom Voice Control Sentences in Home Assistant

As I continue playing with local voice control in Home Assistant, I find more ways to make it better. One of those is the use of custom sentences and responses. What finally pushed me to explore this is the "Sentence" node in Node-RED. Yes, I know there are those of you who don't enjoy Node-RED as I do so there is the "harder" way to do custom sentences in Home Assistant directly. Let's get started.

💡
Be sure to watch my video that relates to this post.

First, the easier way (maybe).

This method uses the Sentence node that I mentioned above. The reason it is so simple is that all you need to do is add the node, specify the sentence(s) you want the node to listen for, and then configure some action to happen when saying that sentence.

Sentence node in Node-RED

There are some prerequisites that you need to make sure are satisfied before this will work.

  • The sentence node was added to version 0.56.0 of node-red-contrib-home-assistant-websocket. You need to make sure you are running at least that version. As of this post, version 0.59.0 is the latest. I should point out that there are nested requirements so you really need version 0.57.0 just to be able to run hass-node-red. Check the latest requirements to make sure you have the needed versions.
  • You also need version 2.2.0 of hass-node-red, also known as the Node-RED companion application (installed via HACS).
  • For the companion app, you will also need at least Home Assistant version 2023.7 (as of this post).
  • It should go without saying that you need the voice assist set up in Home Assistant.

It's always best to make sure you are running updated versions of all the software so you can take advantage of any new features, enhancements, and security updates.

Assuming you have all the correct versions of the software, adding the sentence is super easy. You can tell it is ready to go if you see it registered.

This sentence node is registered and listening.

As with any node, add it to your flow and then double-click to configure it.

Configuration screen for the sentence node.

In this example, the node listens for the sentence "Engage the guest lamp". The response sent back to the voice assistant is "Welcome to the light". I also gave it a meaningful name so I would know what the node is doing. That's it! When you say that sentence, whatever you set to do after that node will execute.

To test, you can click on the assist button in your Home Assistant screen and type in the sentence that you configured to listen for. You should get the response you added in the node.

Example of assist responding to a request using the Node-RED flow.

The Hard(er) Way

If you are not a fan of Node-RED or aren't running it, you can still build out custom sentences and responses. What makes this a bit harder is that you need to get into YAML and create some files in your Home Assistant instance.

Step one is to create a directory in your config directory based on the language model you want to use. For me, that is English. The directory would then be:

custom_sentences/en

In that new directory, you would create a file containing your custom sentence(s). Let's call it guestlampon.yaml. Using my guest lamp sentence example (modified slightly so it won't duplicate the sen, the file might look like this:

language: "en"
intents:
  EngageTheGuestLamp:
    data:
      - sentences:
        - "Activate the guest lamp"

That creates an intent for Home Assistant but doesn't do anything. The second step is to create an intent_script in your configuration.yaml file.

intent_script:
  EngageTheGuestLamp:
    action:
      service: light.turn_on
      target:
        entity_id: light.guest_lamp
    speech:
      text: "The guest lamp has illuminated"
     

After adding all of the above, you will need to restart Home Assistant for it to be applied.

You can test the same way with assist in your browser (or tablet, etc).

Using Home Assistant Assist with Custom Sentences

I combined the YAML and Node-RED sentences in the above screenshot. The first sentence uses the YAML intents to turn on the lamp and uses the Node-RED sentence node to turn off the lamp.

Even though I call this method more challenging to implement, it still isn't that bad. Adding a few lines of YAML code and an extra file or two isn't terrible. It comes down to personal preference.

For both of these methods, you can add more than one sentence to the intent. This could be variations on how one says the same thing. For example, "Turn on the kitchen lights" and "Turn on the lights in the kitchen" can be used for the same action. Use your imagination here.

Finally, there are several built-in intents already in Home Assistant that you can extend. You can use the same YAML method to extend those. The Home Assistant conversation documentation shows this nicely. You would place something like this in your custom intent file to turn off or on any entity and even turn on or off any entity in a specific area. Read all about conversations on the Home Assistant conversations page.

language: "en"
intents:
  HassTurnOn:
    data:
      - sentences:
          - "engage [the] {name}"
      - sentences:
          - "engage [all] lights in [the] {area}"
        slots:
          name: "all"
          domain: "light"
  HassTurnOff:
    data:
      - sentences:
          - "disengage [the] {name}"
      - sentences:
          - "disengage [all] lights in [the] {area}"
        slots:
          name: "all"
          domain: "light"

That's it for this blog post. Thanks for reading and be sure to watch the video!