Check battery level from devices

Hi All,

I used this script when I used the Zwave integration in HA. Now using Zwave@MQTT and have different entities. This script I copied from here and really don’t understand the way how it work.

But now it is not working. All my Sensors have their own battery level entity:

sensor.node_01_battery_level
sensor.node_02_battery_level
sensor.node_03_battery_level
sensor.node_04_battery_level

Can someone assist me to change this code so it will read those entities and show me the output again?

  condition:
    - condition: template
      value_template: >-
        {% macro battery_level() %}
        {%- set threshold = 40 -%}
        {% set domains = ['zwave'] %}
        {% for domain in domains -%}
        {% for item in states[domain] if ((item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold) or ("battery" in item.name | lower and ((item.state | int < threshold and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown"))) -%}
        {% if (item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold) -%}
        {{ item.name }} ({{ item.attributes['battery_level'] }}){%- if not loop.last %}, {% endif -%}{% endif -%}
        {% if "battery" in item.name | lower and ((item.state | int < threshold and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown") -%}
        {{ item.name }} ({{ item.state }}){% if not loop.last %}, {%- endif %} {% endif -%}
        {% endfor %}
        {%- endfor %}
        {% endmacro %}
        {{ battery_level() |trim != "" }}