###############################################################################
#   @author         :   Mahasri Kalavala
#   @date           :   09/20/2018
#   @package        :   scripts
#   @description    :   All my scripts are here in one place. Well, not ALL!
################################################################################
#    _____           _       _
#   / ____|         (_)     | |
#  | (___   ___ _ __ _ _ __ | |_ ___
#   \___ \ / __| '__| | '_ \| __/ __|
#   ____) | (__| |  | | |_) | |_\__ \
#  |_____/ \___|_|  |_| .__/ \__|___/
#                     | |
#                     |_|
################################################################################

homeassistant:
  customize:
    script.all_indoor_lights_off:
      friendly_name: All Indoor Lights & Switches OFF
    script.home_status:
      friendly_name: Home Status (Hourly Report)
    script.home_mode_away:
      friendly_name: Set Home Mode to AWAY
    script.good_night_tts:
      friendly_name: Good Night TTS Report

script:
  toggle_do_not_disturb:
    sequence:
      - service: input_boolean.toggle
        entity_id: input_boolean.do_not_disturb

  play_ringtone:
    sequence:
      - service: xiaomi_aqara.play_ringtone
        data:
          gw_mac: !secret xiaomi_mac
          ringtone_id: 10
          ringtone_vol: 30

  play_fav_song:
    sequence:
      - service: media_player.volume_set
        entity_id: media_player.living_room, media_player.upstairs
        data:
          volume_level: "0.15"
      - service: media_player.play_media
        data:
          entity_id: media_player.living_room, media_player.upstairs
          media_content_id: !secret fav_song_url
          media_content_type: "music"

  play_dog_sounds:
    sequence:
      - service: media_player.volume_set
        entity_id: media_player.living_room, media_player.upstairs
        data:
          volume_level: "1.0"
      - service: media_player.play_media
        data:
          entity_id: media_player.living_room, media_player.upstairs
          media_content_id: !secret dog_sound_url
          media_content_type: "music"
      - delay: "00:00:05"
      - service: media_player.play_media
        data:
          entity_id: media_player.living_room, media_player.upstairs
          media_content_id: !secret dog_sound_url
          media_content_type: "music"
      - delay: "00:00:05"
      - service: media_player.play_media
        data:
          entity_id: media_player.living_room, media_player.upstairs
          media_content_id: !secret dog_sound_url
          media_content_type: "music"

  home_mode_away:
    sequence:
      - service: script.all_indoor_lights_off
      - service: input_boolean.turn_on
        entity_id: input_boolean.camera_alerts
      - service: alarm_control_panel.alarm_arm_away
        data:
          entity_id: alarm_control_panel.home
      - service: script.notify_family
        data:
          message: >
            No one is at home. Cameras rolling, Indoor lights are OFF. Your home security system is turned ON!
          notify_options:
            - telegram

  ###############################################################################
  # The following script runs when no one is home. It excludes some lights
  # and switches like front porch and backyard lights...etc for safety reasons.
  ###############################################################################
  all_indoor_lights_off:
    sequence:
      - service: light.turn_off
        data_template:
          entity_id:
            - light.family_room_lights
            - light.hue_color_lamp_1
            - light.hue_color_lamp_2
            - light.hue_color_lamp_3
            - light.master_bedroom_1
            - light.master_bedroom_2
            - light.master_bedroom_lights

      - service: switch.turn_off
        data_template:
          entity_id:
            - switch.basement_left
            - switch.basement_right
            - switch.front_room
            - switch.garage
            - switch.garage_shop_lights
            - switch.srinika_bedroom
            - switch.hasika_bed_accent
            - switch.hasika_bedroom
            - switch.kitchen_switch
            - switch.office_room
            - switch.guest_room
            - switch.officeroom_accent_lights
            - switch.chromecast_monitor
            - switch.master_bathroom_lights

  xiaomi_red:
    sequence:
      - service: light.turn_on
        data:
          entity_id: light.gateway_light_34ce008ad65d
          brightness: 255
          rgb_color: [255, 0, 0]

  xiaomi_blue:
    sequence:
      - service: light.turn_on
        data:
          entity_id: light.gateway_light_34ce008ad65d
          brightness: 255
          rgb_color: [0, 0, 255]

  xiaomi_green:
    sequence:
      - service: light.turn_on
        data:
          entity_id: light.gateway_light_34ce008ad65d
          brightness: 255
          rgb_color: [0, 255, 0]

  ###############################################################################
  # Status of the house
  ###############################################################################
  home_status:
    sequence:
      - service: script.notify_family
        data_template:
          message: !include ../templates/home_status.yaml
          notify_options:
            - voice

  good_night_tts:
    sequence:
      - service: script.notify_family
        data_template:
          message: !include ../templates/goodnight.yaml
          notify_options:
            - voice
