voydz / alexa-lgtv-remote

Control your webOS powered LG TV with amazon's alexa.
MIT License
50 stars 26 forks source link
amazon-alexa remote-control smarthome television

Alexa LG TV Remote Build Status Greenkeeper badge

Control your webOS powered LG TV with amazon's alexa. This is a small DIY smart home project born out of lazyness and curiosity. It currently supports English and German invocations to control your device.

Getting Started

First of all the setup of this skill does require some amount of developer knowledge, as I am not able to cover everything here. This project consists of a NodeJS HTTP/S webserver in your local network (but has to be reachable by Amazons ASK Services). It handles incoming requests from Alexa and locally communicates with your LG TV.

  1. Create your own Alexa app in Amazons developer center (uses new interaction model).

    • For Step 7. Select Custom
    • Configure Your Skill you will need to update several entries in the Interaction Model as below
      • Invocation name Select a name that you want Alexa to use when using app (Alexa, ask myname to do something). It defaults to lgtv-remote, however the model Invocation name may only contain alphabetic characters, apostrophes, periods and spaces.
      • Configure Your Skill Select JSON Editor under Interaction Model, and replace the contents with what's included in your speechAssets/intentSchema.json file, then click Save Model.
      • Slot types Under slot types in the Interaction Model add at least 1 value for both APP_IDS(e.g. netflix, hulu, live, etc.) and INPUT_IDS (e.g. hdmi1, hdmi2), then click Save Model.
      • Build Model Once saved, click Build Model
    • Endpoints Select Endpoint* As this skill does boot up an HTTP/S server, that is what we want to use.
      • This Default Region endpoint needs to be accessible from Amazon's servers, you can use ngrok or another hosted solution that can also access the local node server running. If using ngrok, endpoint will have naming convention https://<id>.ngrok.io/lgtv-remote to reflect calling of the app. Similarly if using heroku or AWS, would need to specify the lgtv-remote application endpoint to enable Alexa to call this app.
      • If using something like ngrok or heroku, select My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority .
    • Build Model Select Custom
  2. Install all dependencies with npm install.

  3. Configure your environment. First cp .env.example .env, then manipulate the values in .env.

    • PORT the port the webserver will run on.
    • TV_MAC mac address of your LG TV (used for wake on lan)
    • TV_SOCKET ip/host socket connection (used for remote control)
    • CALLHOME URL to enable the application to remain 'active' on server
    • LGDEBUG setting this value will trigger more output for debugging purposes to the console (optional)
    • LANGUAGE currently only supports constants en for English or de for German. By changing the language in this environment variable, all intentions and invocations will be in the selected language. Also when running npm run docs, this variable will generate new speechAssets in the selected language.
  4. Run the app with npm run start.

  5. Make sure the service connect's to your TV correctly (if it is turned on of course). Then check if the webserver is reachable from Amazon's ASK. It HAS TO BE using HTTPS. You can test connectivty through Amazon's developer center.

Command Line Interface

Make sure you call them from project root. Instead of npm you can use yarn of course. For all commands check the scripts section in package.json.

Implemented Features

Remote deployment

Once I ensured the application works locally, I deployed on a Heroku server to have running in the background (could have used AWS, Google, etc). A few notes on deploying remotely: