Advertisement
uhma_s-pastebin

script

May 31st, 2022 (edited)
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.02 KB | None | 0 0
  1. # ############################################################
  2. #
  3. #  ESPHome - unavailable devices notification
  4. #
  5. #  Purpose:
  6. #   - finding unavailable espHome devices
  7. #   - sending text into a Telegram group with the names of the unavailable devices
  8. #
  9. # ############################################################
  10.  
  11. esphome_detect_unavailable_devices_main:
  12.   alias: Detect unavailable ESPHome devices
  13.   icon: mdi:controller-classic-outline
  14.   description: This script detects unavailable ESPHome devices
  15.   fields:
  16.     msg_title:
  17.       description: "The title of the notification"
  18.       advanced: true
  19.       required: true
  20.       example: "State change"
  21.       default: "default msg title"
  22.       # selector: text
  23.     msg_text:
  24.       description: "The message content"
  25.       advanced: true
  26.       required: true
  27.       example: "The light is on!"
  28.       default: "default msg text"
  29.     msg_receiver:
  30.       description: "The receiver of the message"
  31.       advanced: true
  32.       required: false
  33.       example: "admin"
  34.       default: "admin"
  35.   mode: queued
  36.   sequence:
  37.     - service: input_text.set_value
  38.       target:
  39.         entity_id: input_text.esphome_unavailable_devices_text
  40.       data:
  41.         value: >-
  42.           {%- set all_status_entities_list = states.binary_sensor | selectattr('state', 'in', ['unavailable', 'unknown', 'off']) | selectattr("entity_id", "match", "binary_sensor.l[0,2,9].*_status") | map(attribute="entity_id") | list -%}
  43.           {%- set all_status_entities_string=all_status_entities_list | join('\n- ') | regex_replace(find='_status', replace='', ignorecase=False)-%}
  44.           - {{ all_status_entities_string  }}
  45.     - service: script.tg_txt
  46.       data_template:
  47.         msg_title: "*{{ msg_title }}*"
  48.         msg_text: "DEBUG: {{ msg_text }} {{ states('input_text.esphome_unavailable_devices_text') }} ###"
  49.         msg_receiver: "{{ msg_receiver }}"
  50. # ############################################################
  51. #  END OF FILE
  52. # ############################################################
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement