auchter / haaska

Home Assistant Alexa Skill Adapter
263 stars 61 forks source link

haaska - Problem with Lambda #81

Closed supakdee closed 7 years ago

supakdee commented 7 years ago

Hi,

I finished Alexa skill, Lambda Function, Register application and added to my Amazon Echo skill. However, it cannot discover the components I have in my home assistant.

I tried to trace back:

Detail below.

What should I do to make it work?

make test in Raspberry Pi result: pi@raspberrypi:~/haaska $ make test { "header": { "payloadVersion": "2", "namespace": "Alexa.ConnectedHome.System", "name": "HealthCheckResponse", "messageId": "ebd8f280-778e-4bdb-9c8f-18cc863e84d5" }, "payload": { "isHealthy": true } } true

test in Lambda (Input): { "header": { "payloadVersion": "1", "namespace": "Control", "name": "DiscoverAppliancesRequest" }, "payload": { "accessToken": "whatever" } }

test in Lambda (Error): { "stackTrace": [ [ "/var/task/haaska.py", 660, "event_handler", "ha, payload)" ], [ "/var/task/haaska.py", 289, "invoke", "obj = make_class(allowed)(namespace, name, ha, context)" ] ], "errorType": "AttributeError", "errorMessage": "type object 'allowed' has no attribute 'Control'" }

haaska - config.json: { "url": "https://my_ip:443/api", "password": "my_password", "expose_by_default": false }

auchter commented 7 years ago

Looks like the test in Lambda is still sending a payloadVersion 1 command, which I apparently broke support for. AFAIK, actually using the skill from Alexa does not send version 1 commands any longer (at least I haven't seen them).

Can you add "debug": true to your config.json and rerun make deploy? Then you should be able to go to CloudWatch and get more details about what's going wrong.

supakdee commented 7 years ago

Hi,

I added "debug": true in config.json then make deploy.

I got the below from CloudWatch.

By the way, if I change payloadversion in test event in Lambda to "2", I got the same error.

What should I go next?

Log message:

START RequestId: 6c38a1b3-6dad-11e7-9258-bd9b9e72af69 Version: $LATEST [DEBUG] 2017-07-21T00:42:08.17Z 6c38a1b3-6dad-11e7-9258-bd9b9e72af69 calling event handler for DiscoverAppliancesRequest, payload: {}

type object 'allowed' has no attribute 'Control': AttributeError Traceback (most recent call last): File "/var/task/haaska.py", line 660, in event_handler ha, payload) File "/var/task/haaska.py", line 289, in invoke obj = make_class(allowed)(namespace, name, ha, context) AttributeError: type object 'allowed' has no attribute 'Control'

END RequestId: 6c38a1b3-6dad-11e7-9258-bd9b9e72af69 REPORT RequestId: 6c38a1b3-6dad-11e7-9258-bd9b9e72af69 Duration: 1.21 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 26 MB

trisk commented 7 years ago

@supakdee Make sure you are using the Smart Home Discovery test template in the Lambda console. That has a valid version 2 request.

{
  "header": {
    "payloadVersion": "2",
    "namespace": "Alexa.ConnectedHome.Discovery",
    "name": "DiscoverAppliancesRequest",
    "messageId": "F8752B11-69BB-4246-B923-3BFB27C06C7D"
  },
  "payload": {
    "accessToken": "1"
  }
}
supakdee commented 7 years ago

Hi Trisk,

You're right on the spot - Soon as I use "Alexa Smart Home - Discovery", it was successfully discovery & I got response.

However, when I tried in Alexa Skill --> It still cannot discover anything. Below error log from Cloudwatch.

Do you know what might be the issue?

error log from Cloudwatch:

START RequestId: 2701861a-6dc7-11e7-a6f9-bdda80225240 Version: $LATEST 'header': KeyError Traceback (most recent call last): File "/var/task/haaska.py", line 652, in event_handler name = event['header']['name'] KeyError: 'header'

END RequestId: 2701861a-6dc7-11e7-a6f9-bdda80225240 REPORT RequestId: 2701861a-6dc7-11e7-a6f9-bdda80225240 Duration: 0.71 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 33 MB

supakdee commented 7 years ago

I found the issue - It's about payload version in developer.amazon.com

Need to set as v2 (other devices)

28450539-1a5707a0-6e12-11e7-9d13-ea933fe58902

respectTheCode commented 7 years ago

This should be in the docs Need to set as v2 (other devices). I ran into the same problem.

stefan-wiesner commented 6 years ago

v2 is now deprecated and cannot be selected ...

vladm commented 6 years ago

same issue here, can't discover devices - only v3 payload is available.