GET limited number of states/entities when using api/states

Hi everyone,

I’m looking for a way to make Home Assistant return only a specific list of entities when performing an API call. Currently, when I send a GET request to /api/states, it returns all my entities—resulting in a massive response (around 80KB of text and over 20,161 lines). Given the large number of entities in my setup, I’d like to limit the response to only the entities I need.

Is there a way to filter the entities returned by an API request? Ideally, something similar to how the Alexa integration allows specifying included entities and domains, like this:

alexa:
  smart_home:
    locale: fr-FR
    endpoint: https://api.amazonalexa.com/v3/events
    client_id: amzn1.ask.skill.mypersonnalskillID
    client_secret: xxxx
    filter:
      include_entities:
        - switch.interrupteur_chambre_perso_left
        - switch.interrupteur_cuisine_left
        - switch.interrupteur_cuisine_right
        - switch.interrupteur_salon_left
        - switch.prise_backup_4g
        - climate.ac_couloir
        - climate.ac_salon
        - light.lumieres_salon
      include_domains:
        - cover
        - fan

Does Home Assistant provide a way to achieve this via its API?

Thanks in advance for any insights! :rocket:

You can use a template to limit the list of entities by posting to /api/template.

Thanks for the quick answer, this is what I am looking for.
I’m going to learn how to format templates now !
Have a nice day !