Advertisement
GrzegorzM

ZWaveJS - PING dead nodes

Feb 19th, 2023
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.30 KB | None | 0 0
  1. ##############################################################################
  2. # Automation requirements: all z-wave devices should contain
  3. # enabled 'sensor.*_node_status' and 'button.*_ping' entities
  4. # This automation is pressing ping button up to 5 times every 15 seconds until
  5. # a node becomes alive. The automation is queued to avoid zwave network traffic jam.
  6. alias: Z-Wave - PING dead nodes
  7. description: ""
  8. trigger:
  9.   - platform: state
  10.     entity_id:
  11.      - sensor.myot_node_status
  12.       - sensor.panel_alarmu_node_status
  13.       - sensor.roleta_agatka_dach_node_status
  14.       - sensor.termostat_zuzia_node_status
  15.     to: dead
  16. condition: []
  17. action:
  18.   - repeat:
  19.       while: '{{ states(trigger.entity_id) == "dead" and repeat.index <= 5 }}'
  20.       sequence:
  21.         - service: persistent_notification.create
  22.           data:
  23.             title: 'Waking up - {{ states("sensor.date_time") }}'
  24.             message: '{{ device_attr(device_id(trigger.entity_id), "name") }} - try no. {{ repeat.index }}'
  25.         #use ping buttons as the service wave_js.ping is deprecated
  26.         - service: button.press
  27.           target:
  28.             entity_id: '{{ trigger.entity_id | regex_replace(find="sensor.(.*)_node_status", replace="button.\\1_ping", ignorecase=False) }}'
  29.         - wait_template: '{{ states(trigger.entity_id) == "alive" }}'
  30.           timeout:
  31.             seconds: 15
  32. mode: queued
  33.  
  34. ######################################################################
  35. # Template to collect _node_status entities for non-battery powered z-wave devices
  36. # Pinging battery powered devices repeatedly is not good idea as they need to be woken up.
  37. # The output of this temlate can be used in the trigger definition of the automation above.
  38. # Using the template in the trigger or in a template sensor is not recommended because
  39. # it will be executed on each state change of each z-wave entity causing resource loss.
  40. {% set all_nodes = expand(integration_entities('Z-Wave JS') ) |
  41.   selectattr('entity_id', 'search', 'node_status') |
  42.    map(attribute='entity_id') | list %}
  43. {%- set ns = namespace(entities = []) %}
  44. {% for n in all_nodes %}
  45.   {% if states(n.split('_node')[0] + '_battery_level') == 'unknown' %}
  46.      {% set ns.entities = ns.entities + [n] %}
  47.   {% endif %}
  48. {% endfor %}
  49. - {{ns.entities | join('\n- ')}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement