###############################################################################
#   @author         :   Mahasri Kalavala
#   @date           :   04/15/2017
#   @package        :   WatchDog
#   @description    :   Watchdog Automations
###############################################################################

###############################################################################
#                _                        _   _                 
#     /\        | |                      | | (_)                
#    /  \  _   _| |_ ___  _ __ ___   __ _| |_ _  ___  _ __  ___ 
#   / /\ \| | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
#  / ____ \ |_| | || (_) | | | | | | (_| | |_| | (_) | | | \__ \
# /_/    \_\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/
#                                                                              
###############################################################################
automation:

# Garage:
# Working in Garage Mode Watch Dog - Turns off after 2 hours
###############################################################################
  - alias: Working In Garage WatchDog
    initial_state: true
    trigger:
      - platform: state
        entity_id:
          - input_boolean.working_in_garage
        to: 'on'
        for: 
          hours: 2
    action:
      - service: script.notify_me
        data: 
          message: "It has been two hours, are you still working in the garage? Changing the status to 'Not working'!"
      - service: input_boolean.turn_off
        entity_id: input_boolean.working_in_garage
  
# Garage:
# Keeps and eye on the garage door... reminds me to close after 5 min
###############################################################################
  - alias: Single Car garage Door WatchDog
    initial_state: true
    trigger:
      - platform: state
        entity_id:
          - binary_sensor.single_car_garage_door_tilt_sensor_sensor
        to: 'on'
        for: 
          minutes: 5
    condition:
      - condition: state
        entity_id: input_boolean.working_in_garage
        state: 'off'
    action:
      - service: script.notify_me
        data: 
          message: "Single Car Garage Door is OPEN for more than 5 minutes!"
      - service: script.voice_notify
        data_template:
          message: "Attention! Your single car garage door is open for more than 5 minutes."

# Garage:
# Keeps and eye on the garage door... reminds me to close after 5 min
###############################################################################  
  - alias: Two Car garage Door WatchDog
    initial_state: true
    trigger:
      - platform: state
        entity_id:
          - binary_sensor.two_car_garage_door_tilt_sensor_sensor
        to: 'on'
        for: 
          minutes: 5
    condition:
      - condition: state
        entity_id: input_boolean.working_in_garage
        state: 'off'
    action:
      - service: script.notify_me
        data: 
          message: "Your Two Car Garage Door is OPEN for more than 5 minutes!"
      - service: script.voice_notify
        data_template:
          message: "Attention! Your two car garage door is open for more than 5 minutes."

# Front Yard:
# Keeps and eye on the front porch lights...
###############################################################################
  - alias: Frontyard Light WatchDog
    initial_state: true
    trigger:
      - platform: state
        entity_id:
          - switch.frontyard_light
        to: 'on'
        for:
          minutes: 5
    condition:
      - condition: state
        entity_id: sun.sun
        state: 'above_horizon'
    action:
      - service: switch.turn_off
        data_template:
          entity_id: "{{ trigger.entity_id }}"
      - service: script.notify_me
        data_template:
          message: >
            {{ trigger.to_state.attributes.friendly_name }} is ON during the day time. Saving power by turning it off!
  
# Back Yard:
# Keeps and eye on the patio lights...
###############################################################################
  - alias: Backyard Light WatchDog
    initial_state: true
    trigger:
      - platform: state
        entity_id:
          - switch.wemobackyardlightswitch
        to: 'on'
        for:
          minutes: 5
    condition:
      - condition: state
        entity_id: sun.sun
        state: 'above_horizon'
    action:
      - service: switch.turn_off
        data_template:
          entity_id: "{{ trigger.entity_id }}"
      - service: script.notify_me
        data_template:
          message: >
            {{ trigger.to_state.attributes.friendly_name }} is ON during the day time. Saving power by turning it off!
  
# Guest Bedroom:
# Keeps and eye on the Guest Bedroom 1 lights...
###############################################################################
  - alias: Guest Bedroom 1 Light WatchDog
    initial_state: true
    trigger:
      - platform: state
        entity_id:
          - switch.guest_bedroom
        to: 'on'
        for:
          minutes: 15
    action:
      - service: switch.turn_off
        data_template:
          entity_id: "{{ trigger.entity_id }}"

# Guest Bedroom 2:
# Keeps and eye on the Guest Bedroom 2 lights...
###############################################################################
  - alias: Guest Bedroom 2 Light WatchDog
    initial_state: true
    trigger:
      - platform: state
        entity_id:
          - switch.prayer_room
        to: 'on'
        for:
          minutes: 10
    action:
      - service: switch.turn_off
        data_template:
          entity_id: "{{ trigger.entity_id }}"
  
# Kids Bedroom:
# Keeps and eye on the Kids Bedroom lights...
###############################################################################
  - alias: Kids Bedroom Light WatchDog
    initial_state: true
    trigger:
      - platform: state
        entity_id:
          - switch.kids_bedroom
        to: 'on'
        for:
          minutes: 10
    action:
      - service: switch.turn_off
        data_template:
          entity_id: "{{ trigger.entity_id }}"