Issues with HA built-in intents [HassTurnOff]

Yes, running as add-on. Sorry should have mentioned that.

Set-Up:
Server: Win10 running VM with hass.io 5.9. and Rhasspy 2.5.8.1 add-in & deCONZ

Satellite: RasPi 4 with Raspian Buster Lite and Rhasspy 2.5.8.1

Ok, can you set the Hass URL to the default?

I am not that familiar with intents because I use event, maybe the name is really the name and not the enitity id or with underscores instead of spaces.

I suggest to change you living room lamp to livingroom and also your sentences.ini to
turn on the livingroom{name}

Hey thanks again for helping, really appreciated.

I messed around again, but to no avail.

Renamed the entity to “livingroom” in HA.

Changed sentence.ini to:

[HassTurnOff]
turn off the (living room lamp):livingroom {name}

Changed profile.json to default, i.e.:

    "url": "http://hassio/homeassistant"

Added to configuration.yaml:

 http:
   base_url: localip.of.ha.server:8123

Just tried the same set-up but with the entity_ID instead of “name”, no change.

After reading this:

Maybe both intent and intent_script are needed.

It is not working for me either.

I suggest not using the built-in intents, but create your own as per:

I am using event by the way, which trigger automations. For me that is more natural and better to debug :slight_smile:

Yeah, I’ll take a look at that. Built-In sounded like the easy solution, but seems not to be the case. Thanks for all the suggestions.

And if you want speech feedback, I recommend using events and creating a light from your switch
Put this in your configuration.yaml:

light:
  - platform: switch
    name: Living room
    entity_id: switch. on_off_plug_in_unit_3
    
rest_command:
  rhasspy_speak:
    url: 'http://192.168.1.34:12101/api/text-to-speech?siteId={{ siteid }}'
    method: 'POST'
    payload: '{{ payload }}' 
    content_type: text/plain

And this in automations.yaml (you might be able to do that in the frontend):

- id: '1581372525473'
  alias: EventLights
  trigger:
  - event_data: {}
    event_type: rhasspy_Lights
    platform: event
  condition: []
  action:
  - data_template:
      siteid: '{{trigger.event.data._intent.siteId}}'
      payload: OK, {{ trigger.event.data.location }} {{trigger.event.data.action}}
    service: rest_command.rhasspy_speak
  - data_template:
      entity_id: light.{{ trigger.event.data.location }}
    service_template: light.turn_{{ trigger.event.data.action }}
  mode: single

Change your sentences.ini to this:
[Lights]
turn ($actions){action} the ($locations){location} lamp

Create slot for actions (name it actions, like before the $ in your sentences):

on
off

And for locations (name it locations):

livingroom

Restart HA en set Rhasspy to sending events.

2 Likes

Great idea. I’ll have to take some more time and understand more about scripting, intents etc.

I am using the above code exactly like that, you will probably find more “rhasspy_speak” rest command on this forum (copy pasted from me), but I have changed the url and added siteId
This is because when you have a satellite, the speech response also needs to go there.
When you omit the siteId, it will output the audio on your server :slight_smile:

Good luck and I will help if you need any

Question to this part of your code in the previous post: Is ‘url’ supposed to point to the satellite’s IP? Or the server’s IP? (In my concrete case .34 is the server)
I didn’t try it yet, hope to do so during this week.

ServerIP, because that is handling the responses :slight_smile:

Didn’t have time to work on this the last 2 weeks, but finally managed now. Triggerin HA automations by firing events works fine.

To your code I have some very, very basic questions to your post. I’ll descibe in layman terms, if I got it correctly:

Do I understand correctly that with the code you posted 2 things shuold be are achieved:
The light is actually switched and Rhasspy returns a spoken feedback, e.g. “OK, livingroom off”?

What I believe the code is doing:
By saying “turn on the livingroom lamp” the event “Lights” is triggered and sent to HA. HA then responds and sends the repsonse back to the rhasspy siteID the trigger came from, in this example ‘satellite’. This is done ist the 1st data_template section.
The 2nd data_template section toggles the switch.

