Advertisement
phreaknes

Untitled

May 21st, 2025 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.12 KB | None | 0 0
  1. alias: Water Leak Automation
  2. mode: parallel
  3. max: 10
  4.  
  5. trigger:
  6.   - platform: state
  7.     entity_id: binary_sensor.water_leak_sensor_group
  8.     from: "off"
  9.     to: "on"
  10.  
  11. variables:
  12.   notification_tag_prefix: "leak_notify"
  13.  
  14. action:
  15.   - repeat:
  16.       sequence:
  17.         - variables:
  18.             active_leaks: >
  19.              {% set leaks = states.binary_sensor
  20.                 | selectattr('entity_id', 'match', 'binary_sensor.water_leak_sensor_')
  21.                 | selectattr('state', 'equalto', 'on') | list %}
  22.               {{ leaks }}
  23.  
  24.         - choose:
  25.             - conditions:
  26.                 - condition: template
  27.                   value_template: "{{ active_leaks | length > 0 }}"
  28.               sequence:
  29.                 - repeat:
  30.                     for_each: "{{ active_leaks }}"
  31.                     sequence:
  32.                       - variables:
  33.                           sensor_id: "{{ repeat.item.entity_id }}"
  34.                           leak_name: "{{ repeat.item.name or sensor_id.split('.')[-1] }}"
  35.                           tag: "{{ notification_tag_prefix }}_{{ sensor_id.split('.')[-1] }}"
  36.  
  37.                       - service: notify.mobile_app_s21
  38.                         data:
  39.                           message: "Water leak detected at {{ leak_name }}. Shut off Water main?"
  40.                           title: "🚨 Water Leak Alert"
  41.                           data:
  42.                             tag: "{{ tag }}"
  43.                             actions:
  44.                               - action: "SHUTOFF_{{ tag }}"
  45.                                 title: "Yes, Shut Off"
  46.                               - action: "IGNORE_{{ tag }}"
  47.                                 title: "No"
  48.  
  49.                       - wait_for_trigger:
  50.                           platform: event
  51.                           event_type: mobile_app_notification_action
  52.                         timeout: "00:10:00"
  53.                         continue_on_timeout: true
  54.  
  55.                       - choose:
  56.                           - conditions:
  57.                               - condition: template
  58.                                 value_template: >
  59.                                  {{ wait.trigger is defined and wait.trigger.event.data.action == 'SHUTOFF_' + tag }}
  60.                             sequence:
  61.                               - service: switch.turn_off
  62.                                 target:
  63.                                   entity_id: switch.main_water_shutoff
  64.                               - wait_for_trigger:
  65.                                   - platform: state
  66.                                     entity_id: switch.main_water_shutoff
  67.                                     to: "off"
  68.                                     timeout: "00:01:00"
  69.                               - service: notify.mobile_app_s21
  70.                                 data:
  71.                                   message: "✅ Main water was shut off due to leak at {{ leak_name }}"
  72.                                   title: "Water Shutoff Executed"
  73.  
  74.         - delay: "00:10:00"
  75.  
  76.       until:
  77.         - condition: state
  78.           entity_id: binary_sensor.water_leak_sensor_group
  79.           state: "off"
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement