Export List of Entities, Automations, etc

Thanks for the quick reply. The terminology is driving me a bit nuts though.

I have HACS and I just installed button-card, which says below it Lovelace button-card. There is a link to a discussion which mentions ui-lovelace-card.yaml. I put the code there and restarted, but nothing appeared. Then I realized that the discussion is 7 years old and a page they link to now redirects to a place with no mention of Lovelace or yaml. Am I even looking at the right button-card? Everyone there seems to assume that Lovelace is the default UI, but I have no idea whether this is now an unstated assumption or something deprecated before I started with Home Assistant.

There are dozens of things with the words ā€œbuttonā€ and ā€œcardā€ in HACS. None use the word ā€œcustomā€ with ā€œbuttonā€. Can you be more specific about which you use?

Once I have it, am I pasting the code into a *.yaml file? Something in the UI?

Thanks!

Looks to me as if you picked the correct one since yes the thread is 7 years old, for the simple reason since no better replacement was yet developped within the past 7 years for the simple reason that this one got better year by year.

Sort of a so called swiss-army-knife if you ask me, since it could be dead complexed if you want to aswell as pretty simple as long as you keep things easy.

the steps are … you go into a dashboard you want to add a card
press the pencil icon at the upper right corner to go into edit mode
press the +add card button in lower right
and from the popup window asking which card you want to add you scroll down until you reach the section showing the ā€œcustom cardsā€ being installed.
And if there’s one named ā€œButton-Cardā€ with the extra info ā€œA massivly customizable custom button cardā€ … .that’s the one you’re after.

if you click up that you should end up in a small windows telling you that this card must be configured using YAML and it should already present you with a minimalistic yaml example.

In case you have the ā€œSunā€ integration installed the shortest ever test for the button would be the 2 lines

type: custom:button-card
entity: sun.sun

which gives you a button with a sun or moon icon depending upon time of day you try this, and if being tapped/clicked opens a small popup with extra information about sunrise, sunset and such like.

And my example simply is such a minimalistic approach which allows you simply put any javascript function into such a card, with the result that clicking up that button card runs the function.

1 Like

Thank you for your help! All easy, but it just wasn’t obvious to me.

I am very close now.

I added a custom button to switch a light and it worked perfectly.

I added your button-card definition with the generateEntityItems() function inside and created another card. No errors, and it makes a button. When I click it there is a gray fade across the button and nothing else. Where is the output?

I looked first on Home Assistant Yellow.
find / -name hass_entities.csv found nothing.
On my Windows desktop there was nothing new in Downloads

I tried removing the removeChild line from the script hoping it would leave something visible on the page. Nothing.
I looked various panels in the FireFox web developer tools while executing the button. Nothing.

Tell me I made one stupid mistake and it will all work :slight_smile:

Here is what I put in the Button-Card card configuration box. It is simply copied from earlier posts:

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

      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);
      };
      generateEntityItems();
    ]]]

2 Likes

The latest version of the button card has a newly added js action, changed to the following

type: custom:button-card
name: Export my Entites as CSV
tap_action:
  action: javascript
  javascript: |
    [[[
      # function ... 
      generateEntityItems();
    ]]]
5 Likes

Huh, I always just template editor

For all entities

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

For all entities in the script domain

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

Volume level attribute for a.media player

{{ state_attr ('media_player.television', 'volume_level' ) }}

Wow! That did it. I have the csv file. Thank you!

Your examples work nicely for what they do, but I’m wondering how to find all the options. Is there documentation of what all the possible attributes are, or code to list them for an object?

Also, there you have states or state_attr, where can I get a list of valid terms to use there?

Just one other question. I can, for example. replace ā€˜entity_id’ with ā€˜name’ in your first example. What if I want the entity_id AND the name? I tried half a dozen guesses at a possible syntax, but no luck.

Thanks. I am learning a lot from this thread, and trying not to be a pest.

Yep, you can never be sure that besides some goodies, devs introduce breaking changes :slight_smile:

