Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
options.json
3 changes: 3 additions & 0 deletions ha_skill/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [1.0.8]
- Add a method to run this addon as standalone docker container

## [1.0.7]
- Handle large responses by splitting the response across messages

Expand Down
14 changes: 14 additions & 0 deletions ha_skill/Dockerfile_standalone
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM alpine:3.20.2

# Install requirements for add-on
RUN apk add --no-cache python3 py3-pip py3-requests py3-boto3

# Copy data for add-on
COPY run.py /
COPY cloudformation.yaml /

RUN mkdir /data
RUN touch /data/options.json

ENTRYPOINT [ "python3" ]
CMD [ "/run.py" ]
10 changes: 9 additions & 1 deletion ha_skill/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ AWS CloudFormation. Manual setup is still required to create a custom Alexa
Skill and to create an AWS account and create bootstrap IAM credentials. All AWS
usage will fit in the [always free tier](https://aws.amazon.com/free/?awsf.Free%20Tier%20Types=tier%23always-free).

See DOCS.md for setup instructions.
See DOCS.md for setup instructions.

## Docker standalone mode
If you want to use this addon, but you are running HomeAssistant as a Docker container, you can do the following steps:
1. Create a Long Lived Access Token in HomeAssistant
1. Clone this repo
1. `cd ha_addons/ha_skill/`
1. Rename the `example-options.json` file to `options.json` and paste in your informations
1. You can start the container with: `docker compose up -d`
9 changes: 9 additions & 0 deletions ha_skill/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
ha-alexa-skill:
image: ha-alexa-skill
build:
context: .
dockerfile: Dockerfile_standalone
restart: unless-stopped
volumes:
- ./options.json:/data/options.json
10 changes: 10 additions & 0 deletions ha_skill/example-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"AWS Access Key": "ASDADFADSF32897438342",
"AWS Secret Key": "fjdfsljkasdfjklsafdkjlasfdkljjsfdklsj",
"AWS Region":"eu-west-1",
"Alexa Skill Id": "amzn1.asl.skill.6546564545-4544-4455-4554-4514545a1c",
"CloudFormation Stack Name": "HASkill",
"Debug": true,
"HA Base URL":"https://myha.mydomain.com",
"HA Token":"dsdsakjdwkljakjjajhgJHhas2jdhFIDKJNHDSKFDSJHKhjkajshdHJDFJHHD34SFJKGDSHKSALJKAHS32h3jhawpsdasa"
}
12 changes: 9 additions & 3 deletions ha_skill/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def handle_cloudformation_stack(session, stack_name, stack_params={}):
log.info(f'Stack has outputs\n{json.dumps(outputs, indent=2)}')


def poll_for_work(session):
def poll_for_work(session,options):
sqs = session.resource('sqs')
request_queue = sqs.get_queue_by_name(QueueName=QUEUE_NAME)

Expand All @@ -82,8 +82,15 @@ def poll_for_work(session):
)

token = os.environ.get('SUPERVISOR_TOKEN')
if 'HA Token' in options:
token=options['HA Token']
assert token is not None

request_url = 'http://supervisor/core/api/alexa/smart_home'
if 'HA Base URL' in options:
request_url=os.path.join(options['HA Base URL'],'api/alexa/smart_home')
log.debug(f'request_url: "{request_url}"')

log.info(f'Polling for work from {QUEUE_NAME}...')
while True:
try:
Expand All @@ -106,7 +113,6 @@ def poll_for_work(session):
response_queue = sqs.Queue(payload['response_queue'])
group_id = m.attributes['MessageGroupId']

request_url = 'http://supervisor/core/api/alexa/smart_home'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json',
Expand Down Expand Up @@ -178,4 +184,4 @@ def split_string_for_sqs(s):
'Debug': str(options.get('Debug', False))
}
handle_cloudformation_stack(session, options['CloudFormation Stack Name'], stack_params=stack_params)
poll_for_work(session)
poll_for_work(session,options)