Home assistant core + Rasspy configuration

Hi Romkabouter,
Yes I started with HA Docker and realised that HA doesn’t come default Supervisor. Thus I managed to install from GitHub the Supervisor in order to get Rhasspy as an Add-On. This build only have default HTTP.

However, I have HA warning on the Supervisor tab now that either my Raspbain version or Supervisor is unsupported.

Thus as a back-up worrying my above build will be end of life, I have flash another SD card of HA OS with Rhasspy as Add-On with SSL and HTTPS turned-on.

And I manage to replicate all the functions of Rhasspy Wake word > Intent Recognition > STT > Intent Handling as Event > HA Automation and was working fine. Only missing part is HA TTS > Rhasspy Audio Out which I couldn’t get it working.

And now I read a post what back Nov '20 by maleko on how to undo the external MQTT. So I manage to revert back Rhasspy internal MQTT on my 2 builds. So now I am back where I am post changing to external MQTT.

And after some check on my HA automation codes, spotted a minor syntax on “payload_template” which I have corrected.

Thereafter, I have done more Rhasspy > HA testing and spotted this error in row #3 on HA Rhasspy log as per below. It seems like the session has pre-mature termination before HA can perform MQTT Publish. Correct me if I am wrong?

[DEBUG:2021-06-12 18:18:40,402] rhasspyasr_kaldi_hermes: Receiving audio
[DEBUG:2021-06-12 18:18:40,402] rhasspywake_porcupine_hermes: Receiving audio
[ERROR:2021-06-12 18:19:08,160] rhasspydialogue_hermes: Session timed out for site default: default-porcupine_raspberry-pi-7ae06341-6b9a-43cb-acdd-30d7aa939263
[DEBUG:2021-06-12 18:19:08,162] rhasspydialogue_hermes: -> AsrStopListening(site_id='default', session_id='default-porcupine_raspberry-pi-7ae06341-6b9a-43cb-acdd-30d7aa939263')
[DEBUG:2021-06-12 18:19:08,162] rhasspydialogue_hermes: Publishing 105 bytes(s) to hermes/asr/stopListening
[DEBUG:2021-06-12 18:19:08,168] rhasspydialogue_hermes: -> DialogueSessionEnded(termination=DialogueSessionTermination(reason=<DialogueSessionTerminationReason.TIMEOUT: 'timeout'>), session_id='default-porcupine_raspberry-pi-7ae06341-6b9a-43cb-acdd-30d7aa939263', site_id='default', custom_data='porcupine_raspberry-pi')
[DEBUG:2021-06-12 18:19:08,168] rhasspydialogue_hermes: Publishing 183 bytes(s) to hermes/dialogueManager/sessionEnded
[DEBUG:2021-06-12 18:19:08,171] rhasspydialogue_hermes: -> HotwordToggleOn(site_id='default', reason=<HotwordToggleReason.DIALOGUE_SESSION: 'dialogueSession'>)
[DEBUG:2021-06-12 18:19:08,172] rhasspydialogue_hermes: Publishing 50 bytes(s) to hermes/hotword/toggleOn
[DEBUG:2021-06-12 18:19:08,220] rhasspyasr_kaldi_hermes: <- AsrStopListening(site_id='default', session_id='default-porcupine_raspberry-pi-7ae06341-6b9a-43cb-acdd-30d7aa939263')
[DEBUG:2021-06-12 18:19:08,220] rhasspywake_porcupine_hermes: <- HotwordToggleOn(site_id='default', reason=<HotwordToggleReason.DIALOGUE_SESSION: 'dialogueSession'>)
[DEBUG:2021-06-12 18:19:08,220] rhasspywake_porcupine_hermes: Enabled
[DEBUG:2021-06-12 18:19:08,220] rhasspyasr_kaldi_hermes: Stopping listening (session_id=default-porcupine_raspberry-pi-7ae06341-6b9a-43cb-acdd-30d7aa939263)
[DEBUG:2021-06-12 18:19:08,236] rhasspywake_porcupine_hermes: Receiving audio

If you have set Rhasspy to internal again, there will be no messages coming in from Home Assistant to Rhasspy after the intent is recognized and after a while a timeout occurs.

They need to be on the same broker, that is why you need Rhasspy to connect to an external broker.
Have you tried installing the MQTT addon yet?

Got it. Working on installing and configure Mosquitto MQTT again. Will keep you post. Thanks.

After turning back on external MQTT, again Rhasspy is looping again and crash. Unable to restart until I reset back to internal MQTT. Very strange to have such behaviour.

What are your settings?
Can you connect ok with another cliënt?

Here is my Rhasspy external MQTT setting.

And each time I get the below socket error in Rhasspy log after 10 tries to connect and then final message of “Failed to connect MQTT broker”.

