Skip to content

iml885203/trash_tracking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš› Trash Tracking - Home Assistant Integration

GitHub release License CI HACS

Real-time garbage truck tracking integration for New Taipei City, Taiwan. Automatically trigger Home Assistant automations when trucks approach or pass your collection points.

๐Ÿ“‹ Overview

Track garbage trucks in real-time using the New Taipei City Environmental Protection Bureau API. Get notifications and trigger automations when trucks are near your location.

โœจ Key Features

  • ๐Ÿš› Real-time Tracking: Monitor New Taipei City garbage truck locations
  • ๐Ÿ“ Smart Collection Points: Automatic route analysis and collection point suggestions
  • ๐ŸŽฏ Multi-route Support: Track multiple garbage truck routes simultaneously
  • โฐ Early Notification: Configurable advance notification (N stops ahead)
  • ๐Ÿ  Native Integration: Full Home Assistant integration with config flow
  • ๐Ÿ”„ Automatic Updates: Real-time status updates via coordinator
  • ๐ŸŽจ Binary Sensor: Easy automation with nearby/idle states

๐ŸŽฌ Workflow

Truck approaching entry point โ†’ Binary Sensor: ON โ†’ HA automation โ†’ ๐Ÿ’ก Light ON
Truck passing exit point โ†’ Binary Sensor: OFF โ†’ HA automation โ†’ ๐ŸŒ‘ Light OFF

๐Ÿš€ Installation

Method 1: HACS (Recommended)

  1. Add Custom Repository

    • Open HACS in Home Assistant
    • Click on "Integrations"
    • Click the 3-dot menu (top right) โ†’ "Custom repositories"
    • Add repository URL: https://github.com/iml885203/trash_tracking
    • Category: "Integration"
    • Click "Add"
  2. Install Integration

    • Search for "Trash Tracking" in HACS
    • Click "Download"
    • Restart Home Assistant
  3. Add Integration

    • Go to Settings โ†’ Devices & Services
    • Click "+ Add Integration"
    • Search for "Trash Tracking"
    • Follow the setup wizard

Method 2: Manual Installation

  1. Download Integration

    cd /config
    mkdir -p custom_components
    cd custom_components
    git clone https://github.com/iml885203/trash_tracking.git
  2. Copy Files

    cp -r trash_tracking/custom_components/trash_tracking ./
  3. Restart Home Assistant

  4. Add Integration

    • Go to Settings โ†’ Devices & Services
    • Click "+ Add Integration"
    • Search for "Trash Tracking"
    • Follow the setup wizard

โš™๏ธ Configuration

Setup Wizard

The integration provides an easy-to-use setup wizard:

  1. Enter Your Address

    • Input your address in Taiwan format
    • Example: ๆ–ฐๅŒ—ๅธ‚ๆฟๆฉ‹ๅ€ๆฐ‘็”Ÿ่ทฏไบŒๆฎต80่™Ÿ
  2. Select Route

    • The wizard will automatically find nearby garbage truck routes
    • Routes are sorted by distance from your location
    • Select the route that serves your area
  3. Configure Collection Points

    • Entry Point: Truck status changes to "nearby" when arriving at this point
    • Exit Point: Truck status returns to "idle" when passing this point
    • Points are automatically suggested based on your location (entry point = nearest point - 1)

Example Configuration

After setup, the integration creates:

Binary Sensor:

  • binary_sensor.trash_tracking_[route_name]_nearby: ON when truck is near

Sensor:

  • sensor.trash_tracking_[route_name]_info: Detailed truck information

๐Ÿค– Automation Examples

Basic Light Automation

automation:
  - alias: "Garbage Truck Approaching - Turn On Light"
    trigger:
      - platform: state
        entity_id: binary_sensor.trash_tracking_c08_afternoon_nearby
        to: 'on'
    action:
      - service: light.turn_on
        target:
          entity_id: light.notification_bulb
        data:
          brightness: 255
          rgb_color: [255, 0, 0]

  - alias: "Garbage Truck Left - Turn Off Light"
    trigger:
      - platform: state
        entity_id: binary_sensor.trash_tracking_c08_afternoon_nearby
        to: 'off'
    action:
      - service: light.turn_off
        target:
          entity_id: light.notification_bulb

Mobile Notification

automation:
  - alias: "Garbage Truck Notification"
    trigger:
      - platform: state
        entity_id: binary_sensor.trash_tracking_c08_afternoon_nearby
        to: 'on'
    action:
      - service: notify.mobile_app_your_phone
        data:
          title: "๐Ÿš› ๅžƒๅœพ่ปŠไพ†ไบ†๏ผ"
          message: "ๅžƒๅœพ่ปŠๆญฃๅœจๆŽฅ่ฟ‘๏ผŒ่ซ‹ๆบ–ๅ‚™ๅ€’ๅžƒๅœพ"
          data:
            priority: high
            ttl: 0

Play Audio Announcement

automation:
  - alias: "Garbage Truck Audio Announcement"
    trigger:
      - platform: state
        entity_id: binary_sensor.trash_tracking_c08_afternoon_nearby
        to: 'on'
    action:
      - service: tts.google_translate_say
        target:
          entity_id: media_player.living_room_speaker
        data:
          message: "ๅžƒๅœพ่ปŠๅณๅฐ‡ๅˆฐ้”๏ผŒ่ซ‹ๆบ–ๅ‚™ๅ€’ๅžƒๅœพ"

Conditional Actions (Only on Weekdays)

automation:
  - alias: "Garbage Truck Weekday Notification"
    trigger:
      - platform: state
        entity_id: binary_sensor.trash_tracking_c08_afternoon_nearby
        to: 'on'
    condition:
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
    action:
      - service: light.turn_on
        target:
          entity_id: light.notification_bulb

๐Ÿ“Š Sensor Attributes

Binary Sensor Attributes

The binary sensor provides rich attributes for advanced automations:

binary_sensor.trash_tracking_c08_afternoon_nearby:
  state: 'on'  # or 'off'
  attributes:
    current_point: "Minsheng Rd. Sec. 2, No. 80"
    current_rank: 12
    total_points: 69
    distance_meters: 45.2
    car_no: "ABC-1234"
    line_name: "C08 Afternoon Route"
    last_update: "2025-11-23T14:30:00"

Using Attributes in Automations

automation:
  - alias: "Announce Current Stop"
    trigger:
      - platform: state
        entity_id: binary_sensor.trash_tracking_c08_afternoon_nearby
        to: 'on'
    action:
      - service: notify.mobile_app_your_phone
        data:
          message: >
            ๅžƒๅœพ่ปŠ็›ฎๅ‰ๅœจ๏ผš{{ state_attr('binary_sensor.trash_tracking_c08_afternoon_nearby', 'current_point') }}
            ่ท้›ขๆ‚จ๏ผš{{ state_attr('binary_sensor.trash_tracking_c08_afternoon_nearby', 'distance_meters') }} ๅ…ฌๅฐบ

๐Ÿ”ง CLI Tool (Optional)

For developers or advanced users, a CLI tool is available for testing:

# Install CLI tool
pip install -e apps/cli/

# Query trucks by coordinates
python -m trash_tracking_cli --lat 25.018269 --lng 121.471703

# Suggest configuration by address
python -m trash_tracking_cli --suggest "ๆ–ฐๅŒ—ๅธ‚ๆฟๆฉ‹ๅ€ๆฐ‘็”Ÿ่ทฏไบŒๆฎต80่™Ÿ"

# Filter specific route
python -m trash_tracking_cli --lat 25.018269 --lng 121.471703 --line "C08"

๐Ÿ› ๏ธ Development

Setup Development Environment

# Clone repository
git clone https://github.com/iml885203/trash_tracking.git
cd trash_tracking

# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate

# Install core package in editable mode
pip install -e packages/core/

# Install dev dependencies
pip install -r requirements-dev.txt

# Install pre-commit hooks
pre-commit install

Run Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=packages/core/trash_tracking_core --cov-report=html

# Run specific test
pytest tests/test_tracker.py -v

Code Quality

# Linting
flake8 packages/core/trash_tracking_core custom_components/trash_tracking

# Format code
black packages/core/trash_tracking_core custom_components/trash_tracking
isort packages/core/trash_tracking_core custom_components/trash_tracking

# Type checking
mypy packages/core/trash_tracking_core --ignore-missing-imports

๐Ÿ“– Documentation


๐Ÿค Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • New Taipei City Environmental Protection Bureau for providing the public API
  • Home Assistant community for the amazing platform
  • All contributors who helped improve this integration

๐Ÿ“ฎ Support


Made with โค๏ธ for the Home Assistant community

About

๐Ÿš› Real-time garbage truck tracking for New Taipei City with Home Assistant integration

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 3

  •  
  •  
  •