auchter / haaska

Home Assistant Alexa Skill Adapter
263 stars 61 forks source link

Can no longer select payload version 2 - Skill can't connect #102

Open ghost opened 6 years ago

ghost commented 6 years ago

Hi, I went to set this up today and am not having much luck.

My lambda is connecting OK, but my skill is not. There are a coupls of things that I'm unsure about.

Firstly, when I am on the developer console and go to the test simulator, if I select manual JSON I appear to have to select a region at the bottom left corner from a drop down list. But this list is completely unpopulated, so I can't select anything.

Also, and perhaps more significantly, under skill information, I can only select Payload Version v3. Since v2 is now deprecated and I am unable to select it. This seems unfortunate because according to several threads (e.g https://github.com/auchter/haaska/issues/49 and https://github.com/auchter/haaska/issues/86 ), you need to select version 2.

Can anyone help? Can i force v2 somehow?

Thanks,

James

ghost commented 6 years ago

I've now verified that I have most of the set up done correctly. I can go into the Alexa app and find my skill and I can link my amazon account. I beleive that means I've done all the "Log in with Amazon" and the "Account Linking" stuff correctly in theg set up.

I also get a positive response when I run a test in the lambda which seems to indicate that everything's working.

I do not get a positive responses running "make test" but I think that may be because my AWS CLI configuration is wrong.

Ultimately, (ignoring the result of "make test") it appears the problem is the communication between the skill and the lambda. And I believe this is due to the differences between v2 and v3 payloads. Can anyone help?

ghost commented 6 years ago

Looking at this a bit more; the differences between v2 and v3 are not insignificant. I'm not a coder/programmer, so don't think I can pick this up myself, but hopefully someone can :-)

I did have a look, and think I can change the format of the Discover response to have the correct names in it (e.g, ApplianceID becomes endpointID), but much of the other stuff to do with discovering what services and how those responses are made is such a large change that it's beyond me!

wladwnt commented 6 years ago

You still can select v2 with one trick. The Selection v2 is just deactivated in html. If you use firefox, use right click (mouse) on the v2 select box, tehn in the pop-up menu select "examine element (Q)" (or similar item, I have it in german, not sure how it is written in english). Then you can edit html code. You have to find disabled="disabled" as a tag property and delete it. Than you can select v2 :)

wladwnt commented 6 years ago

The best solution, of course, is to update haaska to v3. Hope the author will do it.

malcolmrigg commented 6 years ago

You might want to take a look at this: https://home-assistant.io/blog/2017/12/17/introducing-home-assistant-cloud/ Although I've just noticed that this won't be free either...

ghost commented 6 years ago

@wladwnt I was so excited to read a suggestion that I took the following steps on my phone.

@malcolmrigg - it's because I can't use Home Assistant Cloud that I was inspired to get this going.

ghost commented 6 years ago

Also, I should say - thanks very much @wladwnt !

user0x01 commented 6 years ago

Dankeschön

bitglue commented 6 years ago

Looks like home-assistant implements some part of the smart home API now. I'd guess this means the Lambda function can be much simpler?

cbrherms commented 6 years ago

@bitglue that's related to home assistant cloud. The paid for feature that's currently in beta and at the moment only available for testing by people who use American Amazon accounts. Doesn't currently work for those of us UK English. It does technically the same as haaska, plus potentially more in future, but for those of us who want to use a none paid for option haaska will do the job. There is someone working on getting this functional with V3 here. It's looking like it's almost fully implemented tbf

bitglue commented 6 years ago

Home assistant cloud is just a dumb proxy. It's purely a convenience function: all the Smart Home API logic is in that smart_home.py file.

The cloud component publishes the protocol over a websocket, which the Home Assistant Cloud servers proxy to Amazon. I'm just a stupid low-level programmer so I don't know about these websocket things, but it took all of 10 lines of code to expose the same API with an HTTP POST. Then the Lambda function reduces to:

def event_handler(event, context):
    config = Configuration('config.json')
    if config.debug:
        logger.setLevel(logging.DEBUG)
    ha = HomeAssistant(config)

    return ha.post('alexa_smart_home', event, wait=True).json()

I've just finished the POC, and Alexa discovered my devices and I flipped a few lights on and off. I'll put a bow on this, with PRs to home-assistant to add the necessary HTTP API, and one to Haaska to use that (and update some of the documentation). I don't see much point in implementing the v3 Smart Home payload in Haaska since it's already in home-assistant, and there it's well tested and has support of core developers.

@mike-grant

cbrherms commented 6 years ago

Thankyou for opening my eyes! The term look before you leap springs to mind. Actually hadn't looked in to HA's implementation of cloud yet. Deeming it irrelevant for the time being as they'd not made it available in the UK yet.

waternexus commented 6 years ago

@bitglue Could you share the code for your PoC and the config?

Do you post to http://HASSIP:8123/api/alexa_smart_home or http://HASSIP:8123/alexa_smart_home?

bitglue commented 6 years ago

https://gist.github.com/bitglue/66ca023b3c3c1a5b267bdd1d9b3ee48f

I'm working on some PRs, once I've made this cleaner.

waternexus commented 6 years ago

Awesome, hopefully you'll submit the PRs before Saturday so they could potentially be merged into HA 0.62.

You should post something on the Discord, some other devs might want/be willing to help you.

cbrherms commented 6 years ago

Do you think HA will merge a PR that bypasses their paid for method though?

GreenTurtwig commented 6 years ago

@bitglue Works fine! Good work. 🐈 35228466-b7db448e-ff88-11e7-8e2c-295b2dcc209c

bitglue commented 6 years ago

Do you think HA will merge a PR that bypasses their paid for method though?

We'll see. It's not as if I'm giving away some secret sauce here. If they wanted to force people into using the paid solution they could have easily implemented the API outside home-assistant (like haaska) and kept it private.

mike-grant commented 6 years ago

I actually really like this idea of exposing it in the way that you have. If this pull request makes it into HA then it would be better for the longer term.

bitglue commented 6 years ago

Here are the corresponding changes to Haaska: https://github.com/auchter/haaska/pull/109

A bit rough around the edges: certainly some more cleanup and simplification can happen, but it works.