Giter VIP home page Giter VIP logo

amazon-alexa-as-lg-tv-remote's Introduction

Alexa-LG-TV-Controller

Makes use of Klattimer's LGWebOSRemote module and Sinric's faux WEEMOS creator to control any smart LG TV with Alexa. This python script monitors Alexa's commands through Sinric, and then executes it using LG's nodejs API. It will allow you to turn on/off an LG tv and much more ... all from your Alexa device.

Supported models

Tested with

  • UF830V
  • UH650V
  • UJ635V
  • HU80KG.AEU (CineBeam 4K)
  • [please add more!]

Tested with python 2.7 on linux.

Likely supports

All devices with firmware major version 4, product name "webOSTV 2.0/3.0"

Available Alexa Commands

ChannelDown      
ChannelUp        
FastForward  
Pause       
Play        
Rewind                             
mute                  
off                   
on                    
Set Input          input(HDMI 1,HDMI 2 ...)
Set Channel        channel_number
Set Volume         level                
Volume Down            
Volume Up

Setup

Requires wakeonlan, websocket and websocket-client for python and arp (in Debian/Ubuntu: apt-get install net-tools)

There's a requirements.txt included

 1.)  Setup your sinric account at https://sinric.com/
 2.)  Login to your account and click add smart home device, give the device a name and choose TV as device type
 ----> it is good at this point to copy the api of the device 
 3.)  On the Alexa app go to 'skills & games' and install sinric's skill and login to your account
 4.)  The fake device you just created on the website should then be seen in the Alexa app under 'devices'

# Now enter the directory with the files and type in command line 
------------------------------------->
1.)  pip install -r requirements.txt
2.)  sudo python setup.py
------------------------------------->
---> This will scan for your LG tv and will show the IP address of all LG tv's on the local network
# Example :
{
"count": 1, 
"list": [
    {
        "address": "192.168.0.158", 
        "model": "OLEDXXXXX", 
        "uuid": "0b6405648-ccc7-ab45f-967d-8gd47f21346"
    }
], 
"result": "ok"
}
---> You will then be prompted to enter the ip address of the TV you want to authorise on
please enter  ip like '192.168.0.158' (make sure to use brackets)
3.)  Enter IP address of TV, and a notification will pop up on the TV screen (click authorise on TV)

4.)  Now open the Alexa.py file and edit line 80. Here you need to replace :
# Example :
line 80 | api = ' enter-api-here  ' 
becomes 
line 80 | api = '65a23cd9-2e5d-495c-b4bd-5abfgh3l60345'

5.)  The final step is to start the Alexa.py file : 
          sudo python Alexa.py
     or to run in the background once terminal closes. Use: 
          sudo chmod +x Alexa.py
          nohup python /full/path/to/Alexa.py &
          logout

FeLiNa

Once all the steps above have been completed, and the python script is running, try telling your Alexa device to change your tv volume by saying

ALEXA SET (Sinric Device Name) VOLUME TO (intended level)

Caveats

You need to run setup.py whilst the TV is on as it will need to pull the mac address of the device.

CREDITS

I want to give a big thanks to klattimer whose library I used in this project -> https://github.com/klattimer/LGWebOSRemote/

amazon-alexa-as-lg-tv-remote's People

Contributors

felina22 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

amazon-alexa-as-lg-tv-remote's Issues

Tested on [LG] webOS TV OLED65B6P

Tested on [LG] webOS TV OLED65B6P - works great!

Any idea what (if possible) the wording is for the Alexa command to open an app like YouTube or Netflix? These apps do show up in applists.json .

Can't turn TV on

Hi again :)

Everything is working great, tested many of the functions. The only function that I can't get to work is to have Alexa power on my TV..

After I ask Alexa to turn TV on, I see the following in terminal:

messy : {"deviceId":"5c4bac8c398dcc587988bd0f","action":"setPowerState","value":"ON"}
ERROR LOL : Connection is already closed.
### closed ###
### Initiating new websocket connection ###

Can't turn on TV again

Hi,
Thank you for your amazing Alexa LG tv remote :)
Generally, most functions work well but I found that I can't turn on the TV after off
I know this issue happened before, but It happens again that reporting here

messy : {"deviceId":"5da2a92ca0866720351af2cd","action":"setPowerState","value":"OFF"}
{"type": "response", "id": "0", "payload": {"returnValue": true}}
{"closing": {"reason": "server shutting down", "code": 1001}}

messy : {"deviceId":"5da2a92ca0866720351af2cd","action":"setPowerState","value":"ON"}
ERROR LOL : [Errno 54] Connection reset by peer

closed

It seems the main problem is a "connection"
May I ask how to solve this issue? (I know you don't handle this project anymore :( So, I apologise)

Thank you

Issue running setup.py

Here is the error I receive when I run setup.py:

Traceback (most recent call last):
File "setup.py", line 3, in
LGparser(['scan'])
NameError: name 'LGparser' is not defined

I tried running using sudo and receive the following error:

Traceback (most recent call last):
File "setup.py", line 1, in
import lgtv
File "/home/pi/GitHub/amazon-alexa-lg-tv/lgtv.py", line 6, in
from LGTV import LGTVScan, LGTVClient, getCommands
File "/home/pi/GitHub/amazon-alexa-lg-tv/LGTV/init.py", line 2, in
from ws4py.client.threadedclient import WebSocketClient
ImportError: No module named ws4py.client.threadedclient

Can not find TV when TV is connected to a device running the script

I have a router running on a raspberry pi and I have this Lg tv controller on the same device. When I have the TV connected to the main network this program works fine. I have my phone connected to the subnetwork router on the pi so I would also like the tv connected to that same network so I can easily use the Lg tv app. When I run the setup.py it cannot find the tv even when typing in the IP address or localhost. Is there any way to do this?

LG TV UN74003LB Issue

Hi,

i have used your script to control my old 55UK6750 which 3 weeks ago, died. Now i have UN74003LB, i and setup your application as last time. Everything works, but the LG TV UN74003LB is constantly is asking me AUTHORISE that LG remote app to connect to my TV, when i ask ALEXA to do something.

Last time, 55UK6750 TV only the first time ask me and that's all.
Is it possible to fix the LG TV UN74003LB, by adding some code in the script as automatic authorization, after setup?

I have openhab2, and everything works, NO authorization is needed.

No handlers could be found for logger "ws4py"

After I say YES on the TV I got the error

$ sudo python setup.py
timed out
timed out
timed out
timed out
{
"count": 0,
"result": "failed"
}
Enter IP of TV : '192.168.1.68'
No handlers could be found for logger "ws4py"
{"closing": {"reason": "Going away", "code": 1006}}
Traceback (most recent call last):
File "setup.py", line 10, in
lgtv.LGparser(['listChannels'])
File "/home/ribeiro/amazon-alexa-lg-tv-master/lgtv.py", line 113, in LGparser
ws.connect()
File "/home/ribeiro/.local/lib/python2.7/site-packages/ws4py/client/init.py", line 217, in connect
self.sock.connect(self.bind_addr)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused
$

Open Apps?

Got it working on OLED55B7A, also any plans to implement app launching? Or any guidelines so I can implement?

Syntax eroror

I am running this in a Windows environment, I have installed node.js and python successfully installed all the requirements however when it comes to running the setup.py script it imports the LG module then fails on line 113 complaining about syntax with the brackets, please can someone advise who has this working in a Windows env.

Thanks

Test on Uh661

Hi first of all thx you for giving us a bridge to work with our 'obsolete' tv.
I'm having problem on changeChannel:
image

Not working after all steps

Hi there!,

I followed all instruction, I authorized the app in my TV. The device is recognized in Alexa, but when I say some instruction, nothing happen on the tv and Alexa says "ok". In the shell I have the following lines:

Initiating new websocket connection

messy : {"deviceId":"5cb11c6e9f58230ab4c3c525","action":"setPowerState","value":"OFF"}
messy : {"deviceId":"5cb11c6e9f58230ab4c3c525","action":"setPowerState","value":"OFF"}
messy : {"deviceId":"5cb11c6e9f58230ab4c3c525","action":"SetVolume","value":{"volume":10}}
messy : {"deviceId":"5cb11c6e9f58230ab4c3c525","action":"SetVolume","value":{"volume":0}}

Something to do extra or again??

regards!

Power ON don't work

Hello, everything is fine on my tv.
I putted on the wake on lan.
TV is connected by ethernet

Syntax error running Alexa.py

Hi FeLiNa22 - Opening a new issue as I received the following syntax error when running python Alexa.py (after running setup.py and entering my sinric API key in line 80):

File "Alexa.py", line 81
ws = websocket.WebSocketApp("ws://iot.sinric.com/",header={'Authorization:' + base64.b64encode('apikey: +' api '+ ')},on_message = on_message,on_error = on_error, on_close = on_close)
^
SyntaxError: invalid syntax

promting allow to connect every request

Hi,

I succesfully made this app working with alexa, but the only problem is that every time I ask alexa to do something with tv there is a promt on my tv to allow access for the app.

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.