t0bst4r / matterbridge-home-assistant

Apache License 2.0
36 stars 2 forks source link

Feature Request: hide entities based on their hidden attribute #52

Closed t0bst4r closed 2 weeks ago

t0bst4r commented 3 weeks ago

It would be awesome to have the aggregator ignore hidden entities, I hide useless entities in my HA setup and they get omitted by the Alexa and HomeKit integration. A similar behaviour would be perfect.

antoniozh commented 3 weeks ago

Hi, I've had a look over it and it seems like it could be easily filtered. Unfortunately I couldn't get the development environment set up, so I've just looked at the home assistant js repo and came up with this. In home-assistant-client.ts:48 const filteredEntities = Object.entries(entities).filter(([key, value]) => this.isIncluded(key) && ! value.attributes.hidden);

Please tell me if it makes sense.

dianlight commented 3 weeks ago

also disabled entities are wrongly exported

antoniozh commented 3 weeks ago

Maybe we could just write another method for the entities like isEnabled, just like the isIncluded method?

t0bst4r commented 3 weeks ago

I’ll have a look tomorrow regarding the hidden attribute. i have seen that before, but it felt not to be reliable, but ill give it another try by testing it explicitly.

tam481 commented 3 weeks ago

Sorry about #54. I forgot to refresh my browser page and did not see this one.

+1 though :-)

t0bst4r commented 3 weeks ago

I just gave it a try in #58 without testing. I’ll do some testing tomorrow and release it as soon as possible.

t0bst4r commented 3 weeks ago

I just checked the attributes I get from the WebSocket and the hidden attribute is not exposed at all. Then I checked the attributes in Home Assistant's developer tools and found that the hidden state is NOT an attribute at the entity.

I don't know if and how we can get that information in the WebSocket or the Rest API. For now, I have no solution for this and it needs further investigation.

tam481 commented 3 weeks ago

What about using labels? Would that work as a workaround? i.e. one would create a dedicated label for hidden entities, tag said entities and then Matterbridge can use that label to exclude the entities.

t0bst4r commented 3 weeks ago

Could you check in the developer tools of home assistant if labels are added to attributes?

If not I’ll need to consider to call the rest api additionally to the websocket…

tam481 commented 3 weeks ago

Could you check in the developer tools of home assistant if labels are added to attributes?

If not I’ll need to consider to call the rest api additionally to the websocket…

If I've looked at the correct thing, it doesn't look like the label is part of the attributes of entities.

t0bst4r commented 3 weeks ago

That’s unlucky… I’ve also thought about adding the "hidden" attribute by hand (or automation) via the developer settings in home assistant. That is actually possible to do by hand, but since custom attributes are transient, they are not actually saved and get lost after restarting HA.

we'd need an scheduled automation which syncs the hidden-property to the entity's attributes. But I cannot find any service call to set a custom attribute. On the other hand, that is just a workaround to avoid calling the API 😅 Maybe we should accept that’s it’s not possible with the WebSocket and consider to call the rest api once in a while

t0bst4r commented 3 weeks ago

I have found a way to retrieve the hidden status via the websocket. This needs some further refactoring and therefore I need some days

t0bst4r commented 2 weeks ago

@tam481 @antoniozh Just released version 1.0.0 including this feature