#:########################################################################################:#
# Package: Vehicle Announcements
# File:    vehicle_announcements.yaml
# Version: v1.1.0
# Date:    2026-07-26
#
# Purpose:
#   Sends vehicle arrival announcements through the View Road announcement router.
#   Requires the vehicle to have been continuously away for 20 minutes before
#   announcing, suppressing short Bluetooth range dropouts while parked at home.
#:########################################################################################:#

automation:
  - id: byd_atto3_arrival_announcement
    alias: "BYD Atto 3 - Arrival Announcement"
    description: >
      Sends a Pushover notification to the Zorruno phone when the BYD Atto 3
      Bermuda tracker arrives home after at least 20 minutes away.
    mode: single
    variables:
      minimum_away_minutes: 20
    triggers:
      - trigger: state
        entity_id: device_tracker.byd_atto3_ibeacon_bur4c2a_bermuda_tracker
        from: "not_home"
        to: "home"
    conditions:
      - condition: template
        value_template: >-
          {% set away_started = as_timestamp(trigger.from_state.last_changed, 0) %}
          {% set arrived = as_timestamp(trigger.to_state.last_changed, 0) %}
          {{ away_started > 0
             and arrived > away_started
             and (arrived - away_started) >= (minimum_away_minutes * 60) }}
    actions:
      - action: script.view_road_announcement
        data:
          channels: "pushover_zorruno"
          title: "Vehicle Notification"
          long_announcement: "The BYD Atto 3 has arrived home."
