homeassistant:
  customize:
    binary_sensor.tesla_model_3_charger_sensor:
      friendly_name: Charger
    binary_sensor.tesla_model_3_parking_brake_sensor:
      friendly_name: Parking Break
    climate.tesla_model_3_hvac_climate_system:
      friendly_name: Tesla Climate
    device_tracker.mahasri_tesla_location_tracker:
      friendly_name: Tesla
    lock.tesla_model_3_charger_door_lock:
      friendly_name: Tesla Door Lock
    sensor.tesla_model_3_battery_sensor:
      friendly_name: Battery Percentage
      icon: mdi:battery
    sensor.tesla_model_3_mileage_sensor:
      friendly_name: Total Mileage
    sensor.tesla_model_3_range_sensor:
      friendly_name: Battery Range
    sensor.tesla_model_3_temperature_sensor_inside:
      friendly_name: Temperature Inside
    sensor.tesla_model_3_temperature_sensor_outside:
      friendly_name: Temperature Outside
    switch.tesla_model_3_charger_switch:
      friendly_name: Charger Switch
    switch.tesla_model_3_maxrange_switch:
      friendly_name: Max Range Switch
    switch.tesla_model_3_update_switch:
      friendly_name: Update Tesla

# The scan_interval is now set to 6 hours
# Leaving it to the default (which is 5 minutes, or 300 seconds) will drain battery at a rate of
# 10 miles per day (or 3% battery use) on an average. Use this setting carefully!

tesla:
  username: !secret tesla_username
  password: !secret tesla_password
  scan_interval: 21600

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

automation:
  - alias: Notify Charging Status
    initial_state: true
    trigger:
      - platform: state
        entity_id: binary_sensor.tesla_model_3_charger_sensor
    action:
      - service: script.notify_me
        data_template:
          message: "Tesla Car Charge Status changed to: {{ trigger.to_state.state| upper }}"

  - alias: Notify Door Status
    initial_state: true
    trigger:
      - platform: state
        entity_id: lock.tesla_model_3_door_lock
    condition:
      - condition: template
        value_template: '{{ trigger.from_state.state | lower != "unknown" }}'
    action:
      - service: script.notify_me
        data_template:
          message: "Tesla Door is now: {{ trigger.to_state.state | upper }}"

  - alias: Notify Charger Switch State
    initial_state: true
    trigger:
      - platform: state
        entity_id: switch.tesla_model_3_charger_switch
    condition:
      - condition: template
        value_template: '{{ trigger.from_state.state | lower != "unknown" }}'
    action:
      - service: script.notify_me
        data_template:
          message: "Tesla Door is now: {{ trigger.to_state.state| upper }}"
