Code Monkey home page Code Monkey logo

amazonechoapi's Introduction

AmazonEchoApi

UPDATE: Check out an implementation https://github.com/noelportugal/AmazonEchoHomeAutomation

This is a simple way to login to Amazon and retrieve the unnoficial Echo API. I purposely didn't use Amazon SDKs so anyone can see how to simulate a login and implement with any language. The endoint investigation was done by Owen Piettes and can be found here http://www.piettes.com/the-amazon-echo-api/.

Here is a list of some the endpoints that are of particular interest to observe:

Basic Usage

  AmazonEchoApi amazonEchoApi = new AmazonEchoApi("https://pitangui.amazon.com","username", "password");
  if (amazonEchoApi.httpLogin()){
    String output = amazonEchoApi.httpGet("/api/todos?type=TASK&size=1");
  }

After getting output you can parse the JSON and do whatever you want. If you look at my AmazonEchoApi.java main, you will see that I check the TODO list every 15 seconds and store the itemId. If there is a new one then I go ahead and trigger whatever I want.

This example was build with Netbeans and runs in a Raspberry Pi. I included the following libs:

  • HttpClient
  • Simple-JSON
  • JSoup

Full Example

    public static void main(String[] args) throws InterruptedException, IOException {
        AmazonEchoApi amazonEchoApi = new AmazonEchoApi("https://pitangui.amazon.com","username", "password");
        if (amazonEchoApi.httpLogin()){
            while (true) {                
                String output = amazonEchoApi.httpGet("/api/todos?type=TASK&size=1");

                // Parse JSON
                Object obj = JSONValue.parse(output);
		JSONObject jsonObject = (JSONObject) obj;
                JSONArray values = (JSONArray) jsonObject.get("values");
                JSONObject item = (JSONObject)values.get(0);
                
                // Get text and itemId
                String text = item.get("text").toString();
                String itemId = item.get("itemId").toString();
                
                if (!checkItemId(itemId)){
                    addItemId(itemId);
                    System.out.println(text);
                    // Do something. ie Hue Lights, etc
                }else{
                    System.out.println("No new commands");
                }
                // Sleep for 15 seconds
                Thread.sleep(15000);
            }

        }
    }

amazonechoapi's People

Contributors

noelportugal avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.