Basic Rhasspy light automation

Hi All,

I am new to RPI, Home Assistant, and most things relevant to this project.

Goal: Offline speech recognition for device control

I have HA installed as an OS, which I believe is called Hassio.

I have a Z-wave controller installed, and a Z-wave switch connected both of which are operational.

Rhasspy is installed and configured based on many guides I’ve read.

I have been unable to get the events/api method to work at all for any communication back to HA. I have manually triggered events and monitored them from HA and confirmed they are seen when listening but the same event triggered from Rhasspy is not seen by HA.

I moved on to MQTT.

MQTT broker addon installed on HA and configured accordingly on Rhasspy.

After much trial and error and help from the Rhasspy forum, I can toggle the Z-wave switch.

However, it is indiscriminate of the toggle state requested “on/off” and of the device requested “living room lamp/garage light”.

So when typing the test in Rhasspy, it doesn’t matter if I type “turn on living room lamp” or “turn off garage light” etc, it will simply toggle from the current state of the switch, which is named Living Room Lamp with entity id switch:living_room_lamp.

I understand there are means to have HA review the JSON from Rhasspy for variables, I just don’t understand how to configure it. I understand I can create a unique command set in Rhasspy for device-on/device-off and corresponding automations for every command set but that would result in excessive command sets and automations as I intend on having many lights in this configuration.

Data published to MQTT broker and JSON from Rhasspy that generated the MQTT data below, as well as automation YAML. Automation YAML does not include any conditions/filtering for intended device, only shown as example of what will action when the ChangeLightState intent is seen on the MQTT broker.

{“input”: “turn living room lamp on”, “intent”: {“intentName”: “ChangeLightState”, “confidenceScore”: 1.0}, “siteId”: “default”, “id”: “", “slots”: [{“entity”: “name”, “value”: {“kind”: “Unknown”, “value”: “living room lamp”}, “slotName”: “name”, “rawValue”: “living room lamp”, “confidence”: 1.0, “range”: {“start”: 5, “end”: 21, “rawStart”: 5, “rawEnd”: 21}}, {“entity”: “state”, “value”: {“kind”: “Unknown”, “value”: “on”}, “slotName”: “state”, “rawValue”: “on”, “confidence”: 1.0, “range”: {“start”: 22, “end”: 24, “rawStart”: 22, “rawEnd”: 24}}], “sessionId”: "”, “customData”: null, “asrTokens”: [[{“value”: “turn”, “confidence”: 1.0, “rangeStart”: 0, “rangeEnd”: 4, “time”: null}, {“value”: “living”, “confidence”: 1.0, “rangeStart”: 5, “rangeEnd”: 11, “time”: null}, {“value”: “room”, “confidence”: 1.0, “rangeStart”: 12, “rangeEnd”: 16, “time”: null}, {“value”: “lamp”, “confidence”: 1.0, “rangeStart”: 17, “rangeEnd”: 21, “time”: null}, {“value”: “on”, “confidence”: 1.0, “rangeStart”: 22, “rangeEnd”: 24, “time”: null}]], “asrConfidence”: null, “rawInput”: “turn living room lamp on”, “wakewordId”: null, “lang”: null}
{
    "entities": [
        {
            "end": 7,
            "entity": "state",
            "raw_end": 7,
            "raw_start": 5,
            "raw_value": "on",
            "start": 5,
            "value": "on",
            "value_details": {
                "kind": "Unknown",
                "value": "on"
            }
        },
        {
            "end": 24,
            "entity": "name",
            "raw_end": 24,
            "raw_start": 8,
            "raw_value": "living room lamp",
            "start": 8,
            "value": "living room lamp",
            "value_details": {
                "kind": "Unknown",
                "value": "living room lamp"
            }
        }
    ],
    "intent": {
        "confidence": 1,
        "name": "ChangeLightState"
    },
    "raw_text": "Turn on living room lamp",
    "raw_tokens": [
        "Turn",
        "on",
        "living",
        "room",
        "lamp"
    ],
    "recognize_seconds": 0.16609663400049612,
    "slots": {
        "name": "living room lamp",
        "state": "on"
    },
    "speech_confidence": 1,
    "text": "turn on living room lamp",
    "tokens": [
        "turn",
        "on",
        "living",
        "room",
        "lamp"
    ],
    "wakeword_id": null
}
alias: Rhasspy
description: ''
trigger:
  - platform: mqtt
    topic: hermes/intent/ChangeLightState
condition: []
action:
  - service: switch.toggle
    data: {}
    target:
      entity_id: switch.living_room_lamp
mode: single

I just started working with rhasspy and HA too and was having some similar issues. I think your trigger is wrong. the trigger is EVENT and the topic is ‘rhasspy_ChangeLightState’. Every message from rhasspy will come as an event with event type= ‘rhasspy_NameOfIntentFromSentanceList’. I think the first part of your HA yaml should be:

alias: Rhasspy
description: ' '
trigger:
  - platform: event
    event_type: rhasspy_ChangeLightState
condition: []
action:
  - service: switch.toggle
    data: {}
    target:
      entity_id: switch.living_room_lamp
mode: single