I’m trying to fix an error, but don’t know the code module to look into.
Here’s the issue:
I have a many “Number” domain entities that have been labeled using the Labels feature to more clearly identify their function. For example, for Matter devices, I’ve labeled the “Off transition” delay Number entity with an “Off Transition Time” label. I’d like to be able to select all these entities by label in scripts automations, as shown below:
Seems simple enough, but it doesn’t work. When I click the “<>” on the Off transition Time label, it should expand to show all the correspondingly labeled Number entities. However, when I try to expand the label, I get nothing.
So, what seems to be happening is that the Labels simply aren’t picking up any of the Number domain entities. I don’t know if other domain types are affected (at least “Light” domain entities seem to be target-selectable by their labels, so this may be an isolated issue).
Since target selection by label works with Light domain entities and not with Number domain, my hope is that I can look at how the selection works for the Light domain entities and it may reveal something inadvertently left out in the corresponding code for Number domain entities…
Not an expert on the overall HA code base, but I’m usually pretty good at reviewing / fixing errors when I know where to start looking, but in this case, I don’t know where the proper code module is to begin my search. Anybody know where I should start checking? Even better - anybody more knowledgeable who wants to assist or is able to also recreate this issue and possibly help investigate a fix?
99% sure for at least 2 reasons: If I had selected the wrong service, I would not have seen the label that I was trying to target (for example, when I select the Set Number service, I don’t see labels for light. entities), and when I go to the Entities page and filter by Domain (checking Number) and Labels (checking “Off Transition Time”) I see the entities I’m trying to target.
But, now I realize there is a bigger issue. I was only trying to target by Label, but I went back and tried to target by area - same result - the “Area” target also gives no results even though I am sure the Area contains number entities. Here’s an example of an entity I was trying to target:
As you can see, it is both in the “Backyard” area and has the label “Off TransitionTime” and is a “number.” entity.
Turns out, I can only select it as a target via the “Chose Entity” option. None of the other target selection mechanisms (Choose area", “Choose device”, “Choose label”) will select it.
This particular entity was created with the Matter integration, but I’m noticing that entities created with the Z-wave integration also can’t be targeted in this manner.
This is where the service call extracts the entities from the target selector.
The expand function in the UI will likely call a webservice to get this info and may not be the same code so you should treat these as possibly different issues (or same issue in different code).
Dont have time to dig further atm for you but post here with progress if you want any pointers.
To add… i would investigate line 557
entity_entry.entity_category is None
Which basically doesnt add entites that have an entity category. Not sure what an entity category is and whybit doesnt add in that case. Do these have one? (likely you will need to look in the core.config_entities file at one of these entities).
What Integration created the number entity that you worked with / that worked for you? Was it created by either the Z-Wave or Matter Integration (which I have trouble with), or was it created by something else? Maybe this ties to the integration that created the entity.
Entity category is I think Diagnostic or Configuration, for entities of a device that are not considered it’s primary entities. They appear in separate lists in the device page.
@karwosts@msp1974
Good hints.
All the number entities that I was trying to target are in the Configuration category, so this might be it. I’ll try temporarily changing them from Configuration to “regular” entities and see if they are selectable. Probably get to this tomorrow and I’ll let you guys know what happens.
There’s definitely something going on with the Categories.
As an experiment, I changed the discovery schema in the “number.py” file in the Matter integration (core/homeassistant/components/matter at dev · home-assistant/core · GitHub) so that the relevant entities had their entity_category set to None. Once I did that, I could access the entities by label in a script as I had hoped.
As a second experiment, I then went back to the helpers /service.py file and commented out lines 556-559 and 589. I think this should disable the category and hidden checking and allow the entities to be referenced by label, regardless of category or whether they were hidden. That didn’t work, so I’m stuck for now. Maybe there is another code file that also filters the category, but I can’t find it for now.
Anyway, thanks for the help so far. I think the “ideal” solution for this issue would be if the selector had some option toggles to all selecting Configuration and Diagnostic category items - I was hoping to get there and do a PR, but maybe that becomes a feature request if I can’t solve it myself (I am not familiar with the frontend development needed to add the toggles, but was hoping to at least identify the relevant logic that would need to respond to the toggles)…
We have a history of ignoring categorized sensors for areas, e.g. if you tell HA to turn off all switches in an area, you probably don’t also mean for it to turn every setting of every device to false, that’s the logic behind ignoring these configuration sensors.
Though with labels given that it’s much more explicit to tag individual entities with the labels, I’m surprised they decided to extend that logic to labels as well, maybe enough thought wasn’t put into it.
If you’re thinking about a PR yourself, I would encourage you to start with an architecture discussion. Maybe core team would agree to just remove this logic for entities targetted by a label, given that it’s very explicit which entities you want to target. Then you wouldn’t need any frontend PR.
I think adding extra user visible options to a target selector is probably a no-go, that sounds way too confusing.
Good idea. I’ll go with this approach. I also realized that I could get what I needed using a simple template with label_entities in the target (which allows selection of Configuraiton and Diagnostic category entities)…