PHP
Need help with PHP-LG-SmartTV?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.
StefanNemeth

Description

PHP API for the remote control of LG SmartTV (2012-2013 models)

124 Stars 37 Forks Apache License 2.0 15 Commits 2 Opened issues

Services available

Need anything else?

PHP-LG-SmartTV

A PHP API for the LG SmartTV (2012+) which makes it easy for you to remote control your TV with code. You're able to execute simple/special commands and queries (change channel, get current channel, get channel list, set volume up, set volume down, save screenshot - save gif animation, ...)

You can find command parameters and query structures on the Official Documentation of the LG SmartTV (There is also a command/query list below the examples)

NEEDS CURL

How to connect to your TV

/**

  • Create instance of TV
  • @param IP Address of TV
  • (optional) @param Port of TV (default is 8080) **/ $tv = new SmartTV('192.168.2.103'); // new SmartTV('192.168.2.103', 8080)

/**

  • Set pairing key (if you don't know the pairing key
  • execute the method ..->displayPairingKey() and it will
  • be shown on your tv)
  • @param Key

**/ $tv->setPairingKey(678887); // $tv->displayPairingKey();

/**

  • Authenticate to the tv
  • @except Login fails (wrong pairing key?) **/ try { $tv->authenticate(); } catch (Exception $e) { die('Authentication failed, I am sorry.'); }

How to execute a simple command

  • Set your volume up. **/ $tv->processCommand(TV_CMD_VOLUME_UP);
  • /**

    • Set your volume down **/ $tv->processCommand(TV_CMD_VOLUME_DOWN);

    How to execute a special command

  • Move your mouse **/ $tv->processCommand(TV_CMD_MOUSE_MOVE, [ 'x' => 20, 'y' => 20 ]);
  • /**

    • Trigger a mouse click **/ $tv->processCommand(TV_CMD_MOUSE_CLICK);

    How to change your channel

  • Change channel (Channel VIVA) **/
  • // Get channel list $channels = $tv->queryData(TV_INFO_CHANNEL_LIST);

    // Channel name $channelName = 'VIVA';

    // Search for channel $channelName foreach ($channels as $channel) { if ($channel->chname == $channelName) { // Change channel $tv->processCommand(TV_CMD_CHANGE_CHANNEL, $channel); break; } }

    How to query data

    queryData(TV_INFO_VOLUME)->level;
    
    

    /**

    • Get current channel name **/ echo $tv->queryData(TV_INFO_CURRENT_CHANNEL)->chname;

    How to save a screenshot

  • Save a screenshot **/ file_put_contents('screen.jpeg', $tv->queryData(TV_INFO_SCREEN));
  • Practical Example

    example

    You can find the code of the Practical Example here.

    List of commands and queries (+ Documentation links)

    Simple commands TVCMDPOWER, TVCMDNUMBER0, TVCMDNUMBER1, TVCMDNUMBER2, TVCMDNUMBER3, TVCMDNUMBER4, TVCMDNUMBER5, TVCMDNUMBER6, TVCMDNUMBER7, TVCMDNUMBER8, TVCMDNUMBER9, TVCMDUP, TVCMDDOWN, TVCMDLEFT, TVCMDRIGHT, TVCMDOK, TVCMDHOMEMENU, TVCMDBACK, TVCMDVOLUMEUP, TVCMDVOLUMEDOWN, TVCMDMUTETOGGLE, TVCMDCHANNELUP, TVCMDCHANNELDOWN, TVCMDBLUE, TVCMDGREEN, TVCMDRED, TVCMDYELLOW, TVCMDPLAY, TVCMDPAUSE, TVCMDSTOP, TVCMDFASTFORWARD, TVCMDREWIND, TVCMDSKIPFORWARD, TVCMDSKIPBACKWARD, TVCMDRECORD, TVCMDRECORDINGLIST, TVCMDREPEAT, TVCMDLIVETV, TVCMDEPG, TVCMDPROGRAMINFORMATION, TVCMDASPECTRATIO, TVCMDEXTERNALINPUT, TVCMDPIPSECONDARYVIDEO, TVCMDSHOWSUBTITLE, TVCMDPROGRAMLIST, TVCMDTELETEXT, TVCMDMARK, TVCMD3DVIDEO, TVCMD3DLR, TVCMDDASH, TVCMDPREVIOUSCHANNEL, TVCMDFAVORITECHANNEL, TVCMDQUICKMENU, TVCMDTEXTOPTION, TVCMDAUDIODESCRIPTION, TVCMDENERGYSAVING, TVCMDAVMODE, TVCMDSIMPLINK, TVCMDEXIT, TVCMDRESERVATIONPROGRAMLIST, TVCMDPIPCHANNELUP, TVCMDPIPCHANNELDOWN, TVCMDSWITCHVIDEO, TVCMD_APPS,

    Special commands TVCMDMOUSE_MOVE, TVCMDMOUSE_CLICK, TVCMDTOUCH_WHEEL, TVCMDCHANGE_CHANNEL

    Queries TVINFOCURRENT_CHANNEL, TVINFOCHANNEL_LIST, TVINFOCONTEXT_UI, TVINFOVOLUME, TVINFOSCREEN, TVINFO3D

    We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.