If addtional lights should be integrated, the additiional entity names have to added at the bottem of this code section which then would look lile e.g.

light:
- platform: switch
name: Living room
entity_id: switch. on_off_plug_in_unit_3
entity_id: switch. on_off_plug_in_unit_2

and in sentence.ini and automations.yaml the respective event for that new entites would have to be defined addtionally. Because in your example, the event ‘rhasspy_Lights’ is explictiy for living room.

I know these questions are really basic. 'im just trying to understand if I need to define an individual event for every single possible state. I guess not because this would get very complex very fast, e.g. if “set lamp to brightness 60% and dark blue” were a single event.

Correct

Again correct :slight_smile:

You cannot add multiple entities with with light->switch. Only one entity:

If you want to be able to switch more lights, simply add them to the locations slot.
The data_template uses the light.{{ trigger.event.data.location }} to determine the correct light.

So, you now have livingroom. If you want to turn on a light in the kitchen, add “kitchen” to the locations slot and add a light with name “kitchen” to Home Assistant.

No, you can add brightness and color as a slot. Your sentence would be something like

[Lights]
turn ($actions){action} the ($locations){location} lamp
set $locations){location} to $colors{color} with brightness (0…100){brightness}

See documentation here:

You could also create two events, on for on/off and one for color/brightness.
If you want to use 1 event, you service_template would become more complicated than light.{{}}, because you will need to build depending on what sentence is provided.
My suggestion for that case to search on the the HA forum for service_templates.

No, the Lights event is for all lights you have in your locations slot which have a corresponding name in Home Assistant.
That is what templating does, it replaces the name.

This: light.{{ trigger.event.data.location }}
can become light.livingroom or light.kitchen or any other light entity.

Final feedback in this thread since this is way offtopic because of me already - thanks for pointing me in the right direction.
Voice command on/off of bulbs and plugs is fine via the events method.

I’ve tried to set up color chagning via a sepeate event, but only works for one entity I hardcode in HA. Somehow the location slot is not picked up by the HA event. I just don’t have the grasp of the HA automations work and heading over to HA forums.

The audio feedback isn’t working at the moment, but I havn’t taken a close look at the forum yet.

Can you post the automation? Otherwise it is a bit hard to find the error :wink:

Ok here goes. :smiley:

In this example I spoke to satellite (“sat”) to turn on an arc lamp. The arc lamp is a zigbee plug defined as light in HA and called “white_1”.

Switching the light works.

The audio feedback event in HA seems to fire fine in HA and feed info back to the server which processes the TTS.

[DEBUG:2021-01-24 10:19:45,272] rhasspyserver_hermes: -> TtsSay(text='OK, white_1 on', site_id='serv', lang=None, id='117ec17f-55e0-4b84-aad5-eac5e9ed4f60', session_id='', volume=1.0)
Full Server Log
[DEBUG:2021-01-24 10:19:45,459] rhasspyserver_hermes: Handling TtsSayFinished (topic=hermes/tts/sayFinished, id=de1f2e95-da1b-4907-ac60-86ec90a0a468)
[ERROR:2021-01-24 10:19:45,341] rhasspyserver_hermes: NotFound(404)
Traceback (most recent call last):
  File "/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/quart/app.py", line 1821, in full_dispatch_request
    result = await self.dispatch_request(request_context)
  File "/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/quart/app.py", line 1863, in dispatch_request
    raise request_.routing_exception
