Template to list each entity and area

this template works fine for the first 4 colums I want, but I don’t seem to be able to figure out how to use area_name(lookup_value) or something similar to put the area name in the output. I’ve tried a couple of combinations of quotes and brackets etc… could someone point out how I could return the area name for each entity by adding something to this template?

entity_id,domain,object_id,friendly_name, area_name
{% for state in states %}
{{ state.entity_id }},{{ state.domain }},{{ state.object_id }},"{{ state.attributes.friendly_name }}",{{"Bedroom or whatever the area name is"}}
{%- endfor -%}

area_name(state.entity_id)

BTW, you can use state.name instead of state.attributes.friendly_name

Thank you.

Just in case anyone else can benefit, here is a template to list all entities along with some details about each entity for exporting to Excel:

entity_id,domain,object_id,name,area_name,icon,device_class,unit_of_measurement
{%- for state in states %}
{{ state.entity_id }},{{ state.domain }},{{ state.object_id }},"{{ state.name }}","{{ area_name(state.entity_id) }}","{{ state_attr(state.entity_id,'icon') }}","{{ state_attr(state.entity_id,'device_class') }}","{{ state_attr(state.entity_id,'unit_of_measurement') }}"
{%- endfor -%}
{# The template (Jinja2) is written so that the output can be cut/paste into Excel > Data Tools > Text To Column > Delimited > Comma > Text Qualifier of Quotation mark. #}
{# Alternatively, it can be saved into a CSV Comma Separated Values file #}
{# The minus sign - after the first curly brace percent sign {% will remove preceding whitespace (in this case, eliminate a blank line between the headers and the data) #}

here is some of the output in table form:

entity_id domain object_id name area_name icon device_class unit_of_measurement
sensor.raspi_host_memory_free sensor raspi_host_memory_free System Monitor Memory free None mdi:memory data_size MiB
sensor.gvh5075_b4f6_estimated_distance sensor gvh5075_b4f6_estimated_distance Basement iBeacon TempHumid Estimated Distance Basement mdi:signal-distance-variant distance m
sensor.iphone_456hjkl_battery sensor iphone_456hjkl_battery iPhone-456hjkl Battery Portable mdi:battery battery %
binary_sensor.backups_stale binary_sensor backups_stale Backups Stale None None problem None
binary_sensor.blink_utility_room_battery binary_sensor blink_utility_room_battery blink Basement Utility Room Battery Basement mdi:battery-charging-100 battery None
camera.blink_my_house camera blink_my_house House Driveway None None None
device_tracker.iphone_456hjkl device_tracker iphone_456hjkl iPhone-456hjkl Portable mdi:cellphone None None
person.brad person brad Brad None None None None
select.kitchen_kpl_a_dome_light_ramp_rate select kitchen_kpl_a_dome_light_ramp_rate Kitchen KPL.A Dome Light Ramp Rate Kitchen None None None
switch.laundryrm_motion_switch switch laundryrm_motion_switch Laundry Room Motion Switch Laundry None None None
switch.office_notify_driveway_10 switch office_notify_driveway_10 Office Notify Driveway Office mdi:flash-alert None None
input_boolean.smart_heater_state input_boolean smart_heater_state Govee Smart Heater State None {% if is_state(‘input_boolean.smart_heater_state’, ‘on’) %} mdi:radiator {% else %} mdi:radiator-off {% endif %} None None

Here is the raw output from the Developer Tools > Templates > Results



entity_id,domain,object_id,name,area_name,icon,device_class,unit_of_measurement
sensor.raspi_host_memory_free,sensor,raspi_host_memory_free,"System Monitor Memory free","None","mdi:memory","data_size","MiB"
sensor.gvh5075_b4f6_estimated_distance,sensor,gvh5075_b4f6_estimated_distance,"Basement iBeacon TempHumid Estimated Distance","Basement","mdi:signal-distance-variant","distance","m"
sensor.iphone_456hjkl_battery,sensor,iphone_456hjkl_battery,"iPhone-456hjkl Battery","Portable","mdi:battery","battery","%"
binary_sensor.backups_stale,binary_sensor,backups_stale,"Backups Stale","None","None","problem","None"
binary_sensor.blink_utility_room_battery,binary_sensor,blink_utility_room_battery,"blink Basement Utility Room Battery","Basement","mdi:battery-charging-100","battery","None"
camera.blink_my_house,camera,blink_my_house,"House","Driveway","None","None","None"
device_tracker.iphone_456hjkl,device_tracker,iphone_456hjkl,"iPhone-456hjkl","Portable","mdi:cellphone","None","None"
person.brad,person,brad,"Brad","None","None","None","None"
select.kitchen_kpl_a_dome_light_ramp_rate,select,kitchen_kpl_a_dome_light_ramp_rate,"Kitchen KPL.A Dome Light Ramp Rate","Kitchen","None","None","None"
switch.laundryrm_motion_switch,switch,laundryrm_motion_switch,"Laundry Room Motion Switch","Laundry","None","None","None"
switch.office_notify_driveway_10,switch,office_notify_driveway_10,"Office Notify Driveway","Office","mdi:flash-alert","None","None"
input_boolean.smart_heater_state,input_boolean,smart_heater_state,"Govee Smart Heater State","None","{% if is_state('input_boolean.smart_heater_state', 'on') %} mdi:radiator {% else %} mdi:radiator-off {% endif %}","None","None"
2 Likes

This is gold. I’ll use it to sort per area and build some per-room yaml’s programmatically.

I’ll add that you can also include the entity value and its attributes in the table, by adding {{state.state}},{{state.attributes}}.

Depending on the number of entries the table may get too big. When including all columns i got 'Template output exceeded maximum size of 262144 characters’.

Hi,
I created a template and copied the code but I obviously either missed a step or don’t understand as it didn’t work. I’m no programmer.
Some advice would be great.
TIA
John

Nice code but… even after trimming it down to just this:

entity_id,object_id,name,area_name,device_class
{%- for state in states %}
{{ state.entity_id }},{{ state.object_id }},"{{ state.name }}","{{ area_name(state.entity_id) }}","{{ state_attr(state.entity_id,'device_class') }}"
{%- endfor -%}

I still get this error:
Template output exceeded maximum size of 262144 characters

Still, thanks for posting!

Copy the template code from this post into your clipboard then
Home Assistant > Developer Tools > Template > Clear Template Editor
Past the template code into the Template Editor
The response will appear in the results frame
In my case ≈ 150,000 characters for about 1,000 entities.
If you have more entities or long entity names, @hobbyist99 indicated a limit of 262,144 characters.
Good Luck

In that case I suggest getting less columns at a time. Only choose the ones you need, or get the columns in batches and merge the downloads later.

262144 chararters, that is exactly 256 kB (kilo Bytes). Seems like the maximum buffer you can use :wink:

Template to get names, states and all attributes of all entities whose id contain a specific string:

{%- for state in states %}{% if 'XXX' in  state.entity_id -%}
{{ state.entity_id }},"{{ state.name }}","{{ state.state }}"
{%- for a in state.attributes %}
,{{a}}, "{{ state_attr(state.entity_id,a) }}"
{%- endfor %}
{% endif %}{%- endfor %}