Export entity names

Anyone know if there is a way to export all the entity names as a list?

To get a list of all your entities.

Create this notification integration:

- platform: file
  name: entity_log
  filename: /config/www/entity_log.txt
  timestamp: false

and this script:

print_entities_to_file:
  alias: 'Print Entities To File'
  sequence:
  - service: notify.entity_log
    data_template:
      message: >
        {% for state in states %}
          - {{- state.entity_id -}}
        {% endfor %}

If you don’t have a config/www directory. Create one.

Restart.

Then run the script from the Developer tools / Services menu.

The script will create a text file containing all your entities in a format that can later be cut and pasted into your Recorder, Logbook, and History integrations. You can find the file here /config/www/entity_log.txt.

Open the file in your preferred text editor. You should see something like this:

Home Assistant notifications (Log started: 2020-06-15T16:25:14.430437+00:00)
--------------------------------------------------------------------------------
-alarm_control_panel.house
  -automation.7pm_abc_news_on_tv
  -automation.abb_usage_alert
  -automation.acrc_reboot
  -automation.addon_update_available
  -automation.alarm_away_mode_armed
  -automation.alarm_away_mode_arming
  -automation.alarm_disarmed
  -automation.alarm_triggered
  -automation.alarm_warning
  -automation.allways_on_device_alert
  ...etc
6 Likes

Ok, I did that. Something went wrong though. Now I can’t access HA through 8123. I can access Node Red directly through 1880 and appdaemon through 5050. But when I try to access HA through 8123 I just get:

This site can’t be reached

192.168.1.44 refused to connect.

Can you see the logs ?

I couldn’t see anything. The only way I know how to see them would be through the Lovelace UI. I wanted to move the Pi anyway so I just killed it and plugged it back in. Before I did that, I used the FTP addon to edit configuration.yaml to comment out your lines. I realised that might have been my mistake. I just saw that and assumed it went into configuration.yaml.

So, I guess that’s my next question :slight_smile: How do I create a notification integration?

In configuration.yaml :

notify:
  - name: notifier_hangouts
    platform: hangouts
    default_conversations:
      - id: UgzeEijx9wzdysrrfx14AaABAagBgbmCCw

  - platform: file
    name: entity_log
    filename: /config/www/entity_log.txt
    timestamp: false
2 Likes

Cool. I’ll try that. Before I do… if it goes FUBAR, is there a way to restart HASS without just pulling the plug on the Pi if I don’t have access to the UI? SSH seems to be disabled.

If you are running Home Assistant OS or Home Assistant Supervised, just install the Web Terminal and SSH add-on. Just don’t forget to enable port 22 :

2 Likes

Perfect! That’s done the trick, thank you!

I would also like a list of entities. Where do I place that information?

edit: I figure it out - it goes under notify: in the configuration.yaml as per File - Home Assistant

So I had it set as

notify:
  - platform: file
    name: entity_log
    filename: /config/www/entity_log.txt
    timestamp: false
1 Like

This has stopped working for me, anyone else?

I’m getting this when tying to call the service…

Failed to call service notify/entity_log. required key not provided @ data['message']

I used this command in the developer tools and it worked with no error.

1 Like

This script will work without the error.

print_entities_to_file:
  alias: Print Entities To File
  sequence:
  - service: notify.entity_log
    data:
      message: "{% for state in states %}\n  - {{- state.entity_id -}}\n{% endfor\
        \ %}\n"
  mode: single
1 Like

That worked, thanks!

Hi,
I’m trying to export the info that you can find when clicking under “entities” in configuration.

In other words, a table file with
Name, Entity_id, Integration, Area, Status

Sadly that web page is not exportable, or selectable, not even printable.

Is that possible?

I cannot find how to call the “integration” info such as “Deconz”, “Tuya”, etc.

{% for state in states %}
{{ state.domain, state.entity_id, state.object_id, state.name, }}
{%- endfor -%}

Edit: after discussing on Discord, it seems this is simply not possible using tempaltes as the data is not available there.

I solved my issue with the next trail below

1 Like

I’m almost scared to explain how I did this in 30 seconds (since I didn’t use code but brute forced it somehow)… but

  • Open the file \config.storage\core.entity_registry (I’m on rpi4 / Hassio supervised - did this via Samba)
  • Copy all the text and pasted in this random json to table converter…

VoilĂ . A beautiful table with everything posiible :slight_smile:

Edit: This is the list of data field available in this file:

entity_id
config_entry_id
device_id
area_id
unique_id
platform
name
icon
disabled_by
supported_features
device_class
unit_of_measurement
original_name
original_icon
capabilities/hvac_modes/0
capabilities/hvac_modes/1
capabilities/max_temp
capabilities/min_temp
capabilities/preset_modes/0
capabilities/preset_modes/1
capabilities/preset_modes/2
capabilities/preset_modes/3
capabilities/preset_modes/4
capabilities/source_list/0
capabilities/source_list/1
capabilities/min_mireds
capabilities/max_mireds
capabilities/effect_list/0
capabilities

18 Likes

This is fantastic, just what I was looking for. Thanks so much!

This worked so good, I want to do the same for devices rather than entities. I tried changing this around like so:

In the config:

notify:
  - platform: file
    name: device_log
    filename: /config/www/device_log.txt
    timestamp: false

script:

print_devices_to_file:
  alias: '2.) Print Devices To File'
  sequence:
  - service: notify.device_log
    data_template:
      message: >
        {% for state in states %}
          - {{- state.device_id -}}
        {% endfor %}

put all I received was a list of dashes. I am assuming this section:

{% for state in states %}
  - {{- state.device_id -}}
{% endfor %}

is incorrect but not sure what to use instead? Can anyone assist?

There is a much simpler solution.

Simply navigate to Dev tools>> Template and paste below

        {% for state in states %}
          - {{- state.entity_id -}}
          ^ {{- state.name -}}
        {% endfor %}

The resukt will be shown at right side. You can copy paste into excel and use text to columns to split using ^ symbol for ID and Name and find replace to remove leading - on the entity. Boom - you will have a neat excel in less than a minute

10 Likes

Another option…

With ssh set up its straightforward to access the entities from a terminal on your PC, at home I’m using Linux (Fedora) - any Linux would do. For example:

kiat@fedora:~ ?} ssh ha "cat /config/.storage/core.entity_registry | awk '\$1 ~ /entity_id/ {print \$2}' | sed 's/\(\"\|,\)//g' | sort | egrep ^switch" | tail
switch.wled_island_sync_send
switch.wled_porch_nightlight
switch.wled_porch_reverse
switch.wled_porch_sync_receive
switch.wled_porch_sync_send
switch.wled_utility_nightlight
switch.wled_utility_reverse
switch.wled_utility_sync_receive
switch.wled_utility_sync_send
switch.zbbridge

and

{kiat@fedora:~ ?} ssh ha "cat /config/.storage/core.entity_registry | awk '\$1 ~ /entity_id/ {print \$2}' | sed 's/\(\"\|,\)//g' | sort | egrep ^binary_sensor" | tail
binary_sensor.watersensor_wc_water_leak
binary_sensor.wled_bench_firmware
binary_sensor.wled_hall_firmware
binary_sensor.wled_island_firmware
binary_sensor.wled_porch_firmware
binary_sensor.wled_utility_firmware
binary_sensor.yard_all_occupancy
binary_sensor.yard_person_occupancy
binary_sensor.zigbee2mqtt_running
binary_sensor.zigbee2mqtt_update_available

where I’m using “tail” to truncate, but any prefered output of data is available by tweaking the “awk” and “sed” commands.