You are probably the third, the original question is how to export data to a file. Of course, it can be done in several ways, but for me, the hass object is better

If you’re running HAOS you can install the phpMyAdmin add on and run the below query, at least with MariaDB, I’m sure it works with MySQL but I’ve been using HA for so long that MariaDB used to be the better option. You can then export the query as a csv file. You can see the state attributes table although like. Most databases things are tied together through unique ID’s generated but the names exist somewhere for automations, pretty much anything you create through the UI domain wise should be in the DB, learn some inner joins and and multiple tables to come up with some ā€˜fun’ queries. Just don’t manually update anything for any reason. Fine to look but don’t update unless you know about unique constraints and some minimal database exposure. 1 is my home assistant DB and yes, I got carried away with voice assistants and need to do some cleanup as I also have orphaned entities.

SELECT `entity_id' FROM 'states_meta' WHERE 1


1 Like

Hi Guys, i really like this option with the button-card to get a csv-file. Thanks for that! I have done a little Analyzer Tool with python for the csv file. To get it working, the formatting of csv is changed from comma to semicolon. If you like it you can check my github. There are two Version, a executable exe for Windows and a py to get it work with Linux.

some pics:




1 Like

If you are interested, there is a new Version of the HA_Entity_Analyzer_Tool:
https://github.com/jayjojayson/HA-Entity-Analyzer

App-Features

  • :page_facing_up: simple Entities Tool to analyze your csv-file
  • ā†”ļø import and export csv file
  • :mag: free entity search
  • :bookmark: area & platform filter
  • :bar_chart: entities statistic

Gui-Features

  • works on win, (macos & linux in progress)
  • dark/lite mode
  • app on top (keep in foreground)
1 Like

Hi, I just generated the hass_entities.csv. The ENTITY NAME, DEVICE NAME and AREA are not populated, all other columns are. Could you help me out with this problem, please?

  • Core 2025.11.3
  • Supervisor 2025.11.5
  • Operating System 16.3

Hi, i have tested it and something has changed, so i have adapted the button-card to export the csv File. Now the Area should be displayed again. With Device and Entity i dont have problems, but i have changed it, too. Now all Filter are set to the registries. Changed the Stuff in my github and released a new Version of HA Entity Analyzer.

type: custom:button-card
name: Entity Export as CSV
tap_action:
  action: javascript
  javascript: |
    [[[
      function clean(value) {
        if (!value) return "";
        return String(value)
          .replace(/;/g, ",")   
          .replace(/\r?\n|\r/g, " ");  
      }

      async function generateCSV() {
        const hass = document.querySelector("home-assistant").hass;

        const areas = await hass.callWS({ type: "config/area_registry/list" });
        const devices = await hass.callWS({ type: "config/device_registry/list" });
        const entities = await hass.callWS({ type: "config/entity_registry/list" });

        const areaLookup = {};
        areas.forEach(a => areaLookup[a.area_id] = a.name);

        let csv = "ENTITY ID;ENTITY NAME;DEVICE NAME;DEVICE ID;AREA;PLATFORM;STATE;FORMATTED STATE\n";

        Object.values(hass.states)
          .sort((a,b) => a.entity_id.localeCompare(b.entity_id))
          .forEach(stateObj => {

            const entReg = entities.find(e => e.entity_id === stateObj.entity_id);
            const device = devices.find(d => d.id === entReg?.device_id);

            const areaName =
              entReg?.area_id ? areaLookup[entReg.area_id] || "" :
              device?.area_id ? areaLookup[device.area_id] || "" :
              "";

            const row = [
              clean(stateObj.entity_id),
              clean(hass.formatEntityName(stateObj)),
              clean(device?.name || ""),
              clean(entReg?.device_id || ""),
              clean(areaName),
              clean(entReg?.platform || ""),
              clean(stateObj.state),
              clean(hass.formatEntityState(stateObj))
            ].join("; ");

            csv += row + "\n";
          });

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

      generateCSV();
    ]]]