Let's make the world a better place using digital technologies!

Samsung TV Remote Control over LAN/WLAN using Python

For quite some time, I have been looking for a method to control my Samsung UE55C8000 TV using Linux scripts. Finally, I found this forum post on SamyGo that provides an example using Perl. As I like to do scripting in Python, so I have translated the script to Python with some minor changes. As you can see in the following Python code, the script contains Key names for all the remote control keys and even some extra. You should be able to easily modify the script to your needs. The script can also be downloaded on my download page.

#!  /usr/bin/python
#   Title: samsungremote.py
#   Author: Asif Iqbal
#   Date: 05APR2012
#   Info: To send remote control commands to the Samsung tv over LAN
#   TODO:

import socket
import base64
import time, datetime

#IP Address of TV
tvip = ""
#IP Address of TV
myip = ""
#Used for the access control/validation, but not after that AFAIK
mymac = "00-0c-29-3e-b1-4f"
#What the iPhone app reports
appstring = "iphone..iapp.samsung"
#Might need changing to match your TV type
tvappstring = "iphone.UE55C8000.iapp.samsung"
#What gets reported when it asks for permission
remotename = "Python Samsung Remote" 

# Function to send keys
def sendKey(skey, dataSock, appstring):
 messagepart3 = chr(0x00) + chr(0x00) + chr(0x00) + chr(len(
base64.b64encode(skey))) + chr(0x00) + base64.b64encode(skey);
 part3 = chr(0x00) + chr(len(appstring)) + chr(0x00) \
+ appstring + chr(len(messagepart3)) + chr(0x00) + messagepart3

# Open Socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((tvip, 55000))

# Key Reference
# Normal remote keys
 #KEY_W_LINK #Media P
 #KEY_RSS #Internet
 #KEY_MTS #Dual
# Bonus buttons not on the normal remote:
#Don't work/wrong codes:

# First configure the connection
ipencoded = base64.b64encode(myip)
macencoded = base64.b64encode(mymac)
messagepart1 = chr(0x64) + chr(0x00) + chr(len(ipencoded)) \
+ chr(0x00) + ipencoded + chr(len(macencoded)) + chr(0x00) \
+ macencoded + chr(len(base64.b64encode(remotename))) + chr(0x00) \
+ base64.b64encode(remotename)

part1 = chr(0x00) + chr(len(appstring)) + chr(0x00) + appstring \
+ chr(len(messagepart1)) + chr(0x00) + messagepart1

messagepart2 = chr(0xc8) + chr(0x00)
part2 = chr(0x00) + chr(len(appstring)) + chr(0x00) + appstring \
+ chr(len(messagepart2)) + chr(0x00) + messagepart2

# Now send the keys as you like, e.g.,

# Close the socket when done




View more posts from this author
33 thoughts on “Samsung TV Remote Control over LAN/WLAN using Python
  1. Marco


    Well Done on creating the above

    I am also trying to do the same but having a few problems

    Basically I have created a LUA script based on your python to control the Samsung TV’s over IP

    I can Send The KEY CODES to the set with no problem!

    My problem is that i want to go a bit further and do the following

    -send a command to the TV that opens the Web Browser, or the Photos APP, or even BBC IPLAYER.

    I have sniffed ( wireshark) the set whilst opening the Photos app and managed to find in the TCP Stream the following


    Running this against a Base 64 decoder the result is:


    I have also noticed that IT is a HTTP GET command.

    This TCP Stream was on port 55001

    Now I am completely stuck not knowing what to do next!

    Interested in Helping?

    If So could you create a simple python script that opens say the web browser or the photos app in the TV?
    you can come back to me on marcodias@me.com


    1. admin

      Hello Marco

      Thanks for your comment. If I understand your correctly, then you have already found the solution to what you want to do. Why not simply send “http://TVIPADDRESS:55001/action?select=31_photos” to the TV base64 encoded?

  2. Pingback: Samsung TV Remote Control » xfp's docs

  3. Ozgur


    Thank you for your work. I was also trying to write such sw with c#. I first sniffed GEMOTE app with wireshark. And sent the the same data to my tv with my code but it did not work. I also tried your code with python 3.2.3. I receive below error code;

    Traceback (most recent call last):
    File “C:\Documents and Settings\Özgür Karadeniz\Desktop\samsungremote.py”, line 100, in
    ipencoded = base64.b64encode(myip)
    File “C:\Python32\lib\base64.py”, line 56, in b64encode
    raise TypeError(“expected bytes, not %s” % s.__class__.__name__)
    TypeError: expected bytes, not str

    Could you please help. I am stuck. Thank you…

  4. Özgür


    Thank for your application. I was just trying to write a sw like yours in order to manage channel recording from a usefull interface. I captured GreenFlowRemote with wireshark and sent exactly the same data with my code written in c#. But I am unable to control my tv. I can see the same datas as GreenFlow on wireshark but does not control.

    After that I found your usefull application. But I run your application with Python2. I tried to send only below command;


    it gives no error but does not control tv. Tv also did not as for permission for your application. Could you help?

    1. admin

      Hello Özgür

      I am not aware of how GreenFlowRemote works. Perhaps it sends certain “extra” information that you have not been able to capture.

      On the other hand, my Python script should work actually. Perhaps you have not copied the script correctly. I would suggest downloading it from the link given in my post and then trying.

  5. Jismo

    I tried to tranform this code to python 3 and i noticed that the authentification doesn’t work even if i send the exact same informations. Later i tried to remove the second message and suddenly it works.

    Maybe this could help someone who tries to transform this into another language. Just send the first message and after that you can pass any message corresponding to a key. Even if the application authorized is not authorized you can authentificate with the first message only.

    If someone found out how to send more commands than keys or even recieve informations from the tv, i would the very interested even if it needs samygo!

  6. Sab

    Greate post. Really found it usefull. What I wanted to know is why do we add som any null charaters (chr(0x00)) in the script?

  7. Chopper_Rob

    Works perfect, i see some nice domotica possiblities 🙂
    And i found an extra key KEY_HDMI, this allows you to toggle between active HDMI sources. Very useful if you only have one active HDMI port.

  8. steve

    I am not a programmer but I was looking for a way to try and put caller id name and number from Asterisk (PBX) on my Samsung TV. Are you familiar with Asterisk or have any interest in this?

    1. admin

      Hi Steve
      I do not have information about your question. I am also an Asterisk user and would be interested in knowing how it can be done. I think you can send such information from Asterisk to dreambox which should then appear on the TV (provided, of course, that you are using dreambox).

  9. Sam

    I have a Samsung HT-E6750W Blu ray home theatre system. Most of the commands work such as “KEY_VOLUP”, KEY_CHUP, ect however I can’t find a command that works for power. I have tried the following codes with no luck and have searched through numerous forums.


    Any Suggestions??

    1. admin

      I am not aware of any power command. I would also be interesting in knowing if there is such a command.
      I suspect that, other than by IR remote, the power is handled at the HDMI-CEC level only.

      1. Rekk

        I have a Samsung 46F6400 and I’m trying to control my TV through an application (mobile app, or WebApp, or PC app) in order to integrate it in a automation installation. Your program works well except for powering on the TV.
        I couldn’t ping the TV when it’s powered off, so there is no way to power on the TV. But, in there are talking about power on/off the TV through the HDMI-CEC, as you suggest, with a Raspberry Pi.

  10. PeterPArker

    I’m getting a error in the scrip that says something like thist:

    “No connection can be made because the receiving pc actively rejects it”

    I got the IPs and macs putted correcly…is it something with the port 55000?

  11. Andrew

    Where did you get the codes for the controls/remote keys? Are there any more? The power on and off functionality would be great. Has there been any further development/new info on the power issue?

  12. J G Miller

    Thank you for creating such a useful utility.

    I suspect that this may very well be impossible, but here goes …

    Is there any way to get back the information as to which TV station is currently being viewed, or to grab a screen capture?

  13. Ramin

    I used Python 2.x and 3.x but return an error aftern run (f5):
    Traceback (most recent call last):
    File “C:\Users\VANDA\Desktop\ss.py”, line 35, in
    sock.connect((tvip, 55000))
    TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

    my tv model is F6400

  14. terragona

    Traceback (most recent call last):
    File “remote.py”, line 122, in
    File “remote.py”, line 31, in sendKey
    socket.error: [Errno 32] Broken pipe

    on UE40ES5500, why?


Leave a Reply

Your email address will not be published. Required fields are marked *