Hi All,
I did not find any endpoint in rest api to retrieve the devices. Is the any endpoint we have or how can we do this.
Regards,
Dimantha
Hi All,
I did not find any endpoint in rest api to retrieve the devices. Is the any endpoint we have or how can we do this.
Regards,
Dimantha
You can render a template (POST /api/template
) to return what you need. This returns a list of all device IDs that have at least one entity associated with them:
{{ states|map(attribute='entity_id')|map('device_id')|unique|select|list }}
troon@laptop:~$ curl -H "Authorization: Bearer [MY_TOKEN]" -H "Content-Type: application/json" -d '{"template": "{{ states|map(attribute=\"entity_id\")|map(\"device_id\")|unique|select|list }}"}' http://192.168.1.7:8123/api/template
['1f0d5dd2f4dd0c3dca4e531dd22814e1', 'b8f14a02c562ca16e0292c33cd5b185a', '512bf4bdf8a4f1ef8897b2a9693b9a9b']
(list truncated for posting)
Working with devices is messy though: what are you actually trying to do?
Hi thanks for replying I am trying to migrate data so my team has ask to get device information so I need to pull all the devices let me try this and come back
yeah it was tricky i was able to get the device name like below had to pass the entity {
“template”: “{{ device_attr(‘sensor.temperature_and_humidity_sensor_temperature’, ‘name’) }}”
} my second question is how can i get the information related to where it is configured I mean area(location)?
{{ area_name('sensor.temperature_and_humidity_sensor_temperature') }}
might get you what you need without worrying about devices, hence my original point about knowing what you’re trying to achieve.
thanks. this worked
Hi again I need some help I want to get the integration information when I passed the device id but I get None as the response can you help me I was able to get manufacturere and model device_attr(‘c2936c503fed4d745798ad6ecc19xxxx’, ‘integration’)
That information isn’t stored as a device property, and isn’t in the list I linked.
Looks like you might be able to get it via the domain
attribute of the poorly-documented config entry for each entity [ref]:
{{ config_entry_attr(config_entry_id('sensor.aquarium_temperature'),'domain') }}
# returns 'esphome', as that entity is an ESPHome device entity
…and if you already know the integration name [ref]:
{{ integration_entities('esphome') }}
# for me, returns a big list including the aquarium sensor above
The integration name is all lowercase, as shown on the integration’s HA screen URL.
Still think you’re probably going about this the wrong way, but unless you properly describe what you’re trying to do, it’s hard to help further.
The template below seems to list of all devices (with at least one entity; does not include entities not associated with a device) and their corresponding integration, for pasting into Developer Tools / Templates:
{% set devices = states|map(attribute='entity_id')|map('device_id')|select|unique|list %}
{% set ml = max(32,devices|map('device_attr','name')|select|map('length')|max) %}
{% set mls = "%%-%ds"%ml %}
| {{ mls|format("Device") }} | Integration
|={{"="*ml}}=|={{"="*11 }}=
{% for d in devices -%}
{% if device_entities(d) -%}
{% set n = device_attr(d,'name') or d -%}
{% set i = config_entry_attr(config_entry_id(device_entities(d)[0]),'domain') -%}
| {{ mls|format(n) }} | {{ i }}
{% endif -%}
{% endfor -%}
Note: this is a “heavyweight” template, listening for all state changes. If you leave it live in the template editor, it’ll be putting quite a load on your system. Run it as a demo then delete it.
thanks for the information