Modelling devices with sub-devices #1036
-
BackgroundIt's not uncommon for a single devices to contain multiple sub devices, one example is multi-gang smart light switches, where each channel in the switch as a We currently model such devices as a single device registry entry which has multiple entities. Examples of popular integrations which support such devices as a single device with multiple entities are:
There are some issues with this approach:
Example of a device with 4 relays and energy consumption sensors:Device name: Left 4CH Relay
Entities:
(Channels 2..4 are omitted for brevity) See alsoThe same problem as raised in this discussion was recently discussed in these rejected architecture discussions, both of which essentially suggest ways to implement proposal 2 in this discussion
ProposalTwo very different proposals are outlined below, with known pros and cons. Proposal 1Model devices with multiple sub devices as a main device which contains multiple sub devices linked to the container with From the documentation:
Pros:
Cons:
Example of a device with 4 relays and energy consumption sensors:Main device name: Left 4CH Relay
Entities:
Proposal 2Allow integrations to opt out of having entity id and friendly name attribute prefixed with device name Pros:
Cons:
Example of a device with 4 relays and energy consumption sensors:Main device name: Left 4CH Relay
Entities:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Upvote this comment to vote for proposal 1 |
Beta Was this translation helpful? Give feedback.
-
Upvote this comment to vote for proposal 2 |
Beta Was this translation helpful? Give feedback.
-
TL;DR: No big blocker reasoning found in historical information, Proposal 1 is accepted. I've been digging a bit into the history of this all. As far as I am aware, we've originally set out to add area support to entities to solve this problem. Devices that could operate in multiple areas, like a 2-channel/relay style wall-switch operating lights in different areas, would presumably be solved by allowing entities to be assigned to a different area from their parent device. Area ID support for entities was originally added to the codebase in: home-assistant/core#42221 Interesting is PR #42348, which unsplits devices because of the above-listed addition in #42221. Unfortunately, this doesn't add more context to the story. Searching through a stack of old meeting minutes, I've found this glimpse from a meeting in September 2020:
This indicates OZW (being implemented at the time) had a similar issue. The interesting part is, that it clearly states a device relation to areas (assumingly wall switches as well, considering the early implementation phase of OZW). But this remains guessing, as this is all the context I could find on it. Next, I found this little gem in our private GitHub org members channel on Discord by balloob:
This seems to be the root of the implementation. This was picked up by Robban, who created PR #42221. Scrolling in the chat, leads to a concept document of handling Lovelace dashboards/features different: Leveraging areas (e.g., using views or cards). This one is surprising, as that one indicates how Shelly is one of the drivers behind the area ID to entities change (just like Shelly is a driver behind this proposal as well).
The reasoning is thus two-fold. One is device-less entities, the other is devices providing entities that could be in different areas. This changes the perspective a little. First of all:
I think adding/making exceptions for entities for the areas they are in is still valuable and still holds. We can still have integrations providing just entities (most notably helpers). We do have tons of devices providing a lot more entities. That same light switch now provides configuration entities (like power-on behavior) and diagnostic entities (like power consumption and energy usage). Assigning each and single one of them to a different area is a pain for the end user. I haven't talked about naming yet... The recently added placeholder supports the above historical model, and IMHO still valuable (I've seen it deployed for other reasons too), so that addition was a win. We've discussed this extensively (Paulus, Erik, Martin, Robert and me), and we agree that Proposal 1 would be the path to take unless we found good reasons in our history not to do so. Conclusion on the above: The drive behind the history of adding areas to entity IDs is definitely related, but not exclusive to that use case alone. Things changed a lot, we have tons of entities and data points from our devices nowadays that made the original feature set out to solve this (adding areas to entities), not a full fit anymore. Meanwhile, we have improved our UI. We have links from parent devices to their child devices on the parent device page, for example, making them easier to find and navigate around. Let's do this. ../Frenck |
Beta Was this translation helpful? Give feedback.
-
Another example would be ecowitt weather Station. But I could Connect different Stations / Sensors to one hub - Here, it would make Sense to use "subdevices" in my opinion |
Beta Was this translation helpful? Give feedback.
TL;DR: No big blocker reasoning found in historical information, Proposal 1 is accepted.
I've been digging a bit into the history of this all. As far as I am aware, we've originally set out to add area support to entities to solve this problem.
Devices that could operate in multiple areas, like a 2-channel/relay style wall-switch operating lights in different areas, would presumably be solved by allowing entities to be assigned to a different area from their parent device.
Area ID support for entities was originally added to the codebase in: home-assistant/core#42221
Unfortunately, that PR provided no context or motivation behind the reasoning to do so, so I had to dig deeper.
Interesting…