How to extract device type and power supply information from Zigbee2MQTT using a template?

I have dozens of Zigbee devices and use Z2M to manage them.
I’m developing a custom card to display some essential information about my devices.

In the Z2M interface, I can see whether a device is a “Router” or “End Device” and whether it’s powered by the mains or battery.

I’d like to know which template functions I can use to extract this information.

Battery-powered devices have external functions that allow us to view the load, but what I’m looking for is a function that allows me to see the device’s power supply.

I’ve done a lot of research, but few have ventured into this area, and in my research, I haven’t found anyone who has had success. But the information is there, so there must be a way to extract it.

I appreciate anyone who can help.

The information is in Zigbee2MQTT.

If Zigbee2MQTT doesn’t export the device’s type to Home Assistant, it’s inaccessible via template functions.

Zigbee2MQTT shares its data with Home Assistant via MQTT Discovery. If you view the device in Home Assistant (via the MQTT integration page) and don’t see the device’s type reported, then it means Zigbee2MQTT doesn’t share it.

I just checked and there’s no explicit indication of router/end device.

Having said that, you can infer the device’s type by the presence, or absence, of an associated battery entity (because only mains powered devices typically act as routers). For example, I have a Glassware Dimmer device and it has a sensor.glassware_dimmer_battery entity (so it’s an end device).

You can use template functions to check if a device has a sensor entity whose device_class is “battery” (and/or its entity_id contains the string “battery”).