quart.exceptions.NotFound: NotFound(404)
[DEBUG:2021-01-24 10:19:45,317] rhasspyserver_hermes: Handling AudioPlayBytes (topic=hermes/audioServer/serv/playBytes/117ec17f-55e0-4b84-aad5-eac5e9ed4f60, id=de1f2e95-da1b-4907-ac60-86ec90a0a468)
[DEBUG:2021-01-24 10:19:45,272] rhasspyserver_hermes: Publishing 136 bytes(s) to hermes/tts/say
[DEBUG:2021-01-24 10:19:45,272] rhasspyserver_hermes: -> TtsSay(text='OK, white_1 on', site_id='serv', lang=None, id='117ec17f-55e0-4b84-aad5-eac5e9ed4f60', session_id='', volume=1.0)
[DEBUG:2021-01-24 10:19:45,265] rhasspyserver_hermes: Sent 752 char(s) to websocket
[DEBUG:2021-01-24 10:19:45,254] rhasspyserver_hermes: Handling NluIntent (topic=hermes/intent/Lights, id=7ddf37a8-9c84-4c90-8ac1-073adad75647)
[DEBUG:2021-01-24 10:19:45,245] rhasspyserver_hermes: <- NluIntent(input='switch on white_1', intent=Intent(intent_name='Lights', confidence_score=1.0), site_id='serv', id='41c651c9-c550-4a5a-afce-0c6ba36c5c6e', slots=[Slot(entity='actions', value={'kind': 'Unknown', 'value': 'on'}, slot_name='action', raw_value='on', confidence=1.0, range=SlotRange(start=7, end=9, raw_start=7, raw_end=9)), Slot(entity='locations', value={'kind': 'Unknown', 'value': 'white_1'}, slot_name='location', raw_value='arc lamp', confidence=1.0, range=SlotRange(start=10, end=17, raw_start=10, raw_end=18))], session_id='41c651c9-c550-4a5a-afce-0c6ba36c5c6e', custom_data=None, asr_tokens=[[AsrToken(value='switch', confidence=1.0, range_start=0, range_end=6, time=None), AsrToken(value='on', confidence=1.0, range_start=7, range_end=9, time=None), AsrToken(value='white_1', confidence=1.0, range_start=10, range_end=17, time=None)]], asr_confidence=None, raw_input='switch on arc lamp', wakeword_id=None, lang=None)
[DEBUG:2021-01-24 10:19:45,227] rhasspyserver_hermes: Publishing 204 bytes(s) to hermes/nlu/query
[DEBUG:2021-01-24 10:19:45,226] rhasspyserver_hermes: -> NluQuery(input='switch on arc lamp', site_id='serv', id='41c651c9-c550-4a5a-afce-0c6ba36c5c6e', intent_filter=None, session_id='41c651c9-c550-4a5a-afce-0c6ba36c5c6e', wakeword_id=None, lang=None)
[DEBUG:2021-01-24 10:19:44,302] rhasspyserver_hermes: Handling AsrTextCaptured (topic=hermes/asr/textCaptured, id=5a96629f-a13d-441e-9971-f122cb7ae8e3)
[DEBUG:2021-01-24 10:19:43,875] rhasspyserver_hermes: Publishing 71 bytes(s) to hermes/asr/stopListening
[DEBUG:2021-01-24 10:19:43,875] rhasspyserver_hermes: -> AsrStopListening(site_id='serv', session_id='2b688ffb-bda9-4574-b574-90f17ceaf082')
[DEBUG:2021-01-24 10:19:43,870] rhasspyserver_hermes: Sent 53108 byte(s) of WAV data
[DEBUG:2021-01-24 10:19:43,869] rhasspyserver_hermes: Publishing 178 bytes(s) to hermes/asr/startListening
[DEBUG:2021-01-24 10:19:43,868] rhasspyserver_hermes: -> AsrStartListening(site_id='serv', session_id='2b688ffb-bda9-4574-b574-90f17ceaf082', lang=None, stop_on_silence=False, send_audio_captured=True, wakeword_id=None, intent_filter=None)

Don’t really know what going on in sat1:

Satellite log
[ERROR:2021-01-24 10:19:45,428] rhasspyserver_hermes: 'utf-8' codec can't decode byte 0x80 in position 24: invalid start byte
Traceback (most recent call last):
  File "/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/quart/app.py", line 1821, in full_dispatch_request
    result = await self.dispatch_request(request_context)
  File "/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/quart/app.py", line 1869, in dispatch_request
    return await handler(**request_.view_args)
  File "/usr/lib/rhasspy/rhasspy-server-hermes/rhasspyserver_hermes/__main__.py", line 1129, in api_play_wav
    url_or_path = data.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 24: invalid start byte
