Skip to content

Entity_Analyzer to anlyze the exported csv file from Home Assistant

License

Notifications You must be signed in to change notification settings

jayjojayson/HA-Entity-Analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub release Downloads GH-code-size README English

E_A_T-logo

Entity-Analyzer-Tool

Entity_Analyzer to anlyze the exported csv file from Home Assistant

Man kann wie im HA-Forum beschrieben wurde, auf dem Dahsboard einen Button anlegen, der nach drücken alle Home Assistant Entitäten, Automationen usw. in eine csv Datei exportiert. Diese Funktion vermisse ich aktuell in HA, da man so eine schöne “offline/backup” Variante hat, die Entitäten zu strukturieren, zu kontrollieren, zu dokumentieren bzw. sich einen Überblick zu verschaffen. Perfekt um “Leichen” auszusortieren, Namenstrukturen zu entwickeln usw.. Anschauen könnt ihr euch die csv-Datei z.B. mit dem beigefügtem Analyzer Tool oder mit Excel.

Schaut gerne in der Community vorbei. Dort haben wir ein entsprechendes Diskussion-Thema für den Austausch.

Wenn euch das Tool gefällt würde ich mir über einen Stern ⭐ von euch freuen. 🤗

App-Features:

  • 📄 simple Entities Tool to analyze your csv-file
  • ↔️ import and export csv file
  • 🔍 free entity search
  • 🔖 area, manufacturer & platform filter
  • 📊 entities statistic
  • 📊 energy statistic (imported HA energy.csv)

Gui-Features

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

Exported csv includes: entity_id, entityName, device_id, deviceName, area, plattform, state, manufacturer, model, model_id, sw_version, hw_version

📌 Vorgehensweise

Erstellt als erstes im Dashboard eine neue custom button card und fügt dort folgenden Code ein. Im Anschluss solltet ihr wie im Bild gezeigt diesen Button erhalten. Drückt nach Fertigstellung den Button und ihr bekommt die csv-Datei in den Download-Ordner.

image (1)
type: custom:button-card
name: Entity Export as CSV2
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;" +
          "MANUFACTURER;MODEL;MODEL ID;SW VERSION;HW VERSION\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] || ""
                : "";

            // Plattform
            const platform =
              entReg?.platform ||
              entReg?.integration ||
              stateObj.entity_id.split(".")[0];

            // Geräteattribute
            const manufacturer = device?.manufacturer || "";
            const model = device?.model || "";
            const model_id = device?.model_id || "";
            const sw_version = device?.sw_version || "";
            const hw_version = device?.hw_version || "";

            const row = [
              clean(stateObj.entity_id),
              clean(hass.formatEntityName(stateObj)),
              clean(device?.name || ""),
              clean(entReg?.device_id || ""),
              clean(areaName),
              clean(platform),
              clean(stateObj.state),
              clean(hass.formatEntityState(stateObj)),
              clean(manufacturer),
              clean(model),
              clean(model_id),
              clean(sw_version),
              clean(hw_version)
            ].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();
    ]]]

For HA-Version before 2025.11 use this card below and dowload the ver_1.1
type: custom:button-card
name: Entity Export as CSV
tap_action:
  action: javascript
  javascript: |
    [[[
      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();
    ]]]

📌 Installation

Ich habe ein kleines Python Tool entwickelt, dass die CSV einlesen kann. Für Windows gibt es gibt zwei Wege für die Installation, erstens bequem mit fertigem Programm arbeiten oder zweitens Python direkt installieren und das py-Script starten. Für Linux bleibt aktuell nur die Möglichkeit über Python direkt zu arbeiten, folgt dazu den Anweisungen.

Für Windows ladet euch einfach die ausführbare Version (.exe) herunter und startet das Programm.

Betrifft nur die manuelle Installation!

Das Tool nutzt Python, daher muss Python installiert sein oder werden!

In Windows öffnet ihr dazu die Powershell und gebt folgenden Befehl ein:

winget install Python

Danach installiert ihr noch das pandas Paket bzw. die Bibliothek:

pip install pandas

Unter Windows könnt ihr die Python Datei direkt aus dem "src" Ordner mit Doppelklick starten.


Unter Linux gebt folgende Befehle im Terminal ein:

sudo apt update && sudo apt install python3

Danach installiert ihr noch das pandas Paket bzw. die Bibliothek:

pip install pandas

Um das Programm zu öffnen, wechselt mit cd /euer Verzeichnis in den Ordner wo euer Entity_Analyzer liegt und startet mit folgendem Befehl das Tool.

python3 entity_analyzer_tool.py

📌 Nutzung

Nun könnt ihr den Entity_Analyzer öffnen und eure csv-Datei auswählen. Die Oberfläche bietet ein paar Möglichkeiten eure Entitäten zu sichten. Nach dem öffnen seht ihr unten links die Anzahl der Entitäten! Dort werden auch sonst nützliche Infos angezeigt.

image

1. Jetzt könnt ihr beispielsweise nach gewünschten Entitäten suchen:

Über die Spaltennamen kann beim auswählen eine aufsteigende oder absteigende Sortierung erfolgen. Außerdem könnt ihr die aktuelle Ansicht der Suche als neue csv Datei exportieren.

image

2. Die Entitätsstatistik abrufen und sehen wie viele Lichter oder Schalter habt ihr usw.:

image

3. Oder ihr könnt nach Area also Bereichen bzw. Platform und somit Integrationen filtern.

image (5) image (6)

4. Ihr könnt jetzt auch eure exportierte energy.csv mit dem Tool anschauen und analysieren.

image (5)

image (5)

image (5)

image (5)


⭐ Danke für die Unterstützung aus der Community, besonders an Dreckfresse, Nicknol und MarzyHA. Immer wieder schön, was man gemeinsam erreichen kann.

About

Entity_Analyzer to anlyze the exported csv file from Home Assistant

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages