Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Tesla Invoice Downloader

Overview

Tesla Invoice Downloader is a Python script that retrieves Tesla charging invoices via the Fleet API. It authenticates via OAuth, fetches charging history, and downloads invoices as PDF files. The script can run as a one-time operation or as a daemon checking for new invoices every hour.

License

Copyright © 2025 Alastair D'Silva

This project is licensed under the GNU General Public License v3 (GPLv3). See the LICENSE file for details.

Features

  • OAuth authentication with Tesla Developer API
  • Fetches charging history and invoices
  • Supports filtering by VIN
  • Only retrieves invoices since the last saved charge session
  • Saves metadata alongside invoices in JSON format
  • Daemon mode: checks for new invoices every hour
  • Configurable output directory and logging
  • Option to save invoices as PNG images in addition to PDFs

Installation

Prerequisites

  • Python 3.7+
  • Install dependencies:
    pip install requests pymupdf

Usage

Run the script with the following options:

python tesla_invoice_downloader.py [OPTIONS]

Command-line Arguments

Option Description
--vin VIN Restrict invoices to a specific VIN
--output-dir DIR Directory to save invoices (default: current directory)
--log-file FILE File to save logs (optional)
--daemon Run as a background process, checking for new invoices every hour
--force-auth Force re-authentication to obtain new access and refresh tokens
--on-or-after YYYYMMDD Only download invoices on or after this date (YYYYMMDD format)
--png Output a .png image of the invoice as well as the PDF
--all Traverse the full history and skip the early-exit optimization
--debug Enable debug logging

Example Usage

  1. One-time download

    python tesla_invoice_downloader.py --output-dir ~/invoices
  2. Filter invoices for a specific VIN

    python tesla_invoice_downloader.py --vin 5YJSA1E26JF278XXX
  3. Download invoices on or after a specific date

    python tesla_invoice_downloader.py --on-or-after 20260101
  4. Download invoices and save as both PDF and PNG

    python tesla_invoice_downloader.py --output-dir ~/invoices --png
  5. Traverse the full history and skip early-exit check

    python tesla_invoice_downloader.py --output-dir ~/invoices --all
  6. Run in daemon mode

    python tesla_invoice_downloader.py --daemon --output-dir ~/invoices --log-file ~/logs/invoice.log

Tesla Developer Setup

Before using the script, create a Tesla Developer app:

  1. Go to Tesla Developer Portal
  2. Click "Get Started" and create an application with the following settings:
    • Application Name: (Cannot contain "Tesla")
    • OAuth Grant Type: Authorization Code and Machine-to-Machine
    • Allowed Origin URL: http://localhost:8585
    • Allowed Redirect URI: http://localhost:8585/callback
    • API & Scopes: Select "Vehicle Charging Management"
  3. Save your Client ID and Client Secret.
  4. Run the script and enter these credentials when prompted.

File Naming Convention

Invoices are saved with the following filename format:

YYYYMMDD.Tesla.Charging - <location> - <charging_usage>kWh.<currencySymbol><total_due>.pdf

Where:

  • YYYYMMDD: Charge start date
  • <location>: Site location
  • <charging_usage>: Total charging kWh
  • <currencySymbol>: Currency symbol (e.g., $ for AUD/CAD, for EUR)
  • <total_due>: Total charge cost

Configuration File

The script stores authentication tokens and charging history in:

~/.tesla_invoice_downloader.json

This file is updated automatically and should be kept secure.

Contributing

Pull requests and contributions are welcome! Please ensure your code adheres to the project structure and style.

Issues & Support

If you encounter any issues, feel free to open a GitHub issue or reach out.

Acknowledgments

Disclaimer

This project is not affiliated with or endorsed by Tesla, Inc.

About

Download your Tesla charging invoices via the Tesla Fleet API

Resources

Stars

8 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages