Hya,
where do i find device_id, entity_id for a given device or entity?
Thx in advance.
Hya,
where do i find device_id, entity_id for a given device or entity?
Thx in advance.
under configuration, either devices or entities

The only way you can find this value is by looking in . storage/core. device_registry (or creating a Device Automation via the UI and examining the YAML it generates)
Many thanks! Helpful.
how to do this?
URL works for me! Thank you 
Goto device page, in Automation div click plus button, choose âDo something when this device turns on or offâ (or something like this). This will follow you to creating automation page with trigger on your device. Click three dots, choose âEdit in YAMLâ - you will see device_id and entity_id of this device.
The way you seem to find it is by clicking âMQQT INFOâ
Seems to me, that the value in MQTT INFO is the IEEE address of the device.
From Terminal tool in home assistant browse to the folder using following command
cd /config/.storage
cat core.device_registry
screenshot below
Just right-click on the integrationâs three dots on the integrations page and choose download diagnostics. The id is part of the filename.
I spent way too much time on this and ended up writing a quick Python helper script for this:
import json
import os
def list_sensors():
# Path to the core.entity_registry file
registry_path = '.storage/core.entity_registry'
try:
# Read the JSON file
with open(registry_path, 'r') as f:
data = json.load(f)
# Get all entities
entities = data.get('data', {}).get('entities', [])
# Print ID mappings for occupancy/motion sensors
print("Motion/Occupancy Sensor Mappings:")
print("-" * 50)
for entity in entities:
entity_id = entity.get('entity_id', '')
if ('occupancy' in entity_id.lower() or 'motion' in entity_id.lower()) and 'binary_sensor' in entity_id:
internal_id = entity.get('id')
device_id = entity.get('device_id', 'N/A')
print(f"Internal ID: {internal_id}")
print(f"Entity ID: {entity_id}")
print(f"Device ID: {device_id}")
print("-" * 50)
except FileNotFoundError:
print(f"Error: Could not find file at {registry_path}")
except json.JSONDecodeError:
print("Error: Invalid JSON format in the registry file")
except Exception as e:
print(f"An error occurred: {str(e)}")
if __name__ == "__main__":
list_sensors()
This will return something like this:
Motion/Occupancy Sensor Mappings:
--------------------------------------------------
Internal ID: [redacted]
Entity ID: binary_sensor.[redacted]
Device ID: [redacted]
--------------------------------------------------
[...]
If youâre interested, the following template duplicates most of what is produced by your python script. It reports the device_id and entity_id of every binary_sensor whose object_id contains either the string âmotionâ or âoccupancyâ.
{% for x in states.binary_sensor | selectattr('object_id', 'search', '(motion|occupancy)') -%}
{{ device_id(x.entity_id) }}, {{ x.entity_id }}
{% endfor -%}
What it doesnât report is the id field (as in your python script) because (to my knowledge) itâs not exposed to templating (inconsequential; itâs only used internally for cross-referencing items in the config files).
Hi there!
I have the same issue. I have a tasmota device and dont know itâs identifier as it has itâs own âtasmotaâ integration which doesnât show the device ids.
No I want to link a second (mqtt) device with the tasmota device with the mqtt discovery message option âvia_deviceâ.
But I canât link the mqtt device because I donât get the correct device identifier from the tasmota device. I tried the long id â9183wka838bf59egc592ef83aa4nndd7â from the url in the tasmota device section but obviously itâs wrong.
I also tried your python script and the template, but Iâm always getting the long ID from above.
The mqtt discovery message from the second device is as follows:
device:
via_device: 9183wka838bf59egc592ef83aa4nndd7
identifiers: plantsense
manufacturer: test
sw_version: '0.1'
name: Plant Sensor
model: test
hw_version: '3'
configuration_url: http://192.168.1.43
state_topic: homeassistant/sensor/testdev/plant01/state
object_id: plant01
unique_id: plant01
command_topic: homeassistant/sensor/testdev/plant01/cmd
device_class: temperature
name: soil_moisture
unit_of_measurement: °C