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 ![]()
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();
]]]