Skip to content

A simple tool to scrape your Amazon invoice details (Price + URL) and send them over MQTT. Allows for easy access and integration into Home Assistant.

Notifications You must be signed in to change notification settings

feliggs/AmazonInvoiceScraper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AmazonInvoiceScraper

This project automates the retrieval of your Amazon monthly invoice and publishes the extracted data (price and link) via MQTT – specifically designed for seamless integration with Home Assistant (HA).

If you need advanced order scraping (e.g., product images, delivery dates, collages), check out my main project AmazonOrderScraper on my profile. Both tools work independently but can also be combined. Integration of the monthly invoice feature into the main project is planned.

Note:
The default Amazon region is amazon.de. To use another Amazon site (e.g., amazon.com), adjust the base URL in the script.

Features

  • Automated Login: Secure login to your Amazon account using credentials and OTP (2FA/TOTP).
  • Monthly Invoice Scraping: Retrieves the current month's invoice price and download link.
  • MQTT Publishing: Publishes the invoice data as a JSON object to your configured MQTT topic – ready for use for Home Assistant.
  • Headless Operation: Runs Chrome in headless mode for background automation.
  • Easy Configuration: All credentials and settings via .env file.

Home Assistant Integration

This tool is built to feed data directly into Home Assistant.
You can subscribe to the MQTT topic in your configuration.yaml to display the invoice price and download link in your dashboard.

Example configuration.yaml snippet:

sensor:
  - platform: mqtt
    name: Amazon Monthly Invoice
    state_topic: your/topic
    value_template: "{{ value_json.price }}"
    json_attributes_topic: your/topic
    json_attributes_template: "{{ value_json | tojson }}"

You can then use these values in Lovelace cards, automations, or notifications.

Example Dashboard Use

In my Home Assistant dashboard, I use this integration to:

  • Display the current Amazon invoice amount for quick monthly spending checks.
  • Provide a direct download link to the invoice page for easy access and payment.
  • Trigger automations or alerts if the invoice exceeds a certain threshold (?).

Example visualization:

Home Assistant Dashboard showing Amazon invoice amount and clickable download link

YAML Code:

type: horizontal-stack
cards:
  - type: tile
    entity: sensor.invoice_price
    features_position: bottom
    vertical: false
    icon_tap_action:
      action: more-info
    icon: mdi:currency-eur
    name: Aktuelle Monatsabrechnung
    tap_action:
      action: more-info
  - type: custom:button-card
    show_icon: false
    show_name: true
    name: Zur Rechnung
    tap_action:
      action: url
      url_path: "[[[ return states[\"sensor.invoice_link\"].state ]]]"
    styles:
      card:
        - width: 100%
        - height: 100%
        - border-radius: 8px
        - box-shadow: var(--ha-card-box-shadow)
        - font-size: 1.05em
        - padding: 6px 14px
        - background: var(--card-background-color)
      name:
        - justify-self: center
        - align-self: center
        - font-weight: 500
        - color: var(--primary-color)

Configuration

Edit the config.env file in your project directory with the following variables:

Variable Description Example Value
EMAIL Your Amazon account email address example@example.com
PASSWORD Your Amazon account password password1234
OTP_SECRET TOTP secret for 2-factor authentication (from pyotp) abcdefghijklmnopqrstuvwxyz
MQTT_BROKER MQTT broker address (IP or hostname) 1.1.1.1
MQTT_PORT MQTT broker port 1883
MQTT_TOPIC MQTT topic to publish to your/topic
MQTT_USERNAME MQTT username user
MQTT_PASSWORD MQTT password password

Tip:
If your credentials or secrets contain spaces, enclose the value in double quotes.

Installation

  1. Clone this repository
  2. Install dependencies: pip install -r requirements.txt
  3. Download ChromeDriver:
    Make sure you have ChromeDriver installed and in your PATH.

Usage

  1. Edit config.env:
    Enter your Amazon credentials, OTP secret, and MQTT settings.
  2. Run the script

The script will log in, retrieve your current monthly invoice, and publish the data to MQTT every 2 minutes.

Requirements

See requirements.txt for all dependencies:

  • selenium
  • python-dotenv
  • pyotp
  • paho-mqtt

Notes

  • This script is for personal use only on your own Amazon account.
  • Your credentials and OTP secret are stored locally in the .env file and should never be shared.
  • Use at your own risk: This script is provided for demonstration and educational purposes only.
  • I do not accept any liability for any direct, indirect, incidental, or consequential damages resulting from the use or misuse of this script.
  • There is no warranty of any kind, express or implied.
  • By using this script, you acknowledge and agree that you do so entirely at your own risk and responsibility.

Looking for more features?
Explore AmazonOrderScraper on my profile for full order scraping, product image downloads, and more.
This monthly invoice scraper can be combined with the main project, and integration is planned for the near future.

About

A simple tool to scrape your Amazon invoice details (Price + URL) and send them over MQTT. Allows for easy access and integration into Home Assistant.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages