Service test.zwave_node with several nodes?

Hi everyone,

I want to have an automation to regularly test dead nodes. I have a few which regularly get marked as dead but after a test they communicate again.

- alias: "Z-Wave: Test dead nodes regularly"
  trigger:
    - platform: time
      at: "01:03:00"
    - platform: time
      at: "13:01:00"
  condition:
    - condition: state
      entity_id: binary_sensor.zwave_failed_nodes
      state: 'on'
  action:
    - service: zwave.test_node
      data_template:
        node_id: >
          {{states.zwave|selectattr("state","eq","dead")|map(attribute='attributes.node_id')|join(',') }}
        messages: 5

When i run it i get
expected int for dictionary value @ data['node_id']

I have some other automations working with the same syntax except that the service parameter that gets a list is entity_id instead of node_id.

Anyone knows of a good way to keep this simple and working? Wanted to avoid testing the entire network, hardcoding values or going for appdaemon. I’m not being able to find a solution.

Thanks alot!

Node_id only accepts a single integer. You have to duplicate the services for each node.

1 Like

you know if there’s anyway to do it without hardcoding node id’s?

Yes, just use a template that returns a single integer.

fwiw you can make a python script to do this.

Script.

Make a new folder inside config called 'python_scripts`… <config>/python_scripts/
Then make the following file: zwave_test_node.py

contents:

msg_dflt = 5

nodes = data.get('nodes')
messages = data.get('messages', msg_dflt)

try:
    messages = int(messages)
except ValueError:
    messages = msg_dflt

if nodes is not None:
    strnodes = [ node.strip() for node in nodes.split(',') ]
    nodes = []
    for n in strnodes :
        try:
            nodes.append(int(n))
        except ValueError:
            logger.warning("Invalid node integer {}".format(n))

    if nodes:
        for node in nodes:
            service_data = {'node_id':node, 'messages':messages}
            hass.services.call('zwave','test_node', service_data, False)

Then your automation:

- alias: "Z-Wave: Test dead nodes regularly"
  trigger:
    - platform: time
      at: "01:03:00"
    - platform: time
      at: "13:01:00"
  condition:
    - condition: state
      entity_id: binary_sensor.zwave_failed_nodes
      state: 'on'
  action:
    - service: python_script.zwave_test_node
      data_template:
        node: >
          {{states.zwave|selectattr("state","eq","dead")|map(attribute='attributes.node_id')|join(',') }}
        messages: 5

EDIT: This script should run on all dead nodes. Pretty much what you want but it has to use python scripts instead of the normal UI.

2 Likes

Offtopic slightly- Dead nodes is a symptom of RF issues. This is fixing the symptom but not the cause (you shouldn’t get dead nodes to begin with).

Additional mains powered devices or moving the stick around can improve things 100%. (Additionally you may see high RTT on these nodes that go dead due to weak RF signals - fixing your RF would probably give a better overall experience)

1 Like

Awesome, I had looked into some options but didn’t even consider the python scripts. Thanks alot.

Thanks for the feedback.

What you are saying makes total sense as the nodes that keep dying are the ones further away from the controller. Unfortunatelly my server is located at the office (northern edge of my property) and the weak nodes are on the garden (south). Long way to go and lot’s of walls and non zwave devices in between. I have tried to get some neighbour devices for these nodes but so far without good sucess.

So trying to get some workarounds in place. :slight_smile: