home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.33k stars 650 forks source link

Assist area awareness support #4158

Closed larkery closed 4 months ago

larkery commented 9 months ago

Home Assistant Android app version(s): 2024.1.2-full Android version(s): 12 Device model(s): Samsung galaxy S10e Home Assistant version: 2024.1.2 Last working Home Assistant release (if known): NA Description of problem, include YAML if issue is related to notifications:

Assist should be aware of the area of a voice assistant. If I set the area of my android device within HASS, sentences that require this implicit area do not work (for example, 'turn on the lights'). This would be useful for me (and maybe others) as I have an android device stuck to a wall as a control interface, and I'd like to be able to say 'turn on the lights' to it and have that make sense.

I've traced this through in the hass codebase, and it appears that the websocket pipeline for voice assistant takes device_id in the websocket message when it starts off here: https://github.com/home-assistant/core/blob/1fa7ceede390df037fe9bdb1ba4f7939c9acc138/homeassistant/components/assist_pipeline/websocket_api.py#L144

If this is supplied then somewhere else (intent handling) the device ID is translated to area, which is then supplied in the context for interpreting the intent.

I raised this against hass core here https://github.com/home-assistant/core/issues/108839 and the understanding on that side is that it's the responsibility of the phone app to tell the API what it needs to know.

I'm happy to try and work on this if someone can give me a pointer. I'm guessing if the app's own device_id is lying around somewhere then it is a matter of poking it into here: https://github.com/home-assistant/android/blob/d9e65f8e5daf9bfb94808f545d29624af67f5ded/common/src/main/java/io/homeassistant/companion/android/common/data/websocket/impl/WebSocketRepositoryImpl.kt#L285 or somewhere nearby.

Companion App Logs: NA Screenshot or video of problem: NA Additional information: NA

larkery commented 9 months ago

p.s. thanks for all your hard work :)

jpelgrom commented 9 months ago

Thanks for the report! This is not really an app bug though, I've changed it to feature request. (Maybe an omission/room for improvement in the documentation?)

To be honest, area awareness like you're doing doesn't really fit the companion app's primary use case as they are intended to be mobile so constantly changing. Something magic like room tracking mentioned in the core issue would probably be a better fit but let's not go there yet :) Wall dashboards aren't uncommon however so as long as it doesn't harm other use cases I also don't think we should dismiss this.

I'm guessing if the app's own device_id is lying around somewhere

Unfortunately, it is not. This requires the device registry ID which isn't known to the app and somewhat hard to match due to type safety considerations.

larkery commented 9 months ago

Ah that is a shame, I was hoping for a quick fix.

This makes sense, since the device ID is something the server makes up for the client; it's why I raised it against hass core first. I don't know enough about what is being transmitted to know if the request to the server contains something that could be looked-up to device ID on that side.

Do you think there is a clean way for the app to find its device ID without implementation changes in core, or am I going to have to go back to them anyway if I want this implemented?