Which satellite?

I’ve set up two homeassistant-satellites. In each room with the satellite I have a Sonos speaker. I would like to set up a custom sentence to say “turn the volume up” and the Sonos speaker in the room with the satellite will increase in volume (but not any other Sonos speakers in the other rooms). To do this I need to know which satellite sent the request.

I had this previously working in Rhasspy using event trigger and looking at the value of trigger.event.data._intent.siteId. With the siteId, I could determine which room the request came from and then increase the volume of the Sonos speaker in that room.

I’ve created a custom sentence in sentences.yaml and and intent_script:

  Volume:
    data:
      - sentences:
          - "turn the volume {volume:direction}"
          - "turn {volume:direction} [the] volume"
          - "{volume:direction} [the] volume"
lists:
  volume:
    values:
      - up
      - down
      - in: increase
        out: up
      - in: decrease
        out: down

intent_script:
 Volume:
  action:
    service: script.volume_script
    data_template:
      direction: '{{ direction }}'

Is there a intent_script parameter like trigger in automations that contains which satellite sent the request? Is there another way to determine which satellite sent the request?

3 Likes

This is exactly what I am looking for at the moment as well. Without the ability to pull the satellite sending the request I can’t move past my current rhasspy set up. Ideally it would also be able to have responses sent to external cast speakers but for now would just like to be able to name and refer to the satellite even if it was just by ip address.

1 Like

This kind of feature would open a lot of possibilities. For instance, instead of saying “turn the lights on the living room / kitchen / wherever”, I would just say “turn the lights on” and assistant would know which lights to turn on, depending on the satellite that heard the command.

is this possible to configure?

This is also vital for my setup and transition from Rhasspy. I think HA knows where the request comes from since it will reply to the device that you spoke to but doesn’t seem we can yet have this in a variable (siteid) in order to do what we want with. I’m sure it’s coming though.

I’m pretty confident this will be supported natively soon.
Meanwhile, it can be done manually with a bit of effort:

  • First, for each satellite you need to have an “assist in progress” binary sensor which shows wether the satellite has detected a wakeword and is processing audio. Esphome satellites have this automatically, while for homeassistant-satellite it can done with a template sensor.

  • Then you need to process the intent with an intent_script. In the script you can check the sensors to figure out which satellite is in progress. HA prevents satellites from firing simultaneously so there should be exactly one active.

I have seen this done with the esp satellite (the logic behind it is no different to many of the other implementations through rhasspy), however how would you go about doing this with the non esp and where you would get the information for the sensor to indicate it was in progress? Is there some element that is tracked somehow that can be templated into a sensor?

The code used by celodnb for the esp

# Choose media player
  - platform: template
    sensors:
      choose_speaker_cmd:
        friendly_name: "Choose Notification Speaker based on Command"
        value_template: >-
          {% if is_state('binary_sensor.living_room_sensor_assist_in_progress', 'on') %}
            media_player.living_room_speaker
          {% elif is_state('binary_sensor.bedroom_sensor_assist_in_progress', 'on') %}
            media_player.bedroom_speaker
          {% else %}
            off
          {% endif %}

But not sure where to even look for the non esp.

You need the latest version (master branch) of homeassistant-satellite cause this functionality was merged just a few days ago.

homeassistant-satellite fires a homeassistant_satellite_event on each state change (use the events tab in the developer tools to verify this). Tou can use that in a trigger-based sensor as follows:

template:
- binary_sensor:
    name: Satellite assist in progress
    state: '{{ trigger.event.data.pipeline_event.type != "run-end" }}'
  trigger:
    platform: event
    event_type: homeassistant_satellite_event
    event_data:
      satellite_name: <hostname>

<hostname> is the hostname of the machine running the satellite, useful to distinguish events from different satellites (check the event in the developer tools if you’re not sure what the hostname is). If you have a single satellite you can remove the event_data part altogether.

1 Like

Will do a rebuild of the satellite this afternoon. Thanks!

Thanks for the help @chatziko I was able to create a trigger sensor template that contains the name of satellite when the intent_script is running:

template:
  - trigger:
      - platform: event
        event_type: homeassistant_satellite_event
    sensor:
      name: Assist Satellite Name
      state: >-
        {% if trigger.event.data.pipeline_event.type == 'run-end' %}
        {% else %}
        {{ trigger.event.data.satellite_name }}
        {% endif %}

in the intent_script I set a variable to its value:

    - variables:
        site_id: "{{ states('sensor.assist_satellite_name') }}"
1 Like

Thanks both of you. I have now been able to create a solution that now ties my old mqtt rhasspy integration with the new one.

Hi. I’m running the latest version of homeassistant-satellite on two devices. They are working well, but when I use dev tools to listen, home assistant never registers ‘homeassistant_satellite_event’. I only see state_changed events. The logbook just records “turned on triggered by service Home Assistant Core Integration: Generic turn on”. Any idea how to troubleshoot in order to differentiate between the satellites? Thanks

Are you using a user with admin rights in homeassistant-satellite? Someone on github wasn’t getting the events because of that.

Other than that, start with --debug and check the logs, see also the discusion here.

Thanks for the reply. I’m running it in docker with a user that has admin rights. I’ve pasted my debug log for one interaction. It doesn’t seem to be firing a homeassistant_satellite_event