[DEBUG:2021-01-24 10:19:45,314] rhasspyserver_hermes: Sent 825 char(s) to websocket
[DEBUG:2021-01-24 10:19:45,311] rhasspyserver_hermes: <- NluIntent(input='switch on arc lamp', intent=Intent(intent_name='Lights', confidence_score=1.0), site_id='sat1', id=None, slots=[Slot(entity='action', value={'kind': 'Unknown', 'value': 'on'}, slot_name='action', raw_value='on', confidence=1, range=SlotRange(start=7, end=9, raw_start=7, raw_end=9)), Slot(entity='location', value={'kind': 'Unknown', 'value': 'white_1'}, slot_name='location', raw_value='arc lamp', confidence=1, range=SlotRange(start=10, end=17, raw_start=10, raw_end=18))], session_id='sat1-porcupine_raspberry-pi-b9dfa2ae-a686-45f6-b8f8-88fc1fcf27e7', custom_data=None, asr_tokens=[[AsrToken(value='switch', confidence=1.0, range_start=0, range_end=6, time=None), AsrToken(value='on', confidence=1.0, range_start=7, range_end=9, time=None), AsrToken(value='arc', confidence=1.0, range_start=10, range_end=13, time=None), AsrToken(value='lamp', confidence=1.0, range_start=14, range_end=18, time=None)]], asr_confidence=None, raw_input='switch on arc lamp', wakeword_id='porcupine_raspberry-pi', lang=None)
[DEBUG:2021-01-24 10:19:40,981] rhasspyserver_hermes: <- HotwordDetected(model_id='/usr/lib/rhasspy/.venv/lib/python3.7/site-packages/pvporcupine/resources/keyword_files/raspberry-pi/porcupine_raspberry-pi.ppn', model_version='', model_type='personal', current_sensitivity=0.5, site_id='sat1', session_id=None, send_audio_captured=None, lang=None)

In this guy’s post, it was solved, but he seems to play the audio on the same Rhasspy instance where the TTS is produced. I didn’t test this solution on my set-up though.

My Rhasspy instances are configured as shown below, which is most likely wrong, but I didn’t understand the documentation.

sat1:

serv:

documenation

No, not your Rhasspy setup, but your automation form Home Assistant.
The one you created for this:

I’ve tried to set up color chagning via a sepeate event, but only works for one entity I hardcode in HA.

You mention audio feedback is not working and you have hardcoded the entity in HA.
So, assuming you use automations to react on those events, please post the automation you created in Home Asssistant

Why do you post the wav to an endpoint? (the audio play on the server)
That needs to be hermes, because you want to play the audio on the sat1 right?
And maybe more sats when this is done?

The hardcode bit was only about the 2 seperate events for turn on/off and changing color not working as expected first and using an ugly hardcode soltion. But now I sorted it out in the meantime. The automations for on/off an changing colors work with templates (on/off below).

- id: '1581372525473'
  alias: OnOffLight
  trigger:
  - event_data: {}
    event_type: rhasspy_Lights
    platform: event
  condition: []
  action:
  - data_template:
      siteid: '{{trigger.event.data._intent.siteId}}'
      payload: OK, {{ trigger.event.data.location }} {{trigger.event.data.action}}
    service: rest_command.rhasspy_speak
  - data_template:
      entity_id: light.{{  trigger.event.data.location  }}
    service_template: light.turn_{{  trigger.event.data.action  }}
  mode: single

I posted wav to the endpoint only for testing if it works at all in a single satellite set-up.
Of course you’re right it should be dynamic in case of several satellites. At the moment there is only sat1, where audio should be played.

Setting server to “MQTT: internal” and audio playing: Hermes MQTT and the satellite to MQTT: internal and audio playing: aplay didn’t solve it though.

The satellite’s name has to be entered in the server’s config, right?

Can you post this as well? From your configuration. Most probably it is missing the siteid