Automatic ZWave node heal + notification, but for all nodes

I found this old-archived threat where they describe a way to heal + get a notification each time ZWave node change into “dead” state:

https://www.reddit.com/r/homeassistant/comments/7mr3o6/how_can_i_do_an_automatic_node_heal_if_a_device/

The code is as as follow:

- alias: Heal 'Dead' Nodes
  trigger:
    platform: state
    entity_id: zwave.upper_stair_lights
    to: 'dead'
  action:
    - service: zwave.heal_node
      data:
        node_id: 11
    - condition: state
      entity_id: zwave.upper_stair_lights
      state: 'dead'
    - service: notify.ios_my_iphone
      data:
        message: 'Node heal failed'

Question is: how can I achieve the same but in a more generic way? I have multiple ZWave devices, so I want an automation that can do the same for each device without having to create 1 entry per device.

Any idea?

Thanks!

I’ve got a sensor setup to detect when a zwave node fails. After 5 minutes, I have an automation run to do the repair. The automation may need some improvement. It only runs once if the node is dead.

sensor:
  - platform: template
    sensors:
      zwave_failures:
        entity_id:
          - zwave.back_porch
          - zwave.bubble
          - zwave.bubble_closet
          - zwave.bubble_fan
          - zwave.cat_door
          - zwave.dining_room
          - zwave.dryer
          - zwave.foyer
          - zwave.front_porch
          - zwave.fuzzy_lane
          - zwave.fuzzy_lane_closet
          - zwave.fuzzy_lane_fan
          - zwave.hall_bar
          - zwave.hall_bath
          - zwave.kitchen
          - zwave.kitchen_bar
          - zwave.living_room
          - zwave.living_room_fan
          - zwave.master_bath_toilet
          - zwave.master_bath_vanity
          - zwave.mermaid_room
          - zwave.mermaid_room_closet
          - zwave.mermaid_room
          - zwave.music_room
          - zwave.music_room_fan
          - zwave.music_room_outlet
          - zwave.unknown_node_33
        friendly_name: "Z-Wave Dead Nodes"
        value_template: >
          {% macro is_failed() %}
          {%- set value = true -%}
          {%- set domains = ['zwave'] -%}
          {%- for domain in domains -%}
          {%- for item in states[domain] if ((item.attributes.is_failed is defined and item.attributes['is_failed'] == value))-%}
          {% if (item.attributes.is_failed is defined and item.attributes['is_failed'] == value) -%}
          {{ item.name }}{% endif -%}
          {%- endfor -%}
          {%- endfor -%}
          {% endmacro %}
          {{ is_failed() |trim != "" }}

binary_sensor:
  - platform: template
    sensors:
      zwave_fix:
        friendly_name: "Z-Wave Auto Repair"
        icon_template: mdi:z-wave
        delay_on:
          seconds: 300
        value_template: "{{ is_state('sensor.zwave_failures', 'True') }}"

automation:
  - alias: 'zwave auto repair after 5 minutes'
    initial_state: 'on'
    trigger:
      platform: state
      entity_id:
        - binary_sensor.zwave_fix
      to: 'on'
    action:
      - service: zwave.test_network