Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MisterHouse control for a Samsung Smart TV (by Brian Klier via the mailling list)
######################################################
# Klier Home Automation - Samsung TV Control Module #
# Version 1.00 #
# By: Brian Klier #
# January 11, 2015 #
# E-Mail: brian@kliernetwork.net #
# Webpage: http://kliernetwork.net #
######################################################
#
# Based on a post on the SamyGO forum from "pjnewman" on May 10, 2011
# http://forum.samygo.tv/viewtopic.php?f=12&t=1792
#
# New in Version 1.00:
# - Initial Release
#
use MIME::Base64;
# Category=TV
$samsung_tv = new Socket_Item ('asdf', 'login', '192.168.2.155:55000', undef, 'tcp', 'raw' );
set_casesensitive $samsung_tv;
my $myip = "192.168.2.2"; # Doesn't seem to be really used
my $mymac = "00-08-02-07-02-7d"; # Used for initial access control/validation
my $appstring = "iphone..iapp.samsung"; # What the iPhone app reports
my $tvappstring = "iphone.UE32C6500.iapp.samsung"; # Might need changing to match your TV type
my $remotename = "Perl Samsung Remote"; # What gets reported when it asks for permission/also shows in General->Wireless Remote Control menu
my ($send_samsung_codes, @samsung_codes_to_send, $samsunglist);
$v_samsung_off = new Voice_Cmd("Shut off TV");
if ($state = said $v_samsung_off) {
$send_samsung_codes = "POWEROFF";
}
$v_samsung_ch4 = new Voice_Cmd("Turn TV to Channel 4");
if ($state = said $v_samsung_ch4) {
$send_samsung_codes = "4,ENTER";
}
$v_samsung_ch52 = new Voice_Cmd("Turn TV to Channel 5.2");
if ($state = said $v_samsung_ch52) {
$send_samsung_codes = "5,PLUS100,2,ENTER";
}
$v_samsung_ch5times = new Voice_Cmd("Turn Channel Up 5 Times");
if ($state = said $v_samsung_ch5times) {
$send_samsung_codes = "CHUP,CHUP,CHUP,CHUP,CHUP";
}
$v_samsung_ch5dwntimes = new Voice_Cmd("Turn Channel Down 5 Times");
if ($state = said $v_samsung_ch5dwntimes) {
$send_samsung_codes = "CHDOWN,CHDOWN,CHDOWN,CHDOWN,CHDOWN";
}
$v_samsung_key = new Voice_Cmd("Send
[POWEROFF,SOURCE,0,1,2,3,4,5,6,7,8,9,PLUS100,TTX_MIX,PRECH,MENU,GUIDE,CONTENTS,TOOLS,INFO,EXIT,CHUP,CHDOWN,CH_LIST,VOLUP,VOLDOWN,MUTE,UP,LEFT,RIGHT,DOWN,ENTER,RED,GREEN,Y
ELLOW,CYAN,W_LINK,RSS,MTS,AD,PICTURE_SIZE,CAPTION,REWIND,PAUSE,FF,REC,PLAY,STOP,TV] to Samsung TV");
if ($state = said $v_samsung_key) {
$samsung_tv->start;
my $messagepart1 = chr(0x64) . chr(0x00) . chr(length(encode_base64($myip, ""))) . chr(0x00) . encode_base64($myip, "") . chr(length(encode_base64($mymac, ""))) .
chr(0x00) . encode_base64($mymac, "") . chr(length(encode_base64($remotename, ""))) . chr(0x00) . encode_base64($remotename, "");
my $part1 = chr(0x00) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart1)) . chr(0x00) . $messagepart1;
set $samsung_tv $part1;
my $messagepart2 = chr(0xc8) . chr(0x00);
my $part2 = chr(0x00) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart2)) . chr(0x00) . $messagepart2;
set $samsung_tv $part2;
my $key = "KEY_" . state $v_samsung_key;
my $messagepart3 = chr(0x00) . chr(0x00) . chr(0x00) . chr(length(encode_base64($key, ""))) . chr(0x00) . encode_base64($key, "");
my $part3 = chr(0x00) . chr(length($tvappstring)) . chr(0x00) . $tvappstring . chr(length($messagepart3)) . chr(0x00) . $messagepart3;
set $samsung_tv $part3;
$samsung_tv->stop;
}
# When send_samsung_codes variable changes, send the codes to the TV and clear the variable.
# Codes to be sent sequentially should be separated by commas.
if ($send_samsung_codes ne '') {
print_log "Sending $send_samsung_codes to Samsung TV...";
$samsung_tv->start;
my $messagepart1 = chr(0x64) . chr(0x00) . chr(length(encode_base64($myip, ""))) . chr(0x00) . encode_base64($myip, "") . chr(length(encode_base64($mymac, ""))) .
chr(0x00) . encode_base64($mymac, "") . chr(length(encode_base64($remotename, ""))) . chr(0x00) . encode_base64($remotename, "");
my $part1 = chr(0x00) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart1)) . chr(0x00) . $messagepart1;
set $samsung_tv $part1;
my $messagepart2 = chr(0xc8) . chr(0x00);
my $part2 = chr(0x00) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart2)) . chr(0x00) . $messagepart2;
set $samsung_tv $part2;
@samsung_codes_to_send = (split(',', $send_samsung_codes));
foreach $samsunglist (@samsung_codes_to_send) {
my $key = "KEY_" . $samsunglist;
my $messagepart3 = chr(0x00) . chr(0x00) . chr(0x00) . chr(length(encode_base64($key, ""))) . chr(0x00) . encode_base64($key, "");
my $part3 = chr(0x00) . chr(length($tvappstring)) . chr(0x00) . $tvappstring . chr(length($messagepart3)) . chr(0x00) . $messagepart3;
set $samsung_tv $part3;
select(undef, undef, undef, 0.25);
#sleep 1;
}
$samsung_tv->stop;
$send_samsung_codes = '';
}
=for
*******************************************************
* This is a full list of keys available to TVs *
*******************************************************
KEY_MENU
KEY_UP
KEY_DOWN
KEY_LEFT
KEY_RIGHT
KEY_3
KEY_VOLUP
KEY_4
KEY_5
KEY_6
KEY_VOLDOWN
KEY_7
KEY_8
KEY_9
KEY_MUTE
KEY_CHDOWN
KEY_0
KEY_CHUP
KEY_PRECH
KEY_GREEN
KEY_YELLOW
KEY_CYAN
KEY_ADDDEL
KEY_SOURCE
KEY_INFO
KEY_PIP_ONOFF
KEY_PIP_SWAP
KEY_PLUS100
KEY_CAPTION
KEY_PMODE
KEY_TTX_MIX
KEY_TV
KEY_PICTURE_SIZE
KEY_AD
KEY_PIP_SIZE
KEY_MAGIC_CHANNEL
KEY_PIP_SCAN
KEY_PIP_CHUP
KEY_PIP_CHDOWN
KEY_DEVICE_CONNECT
KEY_HELP
KEY_ANTENA
KEY_CONVERGENCE
KEY_11
KEY_12
KEY_AUTO_PROGRAM
KEY_FACTORY
KEY_3SPEED
KEY_RSURF
KEY_ASPECT
KEY_TOPMENU
KEY_GAME
KEY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
KEY_EXT6
KEY_EXT7
KEY_EXT8
KEY_EXT9
KEY_EXT10
KEY_EXT11
KEY_EXT12
KEY_EXT13
KEY_EXT14
KEY_EXT15
KEY_EXT16
KEY_EXT17
KEY_EXT18
KEY_EXT19
KEY_EXT20
KEY_EXT21
KEY_EXT22
KEY_EXT23
KEY_EXT24
KEY_EXT25
KEY_EXT26
KEY_EXT27
KEY_EXT28
KEY_EXT29
KEY_EXT30
KEY_EXT31
KEY_EXT32
KEY_EXT33
KEY_EXT34
KEY_EXT35
KEY_EXT36
KEY_EXT37
KEY_EXT38
KEY_EXT39
KEY_EXT40
KEY_EXT41
=cut
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.