How to count the number of zwave hardware devices

Before updating to zwave js I was able to the number of hardware devices by the following. After updating my zwave networke zwave js I get 0. Can someone point me to how to change this to count zwave js hardware devices. Thanks


      count_zwave_devices:
        friendly_name: 'ZWave'
        icon_template: mdi:z-wave
        value_template: >
          {%- set domains = ['zwave'] -%}
          {%- for domain in domains -%}
            {%- for item in states[domain] -%}
              {% if loop.first %}
                {{loop.length}}
              {% endif %}
            {%- endfor -%}
          {%- endfor -%}

As far as I know there is no way to do that directly.

But I think you could do that in a bit more round about way:

First you’ll need to make sure that the “node Status” sensor is enabled for all of your entities. It’s a good bit of info to have even outside of this.

then you can use the following to get the count of devices since each device has a node status sensor:

{% for state in states if (state.entity_id.find("node_status") | int>=0) %}
  {% if loop.first %}
    {{loop.length}}
  {% endif %}
{% endfor %}

Thank you…it only found one device :frowning_face:

The node status sensor is disabled by default so you need to manually enable all of them.

Something to check.

is this what you are talking about?

no.

it will be listed under the disabled entities at the bottom of that box.

But you also need to make sure it has the words “node_status” in the entity_id.

it should have that by default but just check to be sure.

Thank you so much that worked, now I’ll go thru all my zwave devices and change that

Now that you’ve got that working there is another form of a template that I’m going to use (credit goes to Rob Colman and Taras as a by-product in another thread):

you can use this to get the number of nodes:

{{ states|selectattr('object_id', 'search', 'node_status')|list|count }}

You can also create a sensor to give you the number of alive nodes out of the total number of nodes:

{% set total = states|selectattr('object_id', 'search', 'node_status')|list|count %}
{% set dead = states|selectattr('object_id', 'search', 'node_status')|selectattr('state', 'in', 'dead, unavailable, unknown') | list | count %}
{{ total - dead }} Alive/{{ total }} Total

it will return a value of something like “27 Alive/29 Total” if you have 2 dead nodes.

Thank you very very much, I’ll give that a try also

1 Like