HA wth Rhasspy plugin minimal effort automation lights example no deep shit

Hi

It seems there is a missing link between installing the Rhasspy plugin and adding my lights to Home assistant. I am very great full to the community for making these two cool tools but I think the last 1% is missing. Once I enabled all the stuff in Rhasspy mic and speaker and used all the recommended stuff it took me WAY to long to connect the events generated in Rhasspy to HA. I was also not prepared to write multiple files different setting that I know would change later or would require maintaing.

This script will turn individual lights on and off or all the ground floor lights. When event come though from Rhasspy they will have a space in the name. This is stripped by the script.

In the sentences I have

[ChangeLightState]

lightname = ((ground floor | living room | hallway | back garden | dining room) {name}) | <ChangeLightColor.lightname>
light_state = (on | off) {state}
turn <lightstate> [the] <lightname> light
turn [the] <lightname> light <lightstate>
turn [the] <lightname> lights <lightstate>

Then in HA I have one automation.

alias: Change Lights
description: ''
trigger:
  - eventtype: rhasspyChangeLightState
    platform: event
condition:
  - condition: template
    value_template: '{{ ''name'' in trigger.event.data and ''state'' in trigger.event.data }}'
action:
  - servicetemplate: light.turn{{ trigger.event.data.state }}
    data_template:
      entity_id: >
        {% if trigger.event.data.name|replace(" ","") == 'groundfloor' %}
        light.diningroom,light.livingroom,light.hallway
        {% else %}
        light.{{ trigger.event.data.name|replace(" ","")}}
        {% endif %}

mode: single

You will most likely need to adjust your entities above in this example they were called

light.hallway
light.livingroom
light.diningroom
etc…

This saves writing a truck load of jinja2 for every light state. I am shocked this is not the default style of setup. As for jinja2 WTF who invited that language to the party?

good luck with your setups :slight_smile: and have fun.

It took me some time to figure those events out aswell.

I can see you are using groundfloor to turn multiple entities on/off. When adding an extra light, you have to change that as well.
It might be a good idea for you to create a group groundfloor in Home Assistant and turn that on/off instead. Saves some work.
Also you can get TTS feedback from Rhasspy too if you want.

Adding something like this to :

  - service: mqtt.publish
    data:
      topic: hermes/dialogueManager/endSession
      payload_template: '{"sessionId": "{{trigger.event.data._intent.sessionId}}",
        "text": "Ok, {{ trigger.event.data..name|replace(" ","") }} {{ trigger.event.data.state }}"}'

You could skip the text, but letting Rhasspy know what you did via endSession is good practise.
Otherwise Rhasspy goes back to ilde after a timout of 30sec. (You will probably see those timeouts in your Rhasspy log at the moment)

Thanks, I see you are using intents. I am using events, does this matter. When I tried enabling mqtt on the Rhasspy end it got caught in a boot loop and I had to reinstall the whole thing.

No, I am using events as well.
But the event.data has the _intent object which has the sessionId and siteId

I see I have made a typo too, it should be trigger.event.data.name|replace(" “,”")