home-assistant / architecture

Repo to discuss Home Assistant architecture
320 stars 100 forks source link

Add support for integrations to define and place devices in areas #425

Closed cdheiser closed 3 years ago

cdheiser commented 4 years ago

Context

Systems like Lutron RadioRA2 and Homeworks have the concept of areas and assigning those devices to areas. It is incredibly tedious to copy/duplicate all that configuration in Home Assistant and then to keep it up to date if you're someone who's building out and modifying your system over time.

Proposal

https://github.com/home-assistant/core/pull/38945

Consequences

Integrations can add support to automatically import the areas and device assignments from their systems into Home Assistant.

balloob commented 4 years ago

I think that we should add a suggested_area to the device_info property. That way when we set up an integration, we can help the user place them.

It would also be useful for systems like Philips Hue where groups = areas.

michaelarnauts commented 4 years ago

I think that we should add a suggested_area to the device_info property. That way when we set up an integration, we can help the user place them.

It would also be useful for systems like Philips Hue where groups = areas.

Just for completion, there are also Hue groups dat aren't an area, but a group of lights (like 3 LEDs on the ceiling that are controlled as one).

eavanvalkenburg commented 4 years ago

Building on top of this, we could make it dynamic as well, rather than a one-time import, which would be a good first thing. But what if a component that get's moved around in it's app auto updates the area and then when calling a service on that area it auto applies to that as well.

In other words, moving a lamp from one room to another through the Hue app, the integration updates that lamps area in HA, an automation calling light.turn_off on the 'new' area also turns off that lamp, would make things extremely powerful. Devices that can detect where in the house they are would be even more powerful!

balloob commented 4 years ago

We should not complicate it by trying to support devices moving suggested areas. It's not a common occurrence.

chrisaljoudi commented 3 years ago

I think that we should add a suggested_area to the device_info property. That way when we set up an integration, we can help the user place them.

đź‘Ť this also has the advantage of an analogous metaphor to name/name_by_user (the user-interaction semantic where 'clearing' the name override restores the 'default name' seems like it would translate well to areas).

That said, though, given home-assistant/core#43804, it seems like clarifying exactly where "area matching" (based on name, presumably) happens in the flow is probably important.

Given that, it humbly seems to me that:

All-in-all, this makes it so that there's no additional API "surface area" for creating areas, but simply an added property to device_info and a helper method for matching in Area Registry.

Sorry for the verbosity, and also apologies if any of the above is missing something/not helpful. More than happy to hear thoughts/comments/corrections.

bdraco commented 3 years ago

I wasn't sure if the matching should be implemented on frontend side or core via an api:

On the UI side:

We should be able to match names by stripping white space, casefolding https://www.npmjs.com/package/casefold and then reorder the area selector in the UI based on the levenshtein distance using https://www.npmjs.com/package/fast-levenshtein if its a 0 distance we can just skip the form and select the area.

Or we could implement the matching in core:

Normalizing the area name in a similar name with casefold, https://pypi.org/project/pylev/, and stripping white space.

bdraco commented 3 years ago

https://github.com/home-assistant/developers.home-assistant/pull/815 has the updated docs