Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Samsung TV Remote Control Python Script
import time
import socket
import base64
src = '192.168.1.2' # ip of remote
mac = '00-AB-11-11-11-11' # mac of remote
remote = 'python remote' # remote name
dst = '192.168.1.3' # ip of tv
app = 'python' # iphone..iapp.samsung
tv = 'LE32C650' # iphone.LE32C650.iapp.samsung
def push(key):
new = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
new.connect((dst, 55000))
msg = chr(0x64) + chr(0x00) +\
chr(len(base64.b64encode(src))) + chr(0x00) + base64.b64encode(src) +\
chr(len(base64.b64encode(mac))) + chr(0x00) + base64.b64encode(mac) +\
chr(len(base64.b64encode(remote))) + chr(0x00) + base64.b64encode(remote)
pkt = chr(0x00) +\
chr(len(app)) + chr(0x00) + app +\
chr(len(msg)) + chr(0x00) + msg
new.send(pkt)
msg = chr(0x00) + chr(0x00) + chr(0x00) +\
chr(len(base64.b64encode(key))) + chr(0x00) + base64.b64encode(key)
pkt = chr(0x00) +\
chr(len(tv)) + chr(0x00) + tv +\
chr(len(msg)) + chr(0x00) + msg
new.send(pkt)
new.close()
time.sleep(0.1)
while True:
# switch to tv
push("KEY_TV")
# switch to channel one
push("KEY_1")
push("KEY_ENTER")
time.sleep(5)
# switch to channel 15
push("KEY_1")
push("KEY_5")
push("KEY_ENTER")
time.sleep(5)
# switch to HDMI
push("KEY_HDMI")
time.sleep(5)
@ccampanale

This comment has been minimized.

Copy link

commented Apr 27, 2015

Love this. Made a port to Ruby that I will push to GH sometime. Thanks so much for posting this! 😄

@cherezov

This comment has been minimized.

Copy link

commented Jan 15, 2016

Briliant! Thanks for sharing this! Made a port to Python3 and use it in my home automation project (smarpy)!

@mmphego

This comment has been minimized.

Copy link

commented Jun 20, 2016

I am unable to connect, please help
In [4]: new = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

In [5]: new.conne
new.connect new.connect_ex

In [5]: new.connect(('192.168.1.2', 55000))

ConnectionRefusedError Traceback (most recent call last)
in ()
----> 1 new.connect(('192.168.1.2', 55000))

ConnectionRefusedError: [Errno 111] Connection refused

@adriandelcl

This comment has been minimized.

Copy link

commented Sep 8, 2017

Same error here.

Conection refused.

@smhaggerty

This comment has been minimized.

Copy link

commented Sep 20, 2017

What is the model number of the TV you are attempting to connect to?

@CryptKid

This comment has been minimized.

Copy link

commented Oct 26, 2017

Detects my TV, terminals says, it works, but nothing happens. Maybe that has something to do with the PIN i had to enter on the App?

@jeremy7358

This comment has been minimized.

Copy link

commented Dec 30, 2017

Hi ,can it work with google home>>ifttt>> google assistant>> webhook ?
without other materials, if so how thank you very much

@WiseSage17

This comment has been minimized.

Copy link

commented Jan 10, 2018

Hi, I am also getting Connection Refused.

Python Version 2.7

src = 'MAC IP' # ip of remote
mac = 'MAC Address of IP' # mac of remote
remote = 'MAC Machine remote' # remote name
dst = 'IP OF TV' # ip of tv
app = 'python' # iphone..iapp.samsung
tv = 'LED46 - Name of TV in TV Settings' # iphone.LE32C650.iapp.samsung

Traceback (most recent call last):
File "/Users//Downloads/998441-c89144315e5fa304e51a88e352d90541b87a8f94/samsung_remote.py", line 35, in
push("KEY_TV")
File "/Users/
/Downloads/998441-c89144315e5fa304e51a88e352d90541b87a8f94/samsung_remote.py", line 15, in push
new.connect((dst, 55000))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 61] Connection refused

Ive scanned the 5 Samsun TVs i have and none of them have Port 55000 Open

@LeThinh2511

This comment has been minimized.

Copy link

commented Mar 8, 2019

Hi, I am also getting Connection Refused.

Python Version 2.7

src = 'MAC IP' # ip of remote
mac = 'MAC Address of IP' # mac of remote
remote = 'MAC Machine remote' # remote name
dst = 'IP OF TV' # ip of tv
app = 'python' # iphone..iapp.samsung
tv = 'LED46 - Name of TV in TV Settings' # iphone.LE32C650.iapp.samsung

Traceback (most recent call last):
File "/Users//Downloads/998441-c89144315e5fa304e51a88e352d90541b87a8f94/samsung_remote.py", line 35, in
push("KEY_TV")
File "/Users/
/Downloads/998441-c89144315e5fa304e51a88e352d90541b87a8f94/samsung_remote.py", line 15, in push
new.connect((dst, 55000))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 61] Connection refused

Ive scanned the 5 Samsun TVs i have and none of them have Port 55000 Open

I used port 8001 instead.

@omriarieli

This comment has been minimized.

Copy link

commented Apr 12, 2019

Hi, great work.
how can i get a list of the supported tests in my tv
what i mean is when using the smart remote feature adding my a/v receiver via optical i have a test button that switches the receiver on and off so techincally i know its possible but i cant control it after for on/off only for volume
thinking of making some kind of script to do it as long as i dont need to get up from the couch :)
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.