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 isamazon.de. To use another Amazon site (e.g.,amazon.com), adjust the base URL in the script.
- 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
.envfile.
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.
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:
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)
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.
- Clone this repository
- Install dependencies:
pip install -r requirements.txt - Download ChromeDriver:
Make sure you have ChromeDriver installed and in yourPATH.
- Edit
config.env:
Enter your Amazon credentials, OTP secret, and MQTT settings. - Run the script
The script will log in, retrieve your current monthly invoice, and publish the data to MQTT every 2 minutes.
See requirements.txt for all dependencies:
- selenium
- python-dotenv
- pyotp
- paho-mqtt
- This script is for personal use only on your own Amazon account.
- Your credentials and OTP secret are stored locally in the
.envfile 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.
