alexa-samples / alexa-smarthome

Resources for Alexa Smart Home developers.
https://alexa.design/smarthome
Other
685 stars 336 forks source link

Is this repo maintained ?? #164

Closed fabltd closed 1 year ago

fabltd commented 4 years ago

Links don't work:

ALX316 - How to Build a Backend for an Alexa Smart Home Skill - This doesn't work and main others.

StefanOltmann commented 4 years ago

I guess it's abandoned. Others also get no answers here.

And I feel the samples as way to complicated and badly explained anyway.

I wish a sample would show how I just can make simple REST API calls to my backend service.

fabltd commented 4 years ago

Hi

I might be able to help as I have this working now. Where are you stuck?

StefanOltmann commented 4 years ago

Thank you. I stuck nowhere. I was just reading a HOWTO and checked the Java sample code. I find that it's a bad sample and very hard to understand. Since Amazon provides no help here I will stop right now.

jbnunn commented 4 years ago

@StefanOltmann We have a few good Python and NodeJS samples that show how to build a Smart Home device that I can share. They are up to date, but they don't show how to make REST calls. They do show how to make calls to another service though (Amazon SQS), and you could easily adapt that to use Node's https or Python's request libraries:

Let me know if this helps

StefanOltmann commented 4 years ago

@jbnunn Thank you, but I fear it does not help me.

I'm looking for a minimal, clean and working sample in Java/Kotlin.

The old samples here are hard to understand because of missing comments.

The ones you provided are really big.

As far as I understand is a request always represented as a JSON String and the answer also. I feel this could be parsed and handled pretty simple.

What I want to build is something minimal to get the "Switch XY on/off" and "Set XY to XX%" requests into my network (to forward it to my KNX interface).

Maybe it is only a forward of JSON to my server. Then I will not have to change the skill.

Or as a cleaner solution I would like to generate REST calls from parsed JSON like this: https://myserver/alexa/switch/[deviceId]/to/[on|off] https://myserver/alexa/set/[deviceId]/to/[percentage]

I would build this skill myself and share it, but because the samples are either outdated, broken or overwhelming I don't see how to do it.

Can you please build a minimal working Java sample for this use case?

jbnunn commented 4 years ago

Hi @StefanOltmann, thanks for letting me know. We have a minimalI Java code sample that will show you the basics of setting up a smart home switch: https://github.com/alexa/skill-sample-java-smarthome-switch. I just ran through all the steps and built it, it works, so I think you'll be able to learn a lot from that.

A few things to note:

1) It uses Lambda as the backend, rather than something in your own cloud or your own server. In https://github.com/alexa/skill-sample-java-smarthome-switch/blob/master/src/main/java/AlexaHandler.java#L103, you can send an HTTPS request to your server instead of using DynamoDB backend, as we do here. 2) The functionality you want ("Switch XY on/off") is controlled by an Alexa PowerController Interface. The code in the repo I send shows you how that works. Once you receive and validate a PowerController request, you can send that request to your network. 3) When using this Java code in Lambda, you might experience a "cold-start" time, meaning the container might take a few seconds to warm up on first invocation. When this happens, testing your Alexa skill might fail the first time. If you test it again ("alexa turn on the sample switch), it will work.

Hope this helps, please let me know.

StefanOltmann commented 4 years ago

@jbnunn

I saw that before. This sample is not really minimalistic. For example it works with an Dynamo Database for unknown reason. And why do I need that AlexaResponse object? What does it do? And method names are somewhat unclear. Also with pascalcased names it's not good Java. Also no comments.

I'm sorry to say that, but that sample code is really messy and left me puzzled about how things work and what I really need of it.

For me it's also not just one smart home device. I want to expose all my devices trough this skill and Alexa to set values on it.

Similar to the OpenHAB Skill which I want to replace in my case with something way easier, because that is a grown project.

So I guess there could be a REST method for discovery that tells Alexa in a JSON string about all device ids, their names and kinds/types.

Alexa can give back JSON strings representing the command.

To avoid JSON parsing & building in code I would use the GSon library and have an actual object (as DTO) for each thing like DiscoveryEntry, SwitchCommand and so on... with default values and short explaination to each field via JavaDoc.

And it should to the absolute necessary. Do not show off other technologies there. This confuses.

Right now I want to understand what is the absolute minimal working code to do device discovery and handle Switch & Percentage Commands (the two most used in every home).

When you bring in more things as the minimal stuff the cognitive complexity grows and it's to hard to learn from the sample because there is no clear picture anymore.

Can you craft me a sample that's so easy?

jbnunn commented 4 years ago

Hi @StefanOltmann

DynamoDB is used to store the state of the switch in this example, but you can do without it.

And why do I need that AlexaResponse object? What does it do?

There are common message fields that are sent to and received from Alexa when Smart Home requests are invoked, and the AlexaResponse class provides helpers to format those messages. You could build your own based off of the Alexa Interface Messaging Guide, but the provided one wraps up everything quite nicely.

At a minimum, a Smart Home skill should:

1) Receive and respond to a discovery request to report back what directive(s) it can handle (PowerController in this case) 2) Receive and respond to a directive request ("Alexa, turn on the switch") 3) Pass messages to make a state change to a device, and/or report back the state of a device

With the exception of the DynamoDB piece, the sample skill I referenced does all three of these, and is really the minimal code required to do this.

Thank you for bringing up the coding style and lack of comments. Learning about the Smart Home skills can be complex, and not having good comments can be frustrating and make learning even harder. We're in the process of writing and applying style guides to our code samples--similar to this one for NodeJS--hopefully we can alleviate this frustration in the future.

StefanOltmann commented 4 years ago

@jbnunn Thank you. I managed to get it working for my private smart home project.

I'm thinking of building a small & clean sample app that shows how to call REST apis in Kotlin. I will prepare a pull request in the next days.

StefanOltmann commented 4 years ago

@jbnunn It's done. :-)

I created a clean and simple Kotlin version from scratch: https://github.com/StefanOltmann/alexa-skill-sample-kotlin-smarthome-rest-api

Also I added a pull request for the original Java version to fix some of the most noticeable code style issues: https://github.com/alexa/skill-sample-java-smarthome-switch/pull/7

I hope this will help people getting started with the Alexa Smart Home Skill.

Mine is working in production now. 👍

jbnunn commented 3 years ago

Great to hear, thank you @StefanOltmann!

StefanOltmann commented 1 year ago

@aszk Closing means "it's not maintained anymore", right?

aszk commented 1 year ago

@StefanOltmann No, we will maintain this repository however we probably need to update many codes and pages. Please feel free to create new issues or contact me.

StefanOltmann commented 10 months ago

@aszk What about my pull request?

aszk commented 10 months ago

We generally don't accept pull request but we will check. I assume https://github.com/alexa-samples/skill-sample-java-smarthome-switch/pull/7

StefanOltmann commented 10 months ago

We generally don't accept pull request

Your Contributing.md says otherwise. I recommend deleting that file before others put time and effort in that, too.