Need help on automation trigger from/with rhasspy

Hi,

I’m using on 2x Pi3B+ : 1x Home Assistant (not hass.io) and 1x rhasspy.
Every thing is ok …

In rhasspy, I use the example [SetLight] with room, in slot :
(from rhasspy)

"hass_event":
"event_data":
"_raw_text": "allume tout"
"_text": "allume tout"
"piece": "bureau"                                               <---- piece = room in french !!! 
"event_type": "rhasspy_SetLight"

well received by Home Assistant (function “Listen to event” )

But, I don’t understand how to “script” into automation.yaml.

What I want to do is :
Make a test on the value of (the slot) room
and tts something different depending of the value
and tts the slot (too …)

- alias: 'rhasspy 2'
  trigger:
    platform: event
    event_type: rhasspy_SetLight
    event_data: 
      piece: rhasspy_SetLight.piece
  action:
    - service: light.turn_on
      entity_id: light.bureau
    - service: rest_command.tts
      data_template: 
        #{payload: "Office switched on at {{now().hour}} and {{ now().minute }} minutes"}
        {payload: "I switched on  {{ piece }}"}

A first sight, ‘event_data’ blocks HA … or it is SetLight.piece
I don’t know/understand

I’ve tryied some examples from this forum / web, but they generates errors or hang

Help mucho mucho appreciated
Link to up2date documentation / examples welcome.

Thanks to share and help

Go to the EVENTS tab of the Developer Tools page. Enter “rhasspy_SetLight” (without quotes) where it says “Event to subscribe to”. Then click START LISTENING. Now, cause the event to happen. It should be printed out, with all the details. That will help you understand what is contained in the event. You can post what you get here if you like and I can help you further.

@pnbruckner,

Thank you for your answer.

I allready do what you recommand, and in fact I see/get all the details.

My problem is I don’t understand how to handle the data (slot values …) in script inside automation.yaml (or another file …).

For example :
if I get (in HA) the following

{
    "event_type": "rhasspy_SetLight",
    "data": {
        "piece": "bureau",
        "_text": "allume le bureau",
        "_raw_text": "allume le bureau"
    },
    "origin": "REMOTE",
    "time_fired": "2020-03-22T07:10:48.852114+00:00",
    "context": {
        "id": "148ebe9e20bd48cd915439f6d7d938ef",
        "parent_id": null,
        "user_id": "d2c36efd2ee24987ac996426821a428b"
    }
}

I can see I have “piece”:“bureau” (It’s what I expect …)

In the script I use :
event_data:
piece : rhasppy_SetLight.piece

Is this syntax correct to have ‘a kind of variable’ named ‘piece’ ?

And if yes, how to use it to make test or to send it back to rhasspy ?
I’ve tryied kind of something like the now.hour() example (that works…) but it’s not ok.
Maybe it’s the {{…}} that is not correct ?
Do you have an up2date link to documentation for this kind of usage ?

BTW : when I use as above ‘event_data’ the action seems to be ignored. If I remove it, the action is executed, I can hear “I switch on …”

Thanks for your time :slight_smile:

If you want the automation to trigger only if the event type is rhasspy_SetLight and the data contains "piece": "bureau", then:

- alias: 'rhasspy 2'
  trigger:
    platform: event
    event_type: rhasspy_SetLight
    event_data: 
      piece: bureau
  action:
    - service: light.turn_on
      entity_id: light.bureau
    - service: rest_command.tts
      data_template: 
        payload: "I switched on {{ trigger.event.data.piece }}"

If you want it to trigger no matter what the value of piece is, then simply remove event_data (and what’s below it) from the trigger. E.g.:

- alias: 'rhasspy 2'
  trigger:
    platform: event
    event_type: rhasspy_SetLight
  action:
    - service: light.turn_on
      data_template:
        entity_id: "light.{{ trigger.event.data.piece }}"
    - service: rest_command.tts
      data_template: 
        payload: "I switched on {{ trigger.event.data.piece }}"

@pnbruckner,

I’ll read all of your post very carefully to be sure I understand.

Thanks a lot for this

:slight_smile:

1 Like

@pnbruckner,

I try what you gave as example …
for example #2 it’s OK for me,
#1 with ‘event_data’ hangs HA … (intent not processed to the end …)

Also (if I may …)
I’m trying the example available on ‘templating’ at the HA site,

- alias: 'rhasspy 2'
  trigger:
    platform: event
    event_type: rhasspy_SetLight
    #event_data: 
    #   piece2: piece
  action:
    - service: light.turn_on
      entity_id: light.bureau
    - service: rest_command.tts
      data_template: >
          {% if is_state('device_tracker.paulus', 'home') %}
          {payload: "Ha, Paulus is home!"}
          {% else %}
          {payload:"Paulus is at {{ states('device_tracker.paulus') }}"
          {% endif %} }

(2 space identation after ‘data_template: >’ )
but I get an :
Invalid config for [automation]: expected a dictionary for dictionary value @ data['action'][1]['data_template']. Got None
error

I’ve read somes posts and docs … tryied the solutions provided … nope !
this #{|^[|#~{~{ syntax is not easy (for me !)

Thanks in advance for your answer, and for the time spent

pm

I don’t understand what you mean by that.

As far as your last example, you can’t put keys (like payload) inside a template. A template can only provide a value for one key.

data_template:
  payload: >
    TEMPLATE GOES HERE

Don’t worry. Many people new to HA and YAML make this mistake. It takes a while to get the hang of it.

I guess my (main) mistake was here :

A template can only provide a value for one key .

I misunderstand this

I’ll try to go forward and let you know
:slight_smile:

@pnbruckner,

Every things works fine now !
A great thank you for your help, patience and time.
:slight_smile:

1 Like