From 7f3407383a81e68dc491d935400fef7ea4332452 Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Fri, 15 Dec 2023 14:04:10 +0100 Subject: [PATCH] Add Unavailable notice for Z-Wave devices --- HELP.md | 11 +++++++ .../automations/info-unavailable-notice.yaml | 18 ----------- home-assistant.yml | 13 +++++++- templates/unavailable-zwave.yaml.j2 | 16 ++++++++++ zwave-devices.yml | 31 +++++++++++++++++++ 5 files changed, 70 insertions(+), 19 deletions(-) delete mode 100644 configuration/automations/info-unavailable-notice.yaml create mode 100644 templates/unavailable-zwave.yaml.j2 create mode 100644 zwave-devices.yml diff --git a/HELP.md b/HELP.md index 2c53745..9c422cf 100644 --- a/HELP.md +++ b/HELP.md @@ -8,3 +8,14 @@ {% endfor %} {{ ns.result }} ``` + +# List Z-wave entities fot checking unavailability +You need to enable node_status for each device, and they need to have `node_status` suffix +``` +{% set ids = integration_entities('zwave_js') | select('search', 'node_status$') | unique | list %} +{% set ns = namespace(result=[]) %} +{% for s in ids %} + {% set ns.result = ns.result + [ [s, device_attr(s, 'name_by_user')] ] %} +{% endfor %} +{{ ns.result }} +``` diff --git a/configuration/automations/info-unavailable-notice.yaml b/configuration/automations/info-unavailable-notice.yaml deleted file mode 100644 index e126cde..0000000 --- a/configuration/automations/info-unavailable-notice.yaml +++ /dev/null @@ -1,18 +0,0 @@ -- id: info_unavailable_notice - alias: '[INFO] Unavailable notice' - description: '' - mode: single - trigger: - # Kitchen tabletop motion (Z-Wave) - - platform: device - device_id: c7bb75d230dd4f8a5b7ece910f00c583 - domain: zwave_js - type: state.node_status - entity_id: sensor.node_6_node_status - to: dead - action: - - service: notify.mobile_app_iphone - data: - title: "Device unavailable" - message: > - {{ device_attr(trigger.event.data.device_id, 'name_by_user') }} is unavailable diff --git a/home-assistant.yml b/home-assistant.yml index d628c5a..b57f74c 100644 --- a/home-assistant.yml +++ b/home-assistant.yml @@ -39,13 +39,24 @@ include_vars: file: zha-devices.yml name: zha - - name: Build unavailable automations + - name: Build unavailable automations ZHA delegate_to: localhost template: src: unavailable-zha.yaml.j2 dest: './build/automations/unavailable-zha.yaml' vars: devices: "{{ zha.devices }}" + - name: Include Z-wave vars + include_vars: + file: zwave-devices.yml + name: zwave + - name: Build unavailable automations Z-Wave + delegate_to: localhost + template: + src: unavailable-zwave.yaml.j2 + dest: './build/automations/unavailable-zwave.yaml' + vars: + devices: "{{ zwave.devices }}" - name: Build spices shopping automations delegate_to: localhost template: diff --git a/templates/unavailable-zwave.yaml.j2 b/templates/unavailable-zwave.yaml.j2 new file mode 100644 index 0000000..84e2ca8 --- /dev/null +++ b/templates/unavailable-zwave.yaml.j2 @@ -0,0 +1,16 @@ +- id: info_zwave_unavailable_notice + alias: '[INFO][Z-Wave] Device offline' + mode: single + trigger: + - platform: state + to: dead + entity_id: +{% for device in devices %} + - {{ device.entity_id }} # {{ device.name }} +{% endfor %} + action: + - service: notify.mobile_app_iphone + data: + title: "Device unavailable" + message: > + {% raw %}{{ device_attr(device_id(trigger.event.data.device_id), 'name_by_user') }}{% endraw %} is unavailable diff --git a/zwave-devices.yml b/zwave-devices.yml new file mode 100644 index 0000000..7a14c49 --- /dev/null +++ b/zwave-devices.yml @@ -0,0 +1,31 @@ +devices: + - name: '3D Printer' + entity_id: 'sensor.3d_printer_node_status' + - name: 'Kitchen tabletop motion' + entity_id: 'sensor.kitchen_tabletop_node_status' + - name: 'Dining Motion Sensor' + entity_id: 'sensor.dining_motion_sensor_node_status' + - name: 'Printer Switch' + entity_id: 'sensor.printer_switch_node_status' + - name: Siren Alarm + entity_id: 'sensor.siren_alarm_node_status' + - name: 'Kitchen Motion Sensor' + entity_id: 'sensor.kitchen_motion_sensor_node_status' + - name: 'Bathroom Thermostat' + entity_id: 'sensor.bathroom_thermostat_node_status' + - name: '3D Printer Smoke Sensor' + entity_id: 'sensor.3d_printer_smoke_sensor_node_status' + - name: 'Kitchen Big Light' + entity_id: 'sensor.kitchen_big_light_node_status' + - name: 'Doorbell' + entity_id: 'sensor.doorbell_node_status' + - name: Door Window Sensor + entity_id: 'sensor.door_window_sensor_node_status' + - name: 'Coffee machine leak' + entity_id: 'sensor.flood_coffee_machine_leak_node_status' + - name: 'AC Power' + entity_id: 'sensor.ac_power_node_status' + - name: 'Office Thermostat' + entity_id: 'sensor.office_thermostat_node_status' + - name: 'Dining Thermostat' + entity_id: 'sensor.dining_thermostat_node_status'