###############################################################################
#   @author         :   Jeffrey Stone 
#   @date           :   06/10/2020
#   @package        :   Camera
#   @description    :   All the Camera related stuff 
###############################################################################

#######################################################################
# Using the HACS Arlo Integration
# If you see the cloudflare error in the logs uncomment the user_agent line and try that
#
# Also, Don't forget to add the Camera section below.  
aarlo:
  host: https://my.arlo.com
  username: !secret arlo_user
  password: !secret arlo_pass
  db_motion_time: 30
  db_ding_time: 10
  recent_time: 10
  last_format: '%m-%d %H:%M'
  refresh_devices_every: 2
  verbose_debug: True
  tfa_host: 'imap.gmail.com'
  tfa_username: !secret GV_USER
  tfa_password: !secret GV_PASS
  #user_agent: linux

# Arlo Integration
alarm_control_panel:
  # Uses the custom arlo integration found in HACS
  - platform: aarlo
    home_mode_name: home
    away_mode_name: Armed
  
sensor:
  - platform: aarlo
    monitored_conditions:
    - last_capture
    - total_cameras
    - battery_level
    - captured_today
    - signal_strength

binary_sensor:
  - platform: aarlo
    monitored_conditions:
    - motion
    - sound
    - ding

input_boolean:
  backyard_motion:
    name: Backyard Motion
    icon: mdi:motion-sensor

# Dont forget the Camera - Commented out because its really defined below. 
# camera:
#   - platform: aarlo
#     ffmpeg_arguments: '-pred 1 -q:v 2'

#######################################################################

camera:
  - platform: aarlo
    ffmpeg_arguments: '-pred 1 -q:v 2'
  - platform: ffmpeg
    input: !secret livingroom_cam # wyze cam v2
    name: livingroom camera
  - platform: ffmpeg
    input: !secret kitchen_cam # wyze cam v2
    name: kitchen camera
  - platform: ffmpeg
    input: !secret theater_cam # wyze cam v2
    name: theater camera
  - platform: ffmpeg
    input: !secret laundry_cam # wyze cam v2
    name: laundry camera
  - platform: ffmpeg
    name: "Backyard Ezviz"
    input: !secret ezviz_c8c 
ffmpeg:
  ffmpeg_bin: /usr/bin/ffmpeg  

image_processing:
  - platform: doods
    url: http://192.168.7.187:8080
    detector: default
    scan_interval: 10000
    source:
      - entity_id: camera.c8c_f88801557
      - entity_id: camera.reolinkduo_profile000_mainstream
      - entity_id: camera.reolinkduo_profile010_mainstream
    file_out:
      - "/media/images/{{ camera_entity.split('.')[1] }}_latest.jpg"
    labels:
      - name: person
        confidence: 50

  
script:
  backyard_motion:
    sequence:
    - condition: state
      entity_id: input_boolean.backyard_motion
      state: 'off' 
    - service: input_boolean.turn_on
      entity_id: input_boolean.backyard_motion
    - delay: '00:01:00'
    - service: input_boolean.turn_off
      entity_id: input_boolean.backyard_motion

automation:
  - id: someone_on_your_deck
    alias: Someone On Your Deck
    initial_state: true
    trigger:
    # When the current time matches input_datetime.halloween_show, light this candle
    - platform: state
      entity_id: input_boolean.backyard_motion
      to: 'on'
      from: 'off'
    action:
    - service: script.text_notify
      data:
        who: "jeff"
        message: "Wanker in the living room...I mean on the Back Deck"        