Building an Out-of-the-Box Voice Assistant: External Processing with n8n

TL;DR Use Custom Sentence Trigger & Restful Command

configuration.yaml:

...
rest_command:
  custom_http_post:
    url: "{{ url }}"
    method: post
    headers:
      Content-Type: "application/json"
      Authorization: "Bearer {{ token }}"
    payload: "{{ payload }}"

create automation:

alias: restful-automation
description: ""
triggers:
  - trigger: conversation
    command:
      - (ask|tell) ai {query}
conditions: []
actions:
  - action: rest_command.custom_http_post
    response_variable: query_response
    data:
      url: http://192.168.0.111:5678/webhook-test/hass
      token: ""
      payload: >-
        {{ { 'query': trigger.slots.query , 'conversation_id': 'n8n' } | to_json
        }}
  - set_conversation_response: "{{ query_response }}"
mode: single

Example

Note: Remember to change the Webhook response to last executed node :smiley:

Used integrations and Addons:

  • HassMic
  • OpenAI_Compatible_Conversation
  • Whisper
  • Piper
  • OpenWakeWord

References

The following references consist the step by step guide of setting up the whole voice assist framework:

2 Likes

Many thanks! Would you mind to share your example workflow for easy C&P?


For the webhook, you can refer to the image above. The yaml configuration listed are not depend on specific LLM integration, it simply trigger by the specific conversation (from stt or chat) and send the query to the n8n webhook for further processing.

Coming back to you again. Basicly this N8N call is working, but often I receive the error “Timeout when calling resource” when I look into the Traces of the automation. The request itself is performed by N8N successfully, but the home assistant automation timing out way to early. The timeout time is very random as well. Do you have any idea what could be the reason?


you may try increase the timeout of the restcommand which default to 10s only

1 Like