Rhasspy not passing light name to HA

I’m attempting the template example given in rhasspy docs to control lights in homeassistant, using a data template. The tutorial uses JSON data in slots, but rhasspy no longer seems to use JSON for slots, instead using a text file. I found that an entry such as:

(door lights){switch.door_lights}
(kitchen lights){switch.kitchen_lights}
(basement lights){switch.basement_lights}
(dining lights){switch.dining_lights}
(garage lights){switch.garage_lights}

is accepted by rhasspy. The sentences entry reads:

[ChangeLightState]
state = (on | off) {light_state}
turn [the] ($lights) {light_name} <state>
turn <state> [the] ($lights) {light_name}

When triggered by voice recognition the following JSON is produced:

{
    "intent": {
        "name": "ChangeLightState",
        "confidence": 1
    },
    "entities": [
        {
            "entity": "light_state",
            "value": "on",
            "value_details": {
                "kind": "Unknown",
                "value": "on"
            },
            "raw_value": "on",
            "start": 5,
            "end": 7,
            "raw_start": 5,
            "raw_end": 7
        },
        {
            "entity": "switch.kitchen_lights",
            "value": "kitchen lights",
            "value_details": {
                "kind": "Unknown",
                "value": "kitchen lights"
            },
            "raw_value": "kitchen lights",
            "start": 12,
            "end": 26,
            "raw_start": 12,
            "raw_end": 26
        },
        {
            "entity": "light_name",
            "value": "",
            "value_details": {
                "kind": "Unknown",
                "value": ""
            },
            "raw_value": "",
            "start": 12,
            "end": 26,
            "raw_start": 12,
            "raw_end": 26
        }
    ],
    "slots": {
        "light_state": "on",
        "switch.kitchen_lights": "kitchen lights",
        "light_name": ""
    },
    "text": "turn on the kitchen lights",
    "raw_text": "turn on the kitchen lights",
    "tokens": [
        "turn",
        "on",
        "the",
        "kitchen",
        "lights"
    ],
    "raw_tokens": [
        "turn",
        "on",
        "the",
        "kitchen",
        "lights"
    ],
    "wakeword_id": "jarvis_raspberry-pi",
    "siteId": "default",
    "sessionId": "default-jarvis_raspberry-pi-275ba5d4-85ac-4c7d-be65-fb717bf804c6",
    "customData": "jarvis_raspberry-pi",
    "wakewordId": "jarvis_raspberry-pi",
    "lang": null
}

As you see, no value for light_name is sent to HA, but there it is needed in the automation data template. Should the slots entry be another format, or somehow use JSON? Any help is appreciated.

I should add that if I hard code light_name in HA automation.yaml, that is, change this

light_name: "{{ trigger.event.data.light_name }}"

to this

light_name: "switch.kitchen_lights"

then rhasspy will turn those lights on and off. So the problem is definitely that rhasspy isn’t passing light_name and that is probably because the slots entries are wrong. How to fix them?

Actually the JSON you posted is sending 3 entities: “light_state”, “switch.kitchen_lights”, and “light_name” - also summarised in the section

    "slots": {
        "light_state": "on",
        "switch.kitchen_lights": "kitchen lights",
        "light_name": ""
    },

Rhasspy is taking the { and } in your slots as an entity name :frowning: See the documentation

Yes, it is sending “light_name” but “light_name” is always empty. HA needs to receive “light_state” as “on” or “off”, which it does, and “light_name” as “switch.kitchen.lights” or “switch.dining.lights”, etc., which it doesn’t. Isn’t there a way to set up slots and sentences to have rhasspy populate “light_name” with the variable HA needs, that is, “switch.kitchen.lights” and so on?

It is exactly like @donburch is saying. This is wrong

it must be

(door lights):switch.door_lights

Definitely, and it starts by not having the {} braces in your slots file because they indicate an entity name. Currently when Rhasspy matches " (kitchen lights){switch.kitchen_lights}" in your slots file the {} tell rhasspy to send the value “kitchen lights” as an entity named “switch.kitchen_lights”.

What i think you want is that when rhasspy detects “kitchen lights” it should substitute “switch.kitchen_lights”, and for the sentences to send that as the entity “light_name” ???

In your slots file try changing {} to a colon : as in

(kitchen lights):switch.kitchen_lights

Thank you. That works. I could not find this anywhere in the documentation.

It is here:

https://rhasspy.readthedocs.io/en/latest/training/#substitutions

Thanks, I will study that section more thoroughly.

It is definitely there :wink: … but like most “documentation” for open source projects it is written more for developers than for new users. Having said that, I think Rhasspy’s documentation is much more user-friendly than the Home Assistant documentation :wink:

There is plenty of great information, but it take time and experimenting for it to ‘fall into place’.