I would like to determine which entities are part of the same device, which doesn’t seem possible just by looking at the information in /api/states. Is there another way?
Easiest way is probably just to use POST /api/template. You can get to device info in templates so just ask HA to resolve a template that outputs the info you need.
Hi, thanks for your example.
is it possible to add the device id and/or name to the array?
I would like to get an array of device with name/id and a entity array for each device.
Currently I’m reading entities with Websocket API. But I search for a way to get the devices and their entities to group teh entities.
Many thanks
Edit. I think I got it. Here is the result for anyone serching something similar:
{% set devices = states | map(attribute='entity_id') | map('device_id') | unique | reject('eq',None) | list %}
{%- set ns = namespace(devices = []) %}
{%- for device in devices %}
{%- set entities = device_entities(device) | list %}
{%- if entities %}
{%- set ns.devices = ns.devices + [ {device: {"name": device_attr(device, "name"), "entities":[entities ]}} ] %}
{%- endif %}
{%- endfor %}
{{ ns.devices }}