#-------------------------------------------
# @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# Phyn Smart Water ShutOff Support
# https://www.vcloudinfo.com/2020/05/phyn-plus-smart-water-shutoff-device.html
# Added in Custom HACK integration via https://github.com/MizterB/homeassistant-phyn
#-------------------------------------------
######################################################################
##  Phyn Plus Water ShutOff - https://amzn.to/2Zy3sbJ
######################################################################

automation:
  - alias: 'Phyn ShutOff Notification'
    id: 78bbd270-ee1e-4b3d-80fd-44ce7c66dab5
    mode: single

    trigger:
      - platform: state
        entity_id: switch.phyn_shutoff_valve
        to: 'off'

    condition:
      - condition: time
        before: '03:00'
        after: '05:00'

    action:
      - service: script.notify_engine_two_button
        data:
          title: 'Phyn Leak Detection'
          value1: 'Phyn is sensing a leak and turned off the water.  Please verify.'
          who: 'parents'
          group: 'Phyn'
          action1: 'PHYN_WATER_ON'
          action2: 'SNOOZE_PHYN_NOTIFICATION'
          icon1: 'sfsymbols:arrow.up.circle'
          icon2: 'sfsymbols:clock'
          level: 'critical'

  - alias: Turn Phyn Water On
    id: 1f295bb8-8925-4b22-PHYN-9fe079b295a8
    trigger:
      platform: event
      event_type: mobile_app_notification_action
      event_data:
        action: PHYN_WATER_ON
    action:
      - service: homeassistant.turn_on
        entity_id: switch.phyn_shutoff_valve

      - service: script.notify_engine
        data:
          title: 'Phyn Leak Detection'
          value1: 'Request Received. Attempting to Turn the Water back on.'
          who: 'parents'
          group: 'Phyn'
          level: 'time-sensitive'

      - service: script.speech_engine
        data:
          value1: >
            I have been asked to Turn the House Water back on.  Please verify there are no leaks in the house.
          call_no_announcement: 1

  - alias: Snooze Phyn Notification
    id: 2f295bb8-8925-4b22-PHYN-9fe079b295a8
    trigger:
      platform: event
      event_type: mobile_app_notification_action
      event_data:
        action: SNOOZE_PHYN_NOTIFICATION
    action:
      - delay: '00:30:00'
      - service: script.notify_engine_two_button
        data:
          title: 'Phyn Leak Detection'
          value1: 'Phyn is sensing a leak and turned off the water.  Please verify.'
          who: 'parents'
          group: 'Phyn'
          action1: 'PHYN_WATER_ON'
          action2: 'SNOOZE_PHYN_NOTIFICATION'
          icon1: 'sfsymbols:arrow.up.circle'
          icon2: 'sfsymbols:clock'
          level: 'critical'