#:########################################################################################:#
# TITLE: OUTSIDE ENTRANCE BLUETOOTH PROXY
# zorruno.com layout v1.1 2026
#:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-entbtproxy.yaml
#:########################################################################################:#
# VERSIONS:
# V1.1 2026-02-25 Updated yaml to zorruno layout V1.1
# V1.0 Unknown     Initial version
#:########################################################################################:#
# HARDWARE:
# - D1 Mini ESP32 (ESP32)
#:########################################################################################:#
# OPERATION NOTES:
# - Bluetooth Proxy for ESPHome / Home Assistant (BLE tracking + proxy)
# - Uses ESP-IDF framework for stability and (often) smaller binary size
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
#    - BLE scanning/proxy continues running
#    - HA entities unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
#    - BLE scanning/proxy continues running
#    - MQTT features (if any) will not function until MQTT returns
# c) Entire WiFi/Network OFFLINE
#    - No HA API and no MQTT control available
#    - BLE scanning continues locally, but proxy functions needing network will not be usable
#    - Accurate time is NOT needed (SNTP not needed)
#:########################################################################################:#

#:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#:########################################################################################:#
substitutions:
  # Device Naming
  device_name: "esp-entbtproxy"
  friendly_name: "Outside Entrance Bluetooth Proxy"
  description_comment: "D1 Mini ESP32 outside entranceway with BT Proxy (Layout V1.1)"
  device_area: "Entranceway" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.

  # Project Naming
  project_name: "Generic.ESP32 Bluetooth Proxy"
  project_version: "v1.1"

  # Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
  api_key: !secret esp-entbtproxy_api_key
  ota_pass: !secret esp-entbtproxy_ota_pass
  static_ip_address: !secret esp-entbtproxy_ip

  # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
  # Don't forget to switch it back when changed.
  current_ip_address: ${static_ip_address}

  # Device Settings
  log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
  update_interval: "60s" # update time for general sensors etc

#:########################################################################################:#
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
#:########################################################################################:#
packages:
  #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
  common_wifi: !include
    file: common/network_common.yaml
    vars:
      local_device_name: "${device_name}"
      local_static_ip_address: "${static_ip_address}"
      local_ota_pass: "${ota_pass}"
      local_current_ip_address: "${current_ip_address}"

  #### HOME ASSISTANT API (choose encryption or no encryption options) ####
  common_api: !include
    file: common/api_common.yaml
    #file: common/api_common_noencryption.yaml
    vars:
      local_api_key: "${api_key}"

  #### MQTT ####
  common_mqtt: !include
    file: common/mqtt_common.yaml
    vars:
      local_device_name: "${device_name}"

  #### WEB PORTAL ####
  #common_webportal: !include common/webportal_common.yaml

  #### SNTP (Only use if you want/need accurate timeclocks) ####
  common_sntp: !include common/sntp_common.yaml

  #### DIAGNOSTICS Sensors ####
  diag_basic: !include common/include_basic_diag_sensors.yaml
  diag_more: !include common/include_more_diag_sensors.yaml
  diag_debug: !include common/include_debug_diag_sensors.yaml
  #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml

#:########################################################################################:#
# ESPHOME:
# https://esphome.io/components/esphome.html
#:########################################################################################:#
esphome:
  name: "${device_name}"
  friendly_name: "${friendly_name}"
  comment: "${description_comment}" # appears on the esphome page in HA
  area: "${device_area}"
  min_version: 2024.6.0
  project:
    name: "${project_name}"
    version: "${project_version}"

#:########################################################################################:#
# ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html
#:########################################################################################:#
esp32:
  board: esp32dev
  framework:
    type: esp-idf  # Suggested ESP-IDF framework
    version: recommended
    advanced:
      minimum_chip_revision: "3.1" # This makes the binary slightly smaller

#:########################################################################################:#
# LOGGING:
# https://esphome.io/components/logger.html
#:########################################################################################:#
logger:
  level: "${log_level}"
  #baud_rate: 0 # set to 0 for no logging via UART if you want

#:########################################################################################:#
# BLUETOOTH:
# https://esphome.io/components/bluetooth_proxy.html
# https://esphome.io/components/esp32_ble_tracker.html
#:########################################################################################:#
bluetooth_proxy:
  active: true

esp32_ble_tracker:
  scan_parameters:
    # Defaults used so Bluetooth can co-exist with WiFi
    active: true