Make entities and devices independent in the scene editor#11046
Make entities and devices independent in the scene editor#11046balloob merged 9 commits intohome-assistant:devfrom
Conversation
It wasn't unclear, I just don't recognize this myself. But I think I've now learned what is happening. Apparently, most of my scenes use devices with a single entity. Wonder why I never ran into this myself before :S |
|
Another question: should entities (either individual or entities belonging to devices) that have |
|
That is a very good question, which I don't have the answer to myself, to be honest. Both cases sound interesting. As in, scenes can be used to restore the state of a device (e.g., a specific camera configuration when you are away for example, or child locks enabled when kids are home... those things). I think the most common use cases won't be needing the non-primary entities; but ruling them out sounds kinda odd as well 🤷 |
Good point. I think leaving them as is makes sense if we can solve the issue this RFC attempts to solve. Then the user can explicitly include or exclude them depending on what they want to achieve. |
|
@dmulcahey, @frenck let's leave out entities with |
|
Something like this would be super helpful for me. The main devices I have trouble with are WLED devices and my Inovelli Fan + Light Switches. |
dbbc0e8 to
bd3a546
Compare
src/data/scene.ts
Outdated
| [entityId: string]: string | { state: string; [key: string]: any }; | ||
| [entityId: string]: | ||
| | string | ||
| | { state: string; [key: string]: any; entity_only?: boolean | undefined }; |
There was a problem hiding this comment.
Should we tuck the entity_only flag away in a metadata object?
There was a problem hiding this comment.
Do we even need entity_only? If we allow this, we would just make it so that picking an entity in the entity list doesn't automatically upgrade to the device.
There was a problem hiding this comment.
So you pick a device for devices, you pick an entity for entities.
There was a problem hiding this comment.
The problem is that the scene config does not have a concept of devices which are included, frontend derives the included devices by looking up device ids for entities included in the scene.
It means we need some way for frontend to keep track of which devices should be included by storing additional data in the scene config. The entity_only is an opt-out flag; it would maybe be more logical to make it an opt-in flag instead?
There was a problem hiding this comment.
If it's for the frontend only, we generally use metadata.
There was a problem hiding this comment.
Fixed, the frontend settings are now moved to a seperata metadata item in the scene
|
I am not sure if we currently already do this, but selecting a device for a scene should only include entities that have no entity categories. |
We don't do that, and we should fix that too, in a separate PR |
3f022e7 to
cf15bf7
Compare
|
Erik has updated the backend to allow |
| entityMetaData | ||
| ? !entityMetaData.entity_only | ||
| : false |
There was a problem hiding this comment.
It took me a while staring at this code to figure out what it does. This seems to simplify it a bit.
| entityMetaData | |
| ? !entityMetaData.entity_only | |
| : false | |
| entityMetaData && | |
| !entityMetaData.entity_only |
There was a problem hiding this comment.
To not change the behavior in a surprising way, the logic should be reversed so we assume entities in scenes without metadata are added as devices.
| const entityMetaData = config.metadata?.[entityReg.entity_id]; | ||
| if ( | ||
| !this._devices.includes(entityReg.device_id) && | ||
| !(typeof entity === "string") && |
There was a problem hiding this comment.
| !(typeof entity === "string") && | |
| typeof entity !== "string" && |
There was a problem hiding this comment.
This was added when the entity_only flag was set in the entities map and is indeed no longer needed 👍
Co-authored-by: Zack Barett <zackbarett@hey.com>


Breaking change
Proposed change
The scene editor currently only works with devices. You can pick an entity but if it has an associated device the device is what is added to the scene. This "works" but falls down with devices such as multi-gang smart switches where the individual states for each gang should not be forced to be used together in a scene. It is very common for 1 gang to control the lighting for 1 room / area and another gang to control the lighting in another room / area.
This change adds a key
entity_onlyto the stored configuration inscenes.yamlso that it can be used by the editor as a hint when saving and loading the scene. This allows individual entities to be used in scenes regardless of whether or not they are associated to a device.I have done some light testing and this appears to work. It needs a typing issue corrected but I wanted to open this to get some feedback on the change before trying to finish it.
If this change is welcome it may also be worth discussing making the entity picker always available. I get the intention to make this as easy to use as possible but IMO it isn't intuitive to have this picker hidden behind advanced mode.
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: