How to iterate for every item in zigbee2mqtt devices?

Hello

How to iterate for every sensor in zigbee2mqtt devices ?
This is example sensor: sensor.0x00158d0405546b54_battery

It works, but I’d like to list all the sensors match Zigbee address 0x001xxxxxxxxx

{% for state in states.sensor -%}
{%- if state.attributes.battery %}
{{state}}
{%- endif -%}
{%- endfor %}

This should help you get started:

{% for state in states.sensor if state.object_id.startswith('0x001') %}
  {{ state.object_id }}
{% endfor %}

A bit more specific:

{% for state in states.sensor if state.object_id.startswith('0x001')  and state.object_id.endswith('battery')%}
  {{ state.object_id }}
{% endfor %}
1 Like

Perhaps this also might be of interest - will give you a list of all sensors on Z2M, you can then iterate over the list:

{{ states | selectattr('entity_id', 'in', integration_entities('mqtt')) | map(attribute='entity_id') | list }}

I don’t know if you realize it but the template you suggested reports a list of all entities managed by the MQTT integration. In other words, it’s the same as simply this:

{{ integration_entities('mqtt') }}

For omcdr’s application, three years later it’s now possible to do this:

{{ integration_entities('mqtt') | select('search', '^sensor\.0x001') | list }}