Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias: Water Leak Automation
- mode: parallel
- max: 10
- trigger:
- - platform: state
- entity_id: binary_sensor.water_leak_sensor_group
- from: "off"
- to: "on"
- variables:
- notification_tag_prefix: "leak_notify"
- action:
- - repeat:
- sequence:
- - variables:
- active_leaks: >
- {% set leaks = states.binary_sensor
- | selectattr('entity_id', 'match', 'binary_sensor.water_leak_sensor_')
- | selectattr('state', 'equalto', 'on') | list %}
- {{ leaks }}
- - choose:
- - conditions:
- - condition: template
- value_template: "{{ active_leaks | length > 0 }}"
- sequence:
- - repeat:
- for_each: "{{ active_leaks }}"
- sequence:
- - variables:
- sensor_id: "{{ repeat.item.entity_id }}"
- leak_name: "{{ repeat.item.name or sensor_id.split('.')[-1] }}"
- tag: "{{ notification_tag_prefix }}_{{ sensor_id.split('.')[-1] }}"
- - service: notify.mobile_app_s21
- data:
- message: "Water leak detected at {{ leak_name }}. Shut off Water main?"
- title: "🚨 Water Leak Alert"
- data:
- tag: "{{ tag }}"
- actions:
- - action: "SHUTOFF_{{ tag }}"
- title: "Yes, Shut Off"
- - action: "IGNORE_{{ tag }}"
- title: "No"
- - wait_for_trigger:
- platform: event
- event_type: mobile_app_notification_action
- timeout: "00:10:00"
- continue_on_timeout: true
- - choose:
- - conditions:
- - condition: template
- value_template: >
- {{ wait.trigger is defined and wait.trigger.event.data.action == 'SHUTOFF_' + tag }}
- sequence:
- - service: switch.turn_off
- target:
- entity_id: switch.main_water_shutoff
- - wait_for_trigger:
- - platform: state
- entity_id: switch.main_water_shutoff
- to: "off"
- timeout: "00:01:00"
- - service: notify.mobile_app_s21
- data:
- message: "✅ Main water was shut off due to leak at {{ leak_name }}"
- title: "Water Shutoff Executed"
- - delay: "00:10:00"
- until:
- - condition: state
- entity_id: binary_sensor.water_leak_sensor_group
- state: "off"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement