What attributes do devices have?

I’m trying to make a template that lists unavailable devices. I’ve made it work for entities, but of course when a device is unavailable, all its entities are unavailable at the same time and it’s really the device I’m interested in. I’m making progress with this and the new device_id and device_attr template filters:

{% set device_ids = states
  | selectattr('state', 'in', ['unavailable', 'unknown'])
  | map(attribute='entity_id')
  | map("device_id")
  | map("string")
  | unique
  | select("ne", "None")
  | list
%}

{% for device_id in device_ids %}
  {{ device_id }}
  {{ device_attr(device_id, "name") }}
{% endfor %}

This produces a list of IDs and names, but not the name I assigned. For example, I unplugged a sonoff basic, and the list shows:

7c0c371a33b490cdf1e791e0b98af344
0x00124b101e7939c1

I know this device is called “Sonoff Switch F344”, but the name attribute produces the original zigbee2mqtt-assigned name. I admit I guessed that the attribute was called ‘name’. I tried ‘friendly_name’ but that doesn’t seem to be a device attribute. The docs show ‘manufacturer’ as an example attribute, but I can’t find a list of attributes nor how I go about querying a device to see what attributes it has.

So my questions are:

  • Is there a way to find out what attributes are exposed by a given device (not entity)?
  • Is there a better way for me to list my unavailable devices?

Looks like they’re the one used to create the device:

So, for example {{ device_attr(device_id('switch.shelly1'), 'sw_version') }} can work, others are name

4 Likes

name_by_user is super helpful, thanks!

1 Like