postlund/search-card

Search using friendly name

Closed this issue · 4 comments

After trying it out for a bit i thought the search wasn't fully working for some entities for me.

Then i found out that the entities i couldn't find had a unfriendly entity id like 'eurodomest_06_435' when i searched with that it did find my "living room light" since i only changed the friendly name in the customization.

It would be great if the search function would search the entity id and friendly names of entities.

Other than that i haven't ran into any issues so far and am loving this!

Yeah, you are right. Currently it searches on entity id solely, but searching on friendly_name (with fallback on entity_id) would be more convenient. That was my intention all along, also supporting things like regular expressions too. Will add that once I have some free time.

Great that you find it useful! 😄

Finally got myself some time to tinker with it, but my internet is acting up so i can't make a proper PR right now. You'd want to replace the for loop at #88 with

    for (var entity_id in this.hass.states) {
      if (
          (entity_id.toLowerCase().indexOf(searchText) >= 0) ||
          (
            "friendly_name" in this.hass.states[entity_id].attributes &&
            this.hass.states[entity_id].attributes.friendly_name.toLowerCase().indexOf(searchText) >= 0
          )
        ) {
        this.data.push(entity_id);
      }
    }

I added tolowerCase() to both to make it case insensitive, i also did this to the searchtext at #81

Since the internet is back and the other person doing this hasn't updated his PR yet, i have taken some of his code and improved on it in #7

Closed #7, so this should be fixed now!