roondar / alexa2ha

2 stars 1 forks source link

Alexa to Home Assistant Shopping List Sync

This project integrates Alexa and Home Assistant, allowing incomplete items on your Alexa shopping list to be added to Home Assistant's shopping list and marked as completed on Alexa.

Features

Prerequisites

Setup

1. Home Assistant Automation

To handle the webhook, create an automation in Home Assistant: Like describehere

alias: Alexa shopping list
description: ""
trigger:
  - platform: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: "--8v4O3JZHbRRPMS93nspLfIS"
condition: [ ]
action:
  - action: todo.add_item
    metadata: { }
    data:
      item: "{{ trigger.json.name }}"
    target:
      entity_id: todo.shopping_list
mode: single

2. Environment Variables

Ensure you have a .env file in the project root with the following content:

HA_WEBHOOK_URL=http://192.168.1.254:8123/api/webhook/--8v4O3JZHbRRPMS93nspLfIS
AMAZON_URL=https://www.amazon.fr
COOKIE_PATH=/cookie.pickle
LOG_LEVEL=INFO

3. Docker Compose

Update the docker-compose file with your cookie path generated by the alexa_media_player integration.

services:
  scraper:
    image: ghcr.io/roondar/alexa2ha:main
    restart: unless-stopped
    container_name: alexa2ha
    env_file:
      - .env
    volumes:
      - .:/usr/src/app
      - /srv/home-assistant/config/.storage/alexa_media.EMAIL.pickle:/cookie.pickle:ro
    command: python ./main.py

4. Run

docker-compose up
2024-08-16 15:28:44 - __main__ - INFO - Successfully retrieved data.
2024-08-16 15:28:44 - __main__ - INFO - Successfully added item: banane
2024-08-16 15:28:44 - __main__ - INFO - Marking item as completed: banane
2024-08-16 15:28:44 - __main__ - INFO - Item marked as completed: banane

Run locally (for development)

pip3 install -r requirements.txt
export HA_WEBHOOK_URL=http://192.168.1.254:8123/api/webhook/--8v4O3JZHbRRPMS93nspLfIS
export AMAZON_URL=https://www.amazon.fr
export COOKIE_PATH=/cookie.pickle
export LOG_LEVEL=INFO
python3 main.py