Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 106357

Automation last seen notification zwave devices

$
0
0

I’m trying to create an automation that triggers if a device has not been seen for 48 hours, then check the device is still unresponsive with a zwave js ping. If still unresponsive then send a notification. However the action stops at the stage before sending notification.


Hopefully someone can point out where I am going wrong. Code is below.

alias: Z-Wave Device Alert with Ping (Z-Wave JS)
description: >
  Ping Z-Wave devices before sending notifications if they haven't been seen in
  over 48 hours.
triggers:
  - entity_id:
      - sensor.z_wave_error_devices
    for:
      hours: 0
      minutes: 0
      seconds: 1
    trigger: state
  - at: "08:00:00"
    trigger: time
conditions:
  - condition: template
    value_template: >
      {{ 'All devices are active' not in states('sensor.z_wave_error_devices')
      }}
actions:
  - variables:
      error_devices: >
        {{ states('sensor.z_wave_error_devices').replace(', ', ',').split(',')
        }}
  - target:
      entity_id: "{{ error_devices }}"
    action: zwave_js.ping
  - delay: "00:01:00"
  - variables:
      still_unresponsive: |
        {% set unresponsive = [] %} {% for device in error_devices %}
          {% set last_seen = states(device ~ '_last_seen') %}
          {% if last_seen != 'unknown' and last_seen != '' %}
            {% if (now() - (last_seen | as_datetime)).total_seconds() > 172800 %}
              {% set unresponsive = unresponsive + [device] %}
            {% endif %}
          {% endif %}
        {% endfor %} {{ unresponsive }}
  - condition: template
    value_template: "{{ still_unresponsive | length > 0 }}"
  - data:
      title: Z-Wave Device Alert
      message: >
        The following Z-Wave devices haven't been seen in over 48 hours and are
        still unresponsive after pinging: {% for device in still_unresponsive %}
          - {{ state_attr(device, 'friendly_name') or device }}
        {% endfor %}
    action: notify.matthew_and_sams_phone
  - data:
      title: Z-Wave Device Alert
      message: >
        The following Z-Wave devices haven't been seen in over 48 hours and are
        still unresponsive after pinging: {% for device in still_unresponsive %}
          - {{ state_attr(device, 'friendly_name') or device }}
        {% endfor %}
      notification_id: zwave_error_devices
    action: persistent_notification.create
mode: single

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 106357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>