#-------------------------------------------
# @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:
  ###################################
  ##  From IFTTT - Notifications
  ###################################
  - alias: 'Phyn ShutOff Notification'
    id: 78bbd270-ee1e-4b3d-80fd-44ce7c66dab5
    mode: single

    trigger:
      - platform: event
        #Sent from IFTTT Webhooks : {"action":"IFTTT_Phyn", "alert_type":" {{AlertType}}", "where":"{{SuggestedFixtures}}"}
        event_type: ifttt_webhook_received
        event_data:
          action: IFTTT_Phyn

    action:
      - service: script.notify_engine
        data:
          title: 'Phyn Leak Detection'
          value1: 'Phyn is sensing {{ trigger.event.data.alert_type }} and turned off the water.  Please verify {{ trigger.event.data.where }}.'
          who: 'parents'
          group: 'Phyn'
          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: ifttt.trigger
        data: {"event":"phyn_water_on"}

      - service: script.notify_engine
        data:
          title: 'Phyn Leak Detection'
          value1: 'Request Recieved. 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