if there is only one dead node and the device entity_id’s are named consistently you could do the following in the entity_id section of the button press action:
- action: button.press
target:
entity_id: >
{% set dead_list = states | selectattr("entity_id", "search", "node_status") |
selectattr('state', 'in', 'dead, unavailable, unknown') |
map(attribute='entity_id') | list %}
{{ dead_list|replace('sensor', 'button')|replace('node_status', 'ping')}}
if there is more than one dead node at a time it gets more complicated. I’m not entirely sure it’s possible to iterate over a list in an action like that. At least I can’t think of a way off the top of my head.
But if there are more than one then you could ping the first dead node in the list, wait a bit then ping the next dead node in the list. which isn’t too hard since as long as the ping was successful the next node in the list will still be the new first node in the list.
so something like this:
repeat:
while:
- condition: template
value_template: >
{% set dead_count = states | selectattr("entity_id", "search", "node_status") |
selectattr('state', 'in', 'dead, unavailable, unknown') |
map(attribute='entity_id') | list | count %}
{{ dead_count | int > 0 }}
sequence:
- action: button.press
target:
entity_id: >
{% set dead_list = states | selectattr("entity_id", "search", "node_status") |
selectattr('state', 'in', 'dead, unavailable, unknown') |
map(attribute='entity_id') | list %}
{{ dead_list[0]|replace('sensor', 'button')|replace('node_status', 'ping')}}
- delay:
minutes: 5
there may be better ways to do it but I think that should get you started.
the concern will be that a dead node never comes back alive and the automation runs forever trying to revive the totally dead node and never gets past that node.
you can limit the number of times it runs to the number of original dead nodes so that would mitigate that situation:
repeat:
while:
- condition: template
value_template: >
{% set dead_count = states | selectattr("entity_id", "search", "node_status") |
selectattr('state', 'in', 'dead, unavailable, unknown') |
map(attribute='entity_id') | list | count %}
{{ dead_count | int > 0 }}
- condition: template
value_template: >
{% set dead_count = states | selectattr("entity_id", "search", "node_status") |
selectattr('state', 'in', 'dead, unavailable, unknown') |
map(attribute='entity_id') | list | count %}
{{ repeat.index <= dead_count }}
sequence:
- action: button.press
target:
entity_id: >
{% set dead_list = states | selectattr("entity_id", "search", "node_status") |
selectattr('state', 'in', 'dead, unavailable, unknown') |
map(attribute='entity_id') | list %}
{{ dead_list[0]|replace('sensor', 'button')|replace('node_status', 'ping')}}
- delay:
minutes: 5
all of that is totally untested tho.