Export List of Entities, Automations, etc

Is there a way to export the list of Entities from your HA to a file?

It would be nice to be able to get a list of all your entities to import into an Excel file, database, etc., so that you can organize them outside of HA.

there are probably several ways, but you can try directly through the browser. Open the console in developer tools. Enter this command

const hass = document.querySelector('home-assistant').hass;
hass.entities

You will see the whole entities object in hass

To avoid confusion:

There is no console in Home Assistant’s Developer Tools.

They mean in the Web Browser Inspector. Which does not work for me:

Another way is to use the actual Home Assistant Developer Tools → Template editor and enter:

{{ states|map(attribute='entity_id')|list }}

3 Likes

it has to work… open Home Assistant in your browser (e.g., http://homeassistant.local:8123), go to console … paste this full script into console…

function downloadEntitiesCSV() {
  const hass = document.querySelector('home-assistant').hass;
  const entities = hass.entities;


  const sorted = Object.values(entities).sort((a, b) => {
    const idA = a.entity_id?.toLowerCase() || '';
    const idB = b.entity_id?.toLowerCase() || '';
    return idA.localeCompare(idB);
  });


  let csvContent = "ENTITY ID,NAME,PLATFORM\n";


  sorted.forEach(entity => {
    const entity_id = entity.entity_id || '';
    const name = entity.name || '';
    const platform = entity.platform || '';
    csvContent += `"${entity_id}","${name}","${platform}"\n`;
  });


  const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
  const url = URL.createObjectURL(blob);
  const link = document.createElement("a");
  link.setAttribute("href", url);
  link.setAttribute("download", "hass_entities.csv");
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}

then type and run…

downloadEntitiesCSV();

file hass_entities.csv will automatically download to your system

1 Like

Uh huh. So That screenshot I made is a hallucination.

No thanks.

1 Like

Worked after a cache clear. Odd.

@VietNgoc is Console the same at Terminal?

No:

I’m sorry. What is a Web Browser Inspector? Can you take a snapshot of it and post it? I do not see it in my copy of HA.

check How to open DevTools in the browser and console section…

Hej @VietNgoc ;
works fine and it’s helpful… Thanks for that…

I need some more informations in the CSV-Table… I tried to add my points, but it doesn’t work… I ask the KI as i am not famliar in coding JS.

Maybe you are so kind to check my Code made by KI? It based on your code here.
I “only” want to add and want it in this order “Entität”, “Entität-ID”, “Device”, “Area”, “Integration”, “Status”…

And this is the code i tried with:

async function downloadEntitiesCSV() {
  // Home Assistant-Objekt mit allen Entitäten holen
  const hass = document.querySelector('home-assistant').hass;
  const entities = hass.entities;

  // Asynchrone Abfrage der Device Registry und Area Registry von Home Assistant
  const devices = await hass.connection.sendMessagePromise({
    type: "config/device_registry/list"
  });
  const areas = await hass.connection.sendMessagePromise({
    type: "config/area_registry/list"
  });

  // Hilfsobjekte zur schnellen Zuordnung von device_id bzw. area_id zu Namen
  const deviceNameById = {};
  devices.forEach(device => {
    deviceNameById[device.id] = device.name || device.name_by_user || '';
  });

  const areaNameById = {};
  areas.forEach(area => {
    areaNameById[area.area_id] = area.name || area.name_by_user || '';
  });

  // Sorted Array aller Entities nach entity_id alphabetisch sortiert
  const sorted = Object.values(entities).sort((a, b) => {
    const idA = a.entity_id?.toLowerCase() || '';
    const idB = b.entity_id?.toLowerCase() || '';
    return idA.localeCompare(idB);
  });

  // CSV-Header mit gewĂĽnschten Spalten
  let csvContent = "Entität,Entity ID,Gerät,Bereich,Integration,Status,Platform\n";

  // Jede Entität zur CSV hinzufügen
  sorted.forEach(entity => {
    // Friendly Name (menschlich lesbarer Name)
    const friendlyName = entity.attributes?.friendly_name || '';

    // Entity ID (eindeutige ID in HA)
    const entityId = entity.entity_id || '';

    // Geräte-Name aus Device Registry, basierend auf context.device_id
    const deviceId = entity.context?.device_id || '';
    const device = deviceNameById[deviceId] || '';

    // Bereichs-Name aus Area Registry, basierend auf area_id des Geräts
    const deviceAreaId = devices.find(d => d.id === deviceId)?.area_id || '';
    const area = areaNameById[deviceAreaId] || '';

    // Integration – benutzt platform-Zuweisung als Proxy
    const integration = entity.integration || entity.platform || '';

    // Status = aktueller Zustand der Entität (z.B. on, off)
    const status = entity.state || '';

    // Platform (mqtt, zwave, template...)
    const platform = entity.platform || '';

    // Zeile fĂĽr CSV
    csvContent += `"${friendlyName}","${entityId}","${device}","${area}","${integration}","${status}","${platform}"\n`;
  });

  // CSV-Datei als Blob erzeugen
  const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });

  // Download-URL erzeugen und Klick auf unsichtbaren Link simulieren
  const url = URL.createObjectURL(blob);
  const link = document.createElement("a");
  link.setAttribute("href", url);
  link.setAttribute("download", "hass_entities.csv");
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}

And this is the result:
image

Here is a modified version with additional info…

function generateEntityItems() {
    const hass = document.querySelector("home-assistant").hass;
    const entities = hass.entities;
    
    const sorted = Object.values(entities).sort((a, b) => {
        const idA = a.entity_id?.toLowerCase() || '';
        const idB = b.entity_id?.toLowerCase() || '';
        return idA.localeCompare(idB);
    });

    let csvContent = "ENTITY ID,ENTITY NAME,DEVICE NAME, DEVICE ID, AREA,PLATFORM (INTEGRATION),STATE,FORMATED STATE\n";
    
    sorted.forEach((ent) => {
        const eId = ent.entity_id;
        const stateObj = hass.states[eId];
        const entityName = hass.formatEntityName(stateObj, "entity");
        const deviceName = hass.formatEntityName(stateObj, "device");
        const deviceId =  ent.device_id;
        const areaName = hass.formatEntityName(stateObj, "area") || '';
        const platform = ent.platform || '';
        const state = stateObj.state;
        const formatedState = hass.formatEntityState(stateObj);
        
        const info = [eId, entityName, deviceName, deviceId, areaName, platform, state, formatedState].join(", ");
        
        csvContent += `${info}\n`;
    });

    const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
    const url = URL.createObjectURL(blob);
    const link = document.createElement("a");
    link.setAttribute("href", url);
    link.setAttribute("download", "hass_entities.csv");
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
};
1 Like

This still seems a lot easier:

3 Likes

Problem is that working with the browsers console is such an uncomfortable way for such a neat thing I would simply surround it by something like this.

type: custom:button-card
name: Export my Entitys as CSV
tap_action:
  action: execute-a-js-function
  the_js_function: |
    [[[

      # paste the function in here

      generateEntityItems();
    ]]]

and you got a nice button on your dash which allows you to simply generate that list without using opening the devtools console paste the whole lot and close that view afterwards.

I do love your function as I do love that I could define tap_actions named to whatever I like. :slight_smile:

1 Like

@tom_l ,
thank you for your thoughts and your Code line…
But how can i expand the list with some more details for the devices, integration, status? Where do i find the keywords for those?
I tried this, but it doesn’t work?

1 Like

Hej @VietNgoc ,
thank you sooo much… That works fine for me and give me so much support…

Only a question please… How did you get the right variables for the Columns? Where did you get the correct variable names for the columns to be listed? You have to tell the script which “drawers” to look in to get the values. Where can I look them up if I have further requests?

And again… You made my Day… Thanks

@justone ,
thanks for your support… I will try this to have more comfort way on creating my list…

I’m new here. Where do I “simply surround” the function with your code? Template editor? Terminal? A file somewhere?

Thanks.

The custom button card is a card to be placed in the dashboard.
You have to install it from HACS since it’s a custom card.

And the example is sort of the most raw configuration of that card without any fancy fonts , colors, fancy buttons or such like.

You simply paste the function @VietNgoc posted some posts earlier between the rectangle brackets, that’s it.

You’ll then find a small card with a title “Export my Entitys as CSV” in your dashboard and once you pressed the card (button) the file gets saved.