Export devices and entities

Would be great to get some export functionalities for area, devices and entities in a csv format or other type of format via a button or so. Would be easier to map everything in for example spreadsheets and workbook.
Alternatively adding similar functionality in the supervisor. I know a lot of functionalities are already build in but visibility per area of devices and entities and possibilities to add comments is missing. I think the export functionality is more simple to do though.

Hi, I assume that you want some GUI button to download stuff?

The information you want to export is stored in JSON format in the configuration/.storage folder.
Maybe that helps you as long as your Feature Request is not realized.

I also recommend to vote for your own request :wink:

Yes, would be great to have a “button” or something like that. I will add this to the request. Thanks for the hints on voting and where to find the data for now.

I would second this request. I’m in the middle of migrating Z-Wave to the new JS integration. I really wish all of the device and entity lists had an export to csv feature. Ideally, it would export the list as shown with applicable filters. In this instance I’d like to see all of the old device and entity names specific to the old z-wave integration.

Screen grab into a Google sheet didn’t format correctly into a table. It listed everything as one big column and I’m having to manually transpose the 5 or 6 rows into columns for each entity. My end goal is just to make sure the new device and entity names match so that all my dashboards and automations match correctly.

2 Likes

Has there been any update to this request?

I tried copy pasting the list from the Configuration/Devices page into Excel, and then extract the information. As @bwerst noted, this pulls across a single column, which then needs to be transposed. It also does not bring across the full list. And the transpose is a nightmare because the integrations do not have the same number of columns.

I’ve been digging around to work around this missing feature. Looking at .storage/core.device_registry and .storage/core.entity_registry, and I just want to keep some notes here on how far I got.

Looking at my IKEA Zigbee on/off/dimmer button, it’s as a device in the registry of course, but without useful info about the device class: all of this seems to be hidden in the integration (ZHA in my case), which figured out that this is a switch and enumerates entities. So there’s no info in HA that says “This is a switch [corresponding e.g. to a Zigbee cluster in a profile?], and in addition to having the switch-entity, it has another few entities that may be useful to you, like battery-level”.

So if I’m not interested in entities only, but the physical devices, my best way forward seems to be to build a mechanism that reconstructs the “device class” (switch/dimmer/sensor) based on the available entities (which I find in the core.entity_registry) and define a library of well-known device classes (which collection of entities for a device make it a “switch”, possibly with subclassing/multiple inheritance). Basically, HA doesn’t so much work with devices, but just all of their individual entities, with the only benefit of adding all entities of a new devices together in a UI-element when adding it.

Given just the device id, is there a way to ask the underlying integration to provide the underlying device class to me? Or is the original_device_class in the entity registry OR the entity-class (“switch”,“sensor”,…) the closest I can get? It would be really nice to somehow harness the underlying Python classes/class-hierarchy…except: is there actually a hierarchy? The binary_sensor has no relation to the sensor-device class, it seems, and duplicates lots of the enums in there.

@LittlePapaJohn @bwerst, @MilesAheadToo, @VolkerStolz
It has been along time since I implemented the following to accomplish what you are asking.
I can’t find my source, but try this if you are still seeking a solution…
There are a few steps:

  1. create a script to call the service and link it to a button on your desktop for easy activation. Examining mine, you will see I use a ~ for column separation.
alias: print_entity_attributes
sequence:
  - service: notify.print_export
    data_template:
      message: |
        {% for state in states %}{{ state.entity_id }}~{{ state.domain }}~{{ state.object_id }}~{{ state.name }}~~{{ state.attributes.icon, state.attributes.friendly_name }}~~{{ state.state }}
        {% endfor %}
mode: single
icon: mdi:cloud-print-outline
  1. Create the notify service (Called by the script). ((I am assuming not everyone has the configuration split.)) In your configuration.yaml under default_config:
default_config:
notify:
- name: print_export
  platform: file
  filename: /config/www/export.txt
  timestamp: false

Notes:
filename: /config/www/export.txt designates the destination and name of the file. If the file already exists and it is called again, it will append to the existing results. You could go directly to a .CSV but as you will notice, the first two lines need deleting; additionally, if there are any ,'s (commas) in the file, they need to be remedied before [Search and replace all ~ for ,] Finally you can save and rename the extension to .CSV and you should have everything you are looking for.

7 Likes

Thanks, works very well

1 Like

Thanks…I’m currently running everything through the /api/template-endpoint directly with custom templates. I still need to play a bit with the introspection of @Properties, though.

Hi,
I tried your script but get the following error:

Failed to call service script/export_devices_and_entities. Unable to find service notify.print_export

Any idea how to fix please?

After you modify the config as shown above you need to restart HA for the notify.print_export service to become active.

This solution works well. Is there any way to add the associated integration to the print out?

Building on Roger’s code above… I used the following code…

print_entity_attribute:
  alias: Print Entity Attributes
  sequence:
    - service: notify.print_export
      data_template:
        message: |
          {{'Device,Domain,Entity ID,Manufacturer,Model,Area,Integration,ID'}}
          {% for state in states -%}
            {%- if device_attr(state.entity_id, 'identifiers') -%}
              {%- set integrations = device_attr(state.entity_id, 'identifiers') | first | list -%}
              {%- set integration = integrations[0] -%}
              {%- set unique_id = integrations[1] -%}
            {%- else -%}
              {%- set integration = '-' -%}
              {%- set unique_id = '-' -%}
            {%- endif -%}
            {%- if device_attr(state.entity_id, 'manufacturer') -%}
              {%- set manufacturer = device_attr(state.entity_id, 'manufacturer') -%}
            {%- else -%}
              {%- set manufacturer = '-' -%}
            {%- endif -%}
            {%- if device_attr(state.entity_id, 'model') -%}
              {%- set model = device_attr(state.entity_id, 'model') -%}
            {%- else -%}
              {%- set model = '-' -%}
            {%- endif -%}
            {%- if device_attr(state.entity_id, 'area_id') -%}
              {%- set area = device_attr(state.entity_id, 'area_id') -%}
            {%- else -%}
              {%- set area = '-' -%}
            {%- endif -%}
            {{state.name}},{{state.domain}},{{state.entity_id}},{{manufacturer}},{{model}},{{area_name(area)}},{{integration}},{{unique_id}}
          {% endfor %}
  mode: single
  icon: mdi:cloud-print-outline

Used some slightly different attributes, you can pick and choose which one’s will work for your needs. I also just used commas instead if tildes so it’s basically a csv file. Come to think of it, I probably could have just saved it as .csv instead of .txt

2 Likes