DEBUG:homeassistant_satellite.remote:{'type': 'auth_required', 'ha_version': '2023.11.1'}
DEBUG:homeassistant_satellite.remote:{'type': 'auth_ok', 'ha_version': '2023.11.1'}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'result', 'success': True, 'result': None}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'run-start', 'data': {'pipeline': '01gzrz8vsw3wyy95p28f2hnvc8', 'language': 'en', 'runner_data': {'stt_binary_handler_id': 1, 'timeout': 300}}, 'timestamp': '2023-11-18T21:22:56.972745+00:00'}}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'wake_word-start', 'data': {'entity_id': 'wake_word.openwakeword', 'metadata': {'format': 'wav', 'codec': 'pcm', 'bit_rate': 16, 'sample_rate': 16000, 'channel': 1}, 'timeout': 3}, 'timestamp': '2023-11-18T21:22:56.972946+00:00'}}
DEBUG:__main__:wake_word-start {'entity_id': 'wake_word.openwakeword', 'metadata': {'format': 'wav', 'codec': 'pcm', 'bit_rate': 16, 'sample_rate': 16000, 'channel': 1}, 'timeout': 3}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'wake_word-end', 'data': {'wake_word_output': {'wake_word_id': 'hey_jarvis_v0.1', 'timestamp': 1730}}, 'timestamp': '2023-11-18T21:23:00.559295+00:00'}}
DEBUG:__main__:wake_word-end {'wake_word_output': {'wake_word_id': 'hey_jarvis_v0.1', 'timestamp': 1730}}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'stt-start', 'data': {'engine': 'stt.faster_whisper', 'metadata': {'language': 'en', 'format': 'wav', 'codec': 'pcm', 'bit_rate': 16, 'sample_rate': 16000, 'channel': 1}}, 'timestamp': '2023-11-18T21:23:00.559487+00:00'}}
DEBUG:__main__:stt-start {'engine': 'stt.faster_whisper', 'metadata': {'language': 'en', 'format': 'wav', 'codec': 'pcm', 'bit_rate': 16, 'sample_rate': 16000, 'channel': 1}}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'stt-vad-start', 'data': {'timestamp': 2070}, 'timestamp': '2023-11-18T21:23:01.183192+00:00'}}
DEBUG:__main__:stt-vad-start {'timestamp': 2070}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'stt-vad-end', 'data': {'timestamp': 2710}, 'timestamp': '2023-11-18T21:23:02.434039+00:00'}}
DEBUG:__main__:stt-vad-end {'timestamp': 2710}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'stt-end', 'data': {'stt_output': {'text': ' turn on the playroom light.'}}, 'timestamp': '2023-11-18T21:23:03.382609+00:00'}}
DEBUG:__main__:stt-end {'stt_output': {'text': ' turn on the playroom light.'}}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'intent-start', 'data': {'engine': 'homeassistant', 'language': 'en', 'intent_input': ' turn on the playroom light.', 'conversation_id': None, 'device_id': None}, 'timestamp': '2023-11-18T21:23:03.382647+00:00'}}
DEBUG:__main__:intent-start {'engine': 'homeassistant', 'language': 'en', 'intent_input': ' turn on the playroom light.', 'conversation_id': None, 'device_id': None}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'intent-end', 'data': {'intent_output': {'response': {'speech': {'plain': {'speech': 'Turned on light', 'extra_data': None}}, 'card': {}, 'language': 'en', 'response_type': 'action_done', 'data': {'targets': [], 'success': [{'name': 'Playroom', 'type': 'entity', 'id': 'light.playroom'}], 'failed': []}}, 'conversation_id': None}}, 'timestamp': '2023-11-18T21:23:03.483810+00:00'}}
DEBUG:__main__:intent-end {'intent_output': {'response': {'speech': {'plain': {'speech': 'Turned on light', 'extra_data': None}}, 'card': {}, 'language': 'en', 'response_type': 'action_done', 'data': {'targets': [], 'success': [{'name': 'Playroom', 'type': 'entity', 'id': 'light.playroom'}], 'failed': []}}, 'conversation_id': None}}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'tts-start', 'data': {'engine': 'tts.piper', 'language': 'en_US', 'voice': 'en_US-lessac-medium', 'tts_input': 'Turned on light'}, 'timestamp': '2023-11-18T21:23:03.483937+00:00'}}
DEBUG:__main__:tts-start {'engine': 'tts.piper', 'language': 'en_US', 'voice': 'en_US-lessac-medium', 'tts_input': 'Turned on light'}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'tts-end', 'data': {'tts_output': {'media_id': 'media-source://tts/tts.piper?message=Turned+on+light&language=en_US&voice=en_US-lessac-medium', 'url': '/api/tts_proxy/..._en-us_1508b67cfb_tts.piper.wav', 'mime_type': 'audio/x-wav'}}, 'timestamp': '2023-11-18T21:23:03.484494+00:00'}}
DEBUG:__main__:tts-end {'tts_output': {'media_id': 'media-source://tts/tts.piper?message=Turned+on+light&language=en_US&voice=en_US-lessac-medium', 'url': '/api/tts_proxy/..._en-us_1508b67cfb_tts.piper.wav', 'mime_type': 'audio/x-wav'}}
DEBUG:homeassistant_satellite.remote:{'id': 1, 'type': 'event', 'event': {'type': 'run-end', 'data': None, 'timestamp': '2023-11-18T21:23:03.484548+00:00'}}
DEBUG:__main__:run-end None
DEBUG:homeassistant_satellite.remote:Pipeline finished
DEBUG:root:play: ['ffmpeg', '-i', 'https://.../api/tts_proxy/..._en-us_1508b67cfb_tts.piper.wav', '-f', 'wav', '-ar', '22050', '-ac', '1', '-filter:a', 'volume=1.0', '-']
Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono

The docker image mentioned in the README is a bit behind unfortunately, this is likely the issue. You can easily build a new one though, grab the latest master from git and run

docker build . -t homeassistant_satellite

Then use the homeassistant_satellite image.

1 Like