socket.gaierror: [Errno -2] Name or service not known
[DEBUG:2021-06-12 23:41:53,306] rhasspyserver_hermes: Connecting to http://“HA ip address”:1883 (retries: 2/10)
[ERROR:2021-06-12 23:41:52,303] rhasspyserver_hermes: mqtt connect
Traceback (most recent call last):
  File "/usr/lib/rhasspy/rhasspy-server-hermes/rhasspyserver_hermes/__init__.py", line 289, in start
    self.client.connect(self.host, self.port)
  File "/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/paho/mqtt/client.py", line 937, in connect
    return self.reconnect()
  File "/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/paho/mqtt/client.py", line 1071, in reconnect
    sock = self._create_socket_connection()
  File "/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/paho/mqtt/client.py", line 3522, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python3.7/socket.py", line 707, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
[DEBUG:2021-06-12 23:41:52,301] rhasspyserver_hermes: Connecting to http://“HA ip address”:1883 (retries: 1/10)
[ERROR:2021-06-12 23:41:51,298] rhasspyserver_hermes: mqtt connect
Traceback (most recent call last):
  File "/usr/lib/rhasspy/rhasspy-server-hermes/rhasspyserver_hermes/__init__.py", line 289, in start
    self.client.connect(self.host, self.port)
  File "/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/paho/mqtt/client.py", line 937, in connect
    return self.reconnect()
  File "/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/paho/mqtt/client.py", line 1071, in reconnect
    sock = self._create_socket_connection()
  File "/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/paho/mqtt/client.py", line 3522, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python3.7/socket.py", line 707, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
[DEBUG:2021-06-12 23:41:51,295] rhasspyserver_hermes: Connecting to http://“HA ip address”:1883 (retries: 0/10)
[DEBUG:2021-06-12 23:41:51,295] rhasspyserver_hermes: Starting core

I only have Rhasspy client at the moment that is outside of HA and Mosquitto broker. Oh I did a test using Mosquitto broker integration test kit. It is working well now. Should be able to work once able to connect from Rhasspy.

And I have found a way to prevent Rhasspy from crashing. I turn from internal MQTT to external MQTT just during any MQTT connection testing. Otherwise, I will set to internal MQTT for all my automation Configuration and testing.

So still left with this last leg of pain to fixed before I can declare I am up and running end to end.

Any other work around or alternative would be most welcome too.

The setting for MQTT must only be the IP address, not http://

Hey romkabouter,
You are the man. I finally manage to nailed this last leg thus I have completed my end to end testing thanks to you. Still a lot more to learn in terms of using Scene, Scripts and many other coding and configuration at HA. And have future plan to try out Node-Red too.

As of now, it is time to move on with more integration, automation of new devices at HA end.

And I will prepare to document a simple step by step guide of my entire build from hardware, software, security protocol, configuration and automation.

Hopefully when completed can benefit some newbies going down Rhasspy>Home Automation be it HA OS or HA container route instead of like me struggling for past 3 weeks to get it work end to end.

One last final request if not too much to ask.

I wanted to past back the scene or state(temperature reading and weather condition) of Event GetTemperature and GetWeather back to Rhasspy.

Can share a sample or guide on how to configure it at HA Event Action step and Rhasspy Sentences and Slots for me to model?

Last but now least many thanks for you time, effort and support. Greatly appreciated.

There is no better guide for sentences than the docs:
https://rhasspy.readthedocs.io/en/latest/training/#sentencesini

On that page are a lot of examples of sentences, slots and all that. Not all might be easy, but a lot of useful stuff

You are actually doing something like that already.

Remember the {{ and }} around the sessioID?
That is called a template, which can also be used for HA entities/

I have posted an example for turning lights on an off here:

In that example there are two slots, location and action.
You can check on how there are used as templates to call back on Rhasspy.
When called: Turn the kitchen light off (having kitchen and off defined as the slots)
It finds an entity by its location (light.kitchen) and calls the correct service (light.turn_off)

If you want to send a state from a sensor or something, you can use regular templates as used in Home Assistant.
Not only do you have access to the event:

But also on all Home Assistant entities:

A small example (only the payload part of the automation) for a sensor called kitchentemp:
Remember to always send the sessionId to end the session

  payload_template: >-
    {"sessionId": "{{trigger.event.data._intent.sessionId}}", "text": "It is currently {{ states('sensor.kitchentemp') }} degrees in the {{trigger.event.data.location}} " }

pay attention to all the single and double quotes :wink:
The result must be a valid json, something like:

{“key” : “value” , “anotherkey” : “second value” }

I highly suggest not to go the HA container route, but only to use the OS.

Many thanks for your sharing and guidance on this topic. Highly appreciated.

Yup, after playing with both, couldn’t agree more with you.

HA OS with Rhasspy add-on seems to be the way forward. Will write the guide for this build which is much straight forward and easy to follow and build for newbies.

No problem, good luck with the write-ups!