Tutorial is great...beginner help with final node-red HA service call

I’m very very new and Rhasspy is my #1 goal for home assistant. The documentation is really excellent and I’ve so far got everything up and running, but I think I’m missing something because I can’t find any useful beginner guides for Node-Red and home assistant (they are just the basics), and that’s the one part that’s left to the user in the Rhasspy docs.

I’ve got my node-red websocket hooked up to a change node used as the intent filter, then to a template node so I can use the mustache template in my ‘service’ and ‘entity_id’ field in the home assistant call serivce node. All my sentences are using home assistant friendly names.

Here is the flow:

[{"id":"70d90eed.9fc7e8","type":"tab","label":"Rhasspy Intent","disabled":false,"info":""},{"id":"d7f94fdd.9b5028","type":"debug","z":"70d90eed.9fc7e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":990,"y":400,"wires":[]},{"id":"d60f2a3e.ec485","type":"websocket in","z":"70d90eed.9fc7e8","name":"","server":"","client":"be111083.116b5","x":200,"y":60,"wires":[["6433981b0ab46587"]]},{"id":"2ae634bbc9757d19","type":"template","z":"70d90eed.9fc7e8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"data\":{\"service\":\"turn_{{slots.state}}\",\"entity_id\":\"{{slots.name}}\"}}\n","output":"json","x":630,"y":280,"wires":[["d7f94fdd.9b5028","4cab6bd1c6caefbd"]]},{"id":"6433981b0ab46587","type":"switch","z":"70d90eed.9fc7e8","name":"intent filter","property":"intent.name","propertyType":"msg","rules":[{"t":"eq","v":"GetTime","vt":"str"},{"t":"eq","v":"ChangeLightState","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":520,"y":100,"wires":[[],["d7f94fdd.9b5028","2ae634bbc9757d19"]]},{"id":"4cab6bd1c6caefbd","type":"api-call-service","z":"70d90eed.9fc7e8","name":"","server":"5a1263d8.ffec3c","version":3,"debugenabled":false,"service_domain":"light","service":"{{payload.data.service}}","entityId":"{{payload.data.entity_id}}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1200,"y":220,"wires":[[]]},{"id":"be111083.116b5","type":"websocket-client","path":"ws://localhost:12101/api/events/intent","tls":"","wholemsg":"true"},{"id":"5a1263d8.ffec3c","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

What keeps happening is everytime Rhasspy detects an intent and sends it along, the call service node loses a connection to the server. Havn’t experienced this with any of my other node red, non-rhasspy, flows, although they are all straight service calls, without any mustache template attempts.

Thanks for any help. Any useful links to really learn node-red for home assistant and rhasspy? Or do I need to just keep reading all the forum topics and experiment?

That is because it is a Node-Red and Home Assistant thing, not a Rhasspy.
Just like there is not much documentation on how to use the events/intents in Home Assistant.
There are examples in the forum however, so that might help.

With regards to you error, I can’t tell what is going on because I do not use Node-Red. Is that required for you setup?
Otherwise I suggest to use events, they can be easily used in automations in Home Assistant. If you check some of my posts, you will find some examples.

1 Like

Thanks for the reply! I didn’t mean to be critical at all. It totally makes sense why that’s left to the user/other docs! I think all the good ‘not-just-starting-beginner’ but not yet ‘advanced-user’ Node-red/HA content is probably difficult to locate with search.

Node red is not required I don’t think, especially with some of the advances with HA templates and such. I think my home assistant knowledge is probably limiting me, so maybe it’s a good idea to familiarize myself with it more thoroughly.

Normally if I can get one (in this case) Rhasspy>Node-Red>HA command it becomes easier and fun to dissect and experiment as the learning process. It’s when you get stuck that you start to feel like everything you’re reading is not contributing at all your understanding :slight_smile:

I’ll start with events by reading your posts! Thanks a lot! This is an awesome project and everyone who contributes in any way should be proud! Thanks again!

Hmm, I can’t seem to get HA to recognize an event. I set up Rhasspy according to the docs and your posts here. Tried my internal IP and “http://supervisor/core/api” as the url, as I’m using the Hassio addon.

In developer tools I started listening to “rhasspy_ChangeLightState”, but can’t get anything to show up.

I tried through the Rhasspy settings and also editing my profile directly. Where can I find the long lived access token created by the addon? It looks like in the above post what got it working was putting that token in the profile. I can’t find if anywhere. Should I create a new one even though I’m using the addon?

EDIT: I’m having some trouble. I can’t get any intents to be recognized either. Have put:

[HassTurnOn]
turn on the (porch light){name}

in sentences and added “intent:” to my ha configuration.yaml. I have a light with the entity_id of “light.porch” and friendly name of Porch Light. Is it these names I’m screwing up? We certainly don’t want Rhasspy to include the ‘light.porch’ as it won’t recognize that. Do frienly names work or are the entity_ids referenced in the docs meaning the entity_id after the “light.” part?

Sorry: my problem was with entity_ids. I used a substation in my sentences and am starting to make some progress. Sorry again, I normally don’t post until I’m sure I’ve read all the docs thoroughly. Still not sure why events are not being recognized, but I’m making progress with intents and separately Node-Red.

I know, no problem. Me neither :wink:

I am working on an beginners tutorial though, but I currently do not have much spare time.

I can very much relate to that :smiley:

romkabouter, one last question for this thread for now:

If I have manually changed the url for the Home Assistant Intent Handling (and am not seeing an access token listed in the web UI settings page), do I need to generate and provide a new access token? In other words, Rhasspy is not looking somewhere else for that token…if the field is blank in the settings page, then Rhasspy needs to get a token from the profile? Is this correct?

I was wrong about being wrong and intents working :). I can’t seem to get any interaction with Home Assistant and am pretty sure getting the url and access token correct is the first place to start. Thanks

Yes, except if you have Rhasspy installed as Addon. Then the token should be taken over.
A long while ago that did not work for me so I generated a new long live token in HA and used it in the settings. I have http://<homeassistant ipadress>:8123 in url and the long lived token in Access Token.

But like I said, if you use the Addon, it should work with the default values (no token and I believe the url look like http://homassitant/hassio or something. I can’t remember

If you do not get any events or intents, that might be the problem try it like I did :slight_smile:

What do have on Home Assistant part to get this working? I see in the other topic you use events right? Then you should create some automation with those events as a trigger

Thanks again romkabouter. I got it working with a token I created and pointing at my internal url. Even though I am running the addon, I’m happy it’s working and am not going to try to change it now that it is.

I have gotten an automation to trigger a recognized Rhasspy event!!! Woo hoo!! I also got Node-Red to work and have routed intents to service calls that work!!

Currently I have two issues: one is I don’t have any speakers or audio output available on the RPI4 that runs hassos and rhasspy. Not sure yet if using HA events I’ll be able to get TTS and audio output from rhasspy to my MPD players around the house that do have speakers. Not sure how to do this in Node Red either, but I have created an endpoint and received the wav data…just got to get it out to the MPD servers.

The other is my entity id names are a mess and I’m unsure right now how to tackle this without having one line per entity in sentences.ini with substitution. In fact, I’m still not clear how anyone handles even if pulling them from HA (entities have no spaces and rhasspy doesn’t like that), so I obviously need to keep reading.

So based on how I progress with those two in the next week will probably push me toward choosing direct events or node-red.

1 Like

Where is your mike? When you mention this, I assume that Pi4 is somewhere in a closet :smiley:
TTS with events is easy. I don’t know how you implemented your automation, but you should alsways add this:

  - 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 }}"}'

It is technically not needed, but if you handle and intent from Rhasspy, it is good practice to end the session by sending a payload to endSession.
The TEXT part is not needed, but that is the TTS Rhassy will generate.
Since it is an automation, you can call any number of services or do other things.
Therefore you can expand your automation by calling the TTS in Home Assistant and play that on your MPD entity

1 Like

Some help here (execpt for the issues:

Basically you can use this script to pull entitites from HA

For entitiies, I use templates.

This is my automation for turning lights on and off:

- id: '1581372525473'
  alias: EventLights
  trigger:
  - event_data: {}
    event_type: rhasspy_Lights
    platform: event
  condition: []
  action:
  - data_template:
      entity_id: light.{{ trigger.event.data.location }}
    service_template: light.turn_{{ trigger.event.data.action }}
  - service: mqtt.publish
    data:
      topic: hermes/dialogueManager/endSession
      payload_template: '{"sessionId": "{{trigger.event.data._intent.sessionId}}",
        "text": "Ok, {{ trigger.event.data.location }} {{ trigger.event.data.action}}"}'
  mode: single

location is the name and action is the on or off

I actually, in hindsight, made the mistake of going from Ubuntu OS with docker HA core, to full hassos install. I thought the benefit of the addon store, but it turns out I can’t get mopidy to work since the addon is incompatible with the RPI4, so I’ve got another RPI3 in the same room doing the mopidy/snapcast server and that has the speaker output.

Did you ever have success with Rhasspy TTS output to snapcast? My whole setup is open to change, and ideally I’d have the RPI4 as Home Assistant plus my main snapserver. If I had that up and running I could pipe all ALSA output to snapcast.

It looks like the script provides a list of friendly names? Can those be used in my sentences.ini and events will trigger? For example, if I have an entity named “light.living.room.1” with a friendly name of “Living Room Window Light”, the spoken voice command would be “Turn on the living room 1” or “Turn on the Living Room Window Light”? Is this correct?

Thanks again, every post makes things a little clearer. I need to get a better testing setup because home assistant is already so useful to me I experiment only if I have a solid block of hours to ensure I can fix things…and nothing replaces experimenting in order to learn.

That should be correct, but I always name light like “Living Room Window” (without the Light, because I already know it is a light). But that is personal preference.

I could indeed output TTS to snapcast, but that config got lost along the way. I will se if I can dig it up again :slight_smile:

Don’t spend too much time searching on accout of me. I’ve spent a lot of time with snapcast and have think I have a handle on what to try (wait til I get stuck and I’ll be back here singing a different tune :wink: ) It might be worthwhile to put one or two examples of entity naming schemes some of our advanced users use in the beginners tutorial. I think that would be a big help. Thanks for sharing some of yours and I know others are here on the forum.

I hooked up a set of speakers to start testing! It’s working, but I’m not getting the endSession feedback. In dev tools, I’m not getting any output when I publish to hermes/tts/say or hermes/dialogueManager/endSession (payload: {“text”: “This is working!”}) I am hearing the voice prompt and intent success/failure tones and I get TTS when I enter it in the Rhasspy UI. The MQTT broker is set to internal. I probably need MQTT Explorer and time to understand MQTT better to start diagnosing this?

I do have a the mosquitto broker addon running mainly for my tasmota devices. How do I connect to the Rhasspy server? I’ve used port 12183 and tried my HA user name and password, but no go.

The endSession needs a sessionId and a siteId. Although the siteId is not required, since it is know in the session.
When you publish to hermes/tts/say, a siteId is required.

If you use Home Assistant, set Rhasspy to external and connect to the same broker as Home Assistant.
They both need to be connected to the same broker, I am using the MQTT addon.

You can connect Rhasspy to the addon by using the IP adress of the HA instance and 1883 as port.
Set username and password to a user in Home Assistant.

Awesome, Thanks @romkabouter! I’ll give it a shot!

EDIT: I have it working for the most part now. Gonna leave all of this in case it helps someone else struggling.

I’ve connected! I can see hermes in MQTT Explorer when I connect to the mosquitto addon. I currently have 4000, what look like wav data, messages and it keeps climbing! Is this normal? If so, what is all this data…Imma try to see if I can get node red to play them, although that already sounds tricky :slight_smile: .

Still not getting any TTS back. Here is my automation:

id: '1634702455575'
alias: Rhasspy Test
description: ''
trigger:
  - platform: event
    event_type: rhasspy_ChangeLightState
    event_data: {}
condition: []
action:
  - data_template:
      entity_id: light.{{ trigger.event.data.name }}
    service_template: light.turn_{{ trigger.event.data.state }}
  - service: mqtt.publish
    data:
      topic: hermes/dialogueManager/endSession
      payload_template:
        sessionId: '{{trigger.event.data._intent.sessionId}}'
        text: Ok, {{ trigger.event.data.location }} {{ trigger.event.data.action}}
mode: single

Here is what is getting MQTT Explorere has for the ‘hermes/dialogueManager/endSession sessionEnded’ topic:

{"termination": {"reason": "timeout"}, "sessionId": "default-blueberry_raspberry-pi-920a01ec-7e2e-47ad-a81c-d0810574c1ed", "siteId": "default", "customData": "blueberry_raspberry-pi"}

Looks like my automation is incorrect since it’s timing out? And that wav data’s topic is ‘hermes/audioServer/default/audioFrame’. It’s up to 16000 messages now.

EDIT: Fixed my payload_template, but still timing out:

      payload_template: '{"sessionId": "{{trigger.event.data._intent.sessionId}}",
        "text": "Ok, {{ trigger.event.data.location }} {{ trigger.event.data.action}}"}'

Using Dev Tools to publish to mqtt works for straight tts:

service: mqtt.publish
data:
  topic: hermes/tts/say
  payload: '{"text": "This is great"}'

EDIT2: Okay, so it seems like my Event that is sent to HA does not include the ‘Key’ fields that yours does. I have no ‘data.location’ or ‘data.action’. My automation was erroring and not getting to the mqtt.publish action. I’ve changed them to ‘trigger.event.data.name’ and ‘trigger.event.data._raw_text’ and now the topic is posted via MQTT, but still nothing.

FYI for the new guys: The session doesn’t seem to be started if you use the Rhasspy UI even with the ‘Handle’ box checked. When I used my physically spoke the command, it all finally worked and I got TTS feedback!!! Also, the 20k topics are zero samples I believe.

So, does my missing data.location and data.action have to do with the structure of my sentences.ini and slots, etc.? That’s what I’m guessing and if so it’s time to tackle that! Hope this post helps someone and can’t thank @romkabouter enough!!

Final edit for tonight: Yes, location is definitely a ‘tag’ and or a ‘domain’ I believe and does not seem to be a default one. Not sure yet the difference. But it does need to be added to the sentences.ini structure. Not sure about action, but I’ll be back!

Yes, that is the Audio data coming from your mike. Every 512 bytes as a small wave file.
Trying to play is it useless, although you can recorder if you adjust this script a bit

Yeah, location and action are slots in my sentences, you should adjust them to what you are using.
I cannot seem to find what your sentences look like. If you post them, I will be able to give the correct values :slight_smile:

Here is a part of mine:

[Lights]
\[zet] [de] [het] ($lampen){location} ($acties){action}

The $lampen and $acties are slots in Rhasspy, like so:

Nevermind the Dutch words, you get the idea :wink: