Want more features on Pastebin? Sign Up, it's FREE!

Sharp AQUOS power button script

By: Chriszuma on Jan 5th, 2014  |  syntax: Python  |  size: 1.56 KB  |  views: 668  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # File:  tv_power.py
  2. # Title: Sharp AQUOS power button script
  3. #
  4. # Brief:
  5. #     Connects to the TV over LAN and toggles it on/off.
  6. #
  7. #     TV must first be set up to connect to wi-fi and enable remote access (via on-screen menu),
  8. #     and have LAN turn-on enabled (by sending "RSPW2   " over putty or hyperterm).
  9. #     I use Intelliremote to kick off this script with my media center remote.
  10. #
  11. # Author:  Chris Hammond (https://www.facebook.com/Chris.A.Hammond)
  12. # Version: Jan 6, 2014
  13. #
  14. # Note: Other commands can be found on page 45 of this PDF:
  15. #       http://files.sharpusa.com/Downloads/ForHome/HomeEntertainment/LCDTVs/Manuals/tel_man_2013_fullline.pdf
  16. #
  17. # Tips: Bitcoin  1P15hKDPDqw5TkXWsWgZcg4QEH3WEcxMGM
  18. #       Dogecoin D7sqgTGt6ERQMuj7T5S3VfvSRrMHvCSSQQ
  19.  
  20. import socket
  21.  
  22. # Got this from my router's status page:
  23. tv_hostname = "unknown9444449D0E9D"
  24. # Got this from TV's setup menu:
  25. tv_port     = 10002
  26.  
  27. print "Connecting to TV..."
  28. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  29. remote_ip = socket.gethostbyname(tv_hostname)
  30. s.connect((remote_ip,tv_port))
  31. print "Connected."
  32.  
  33. # Get current power state:
  34. s.sendall("POWR?   \r")
  35. ans = s.recv(10).rstrip()
  36. if ans != '1' and ans != '0':
  37.         quit( "Failed! TV responded '%s' instead of '1' or '0'." % (ans,) )
  38. print "Current power state: %s" % (ans,)
  39.  
  40. # Send opposite power state:
  41. cmd = "POWR%d   \r" % (ans == '0')
  42. print "Sending '%s'..." % (cmd.rstrip(),)
  43. s.sendall(cmd)
  44. ans = s.recv(10).rstrip()
  45. if ans != 'OK':
  46.         quit( "Failed! TV responded '%s' instead of 'OK'." % (ans,) )
  47.  
  48. print "Success!"
clone this paste RAW Paste Data