Comments (16)
Hi
I might be able to help as I have this working now. Where are you stuck?
from alexa-smarthome.
@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.
from alexa-smarthome.
We generally don't accept pull request but we will check. I assume alexa-samples/skill-sample-java-smarthome-switch#7
from alexa-smarthome.
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.
from alexa-smarthome.
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.
from alexa-smarthome.
@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:
- Alexa Smart Home Virtual Fireplace (Python)
- Alexa Smart Home Virtual Pager (Python)
- Alexa Smart Home Virtual Beeper (NodeJS)
Let me know if this helps
from alexa-smarthome.
@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?
from alexa-smarthome.
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:
- 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.
- 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.
- 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.
from alexa-smarthome.
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?
from alexa-smarthome.
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:
- Receive and respond to a discovery request to report back what directive(s) it can handle (PowerController in this case)
- Receive and respond to a directive request ("Alexa, turn on the switch")
- 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.
from alexa-smarthome.
@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.
from alexa-smarthome.
@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:
alexa-samples/skill-sample-java-smarthome-switch#7
I hope this will help people getting started with the Alexa Smart Home Skill.
Mine is working in production now. 👍
from alexa-smarthome.
Great to hear, thank you @StefanOltmann!
from alexa-smarthome.
@aszk Closing means "it's not maintained anymore", right?
from alexa-smarthome.
@aszk What about my pull request?
from alexa-smarthome.
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.
from alexa-smarthome.
Related Issues (20)
- Alexa HOT 1
- Unable to get Access token using authorization code for a skill in lambda function HOT 3
- when testing smart home ample device it shows error HOT 2
- Validation schema fails to parse in Node.js HOT 7
- Add validation for Camera PTZ controllers HOT 1
- Getting Domain not whitelisted for using LWA javaScript SDK HOT 1
- Capability Evaluations & Test plans HOT 1
- "errorMessage": "2021-05-11T08:48:54.169Z d01782c6-b615-4b06-96b2-ac313bae6d72 Task timed out after 3.06 seconds"
- Adding Alexa.Cooking interfaces into the Validation Schemas? HOT 1
- Documentation misses an important gotcha HOT 1
- How to get utterance activity keys HOT 3
- Schema validation for endpointId using (.) periods HOT 1
- Alexa.PercentageController empty value in payload HOT 1
- Fixes for schema broken by commit 276150255d1843021dcd8b47809c0f79a6660517 HOT 4
- Hm, I'm having trouble reaching null. [Alexa] PowerController TurnOff 0E:38:82:9E:54:6B undefined null HOT 3
- How to report bugs? HOT 1
- Can Alexa Smart Home Lambda skill response with custom so far? HOT 1
- Json schema draft-03 is given instead of draft-04 in validation_schemas/alexa_smart_home_message_schema.json in this link - https://github.com/alexa-samples/alexa-smarthome/wiki/Validation-Schemas HOT 1
- Lambda function not discovering devices? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alexa-smarthome.