Page 1 of 4

Samsung Smart TV (on or off)

Posted: Monday 22 December 2014 15:40
by proohu01
Does anyone know, whether or not it is possible to detect if a Samsung Smart TV is turned on or off using the network connection?

Re: Samsung Smart TV (on or off)

Posted: Monday 22 December 2014 15:48
Probably "YES". My TV (old one now) will not respond to a "ping" when it is in standby, but WILL respond when "on". You can use a script to ping the TV occasionally and to set the state of a dummy switch. This is described in a separate part of the wiki under "presence detection". The script is called something like "check_device_online.py". You would need to modify this for your TV's IP address (I assume it is static?) and to start a CRON job which runs this script every hour. I have this script running to ping a mobile phone.

Re: Samsung Smart TV (on or off)

Posted: Monday 22 December 2014 15:58
by proohu01
Thnx for the reply.
I already use the ping script for some other devices so I am familiar with that. I also own an Onkio receiver and that has a very cool (linux) command line tool that can control almost any function and also query the power state. That's (in my opinion) a more intelligent approach than a ping so I was hoping to accomplish the same functionality with my Samsung TV's.

Re: Samsung Smart TV (on or off)

Posted: Monday 22 December 2014 16:28
by ThinkPad
Maybe start with telling us the type of TV you have ;)

Re: Samsung Smart TV (on or off)

Posted: Monday 22 December 2014 17:13
by roblom
Tested it, and it works on my Samsung TV that is connected to the internet.

Re: Samsung Smart TV (on or off)

Posted: Monday 22 December 2014 19:21
Understood about the intelligent query - much better solution if available. My old (series 6) Samsung does not appear to expose a web-page or a command-line interface. I don't think (?) it has any SNMP functionality either, but that might be worth a check? This is outside my (current) expertise... One other thought: my TV is plugged into a Z-wave switched socket with a power metering function (to provide the ultimate "off" control!). I can easily see if the TV is on (about 70 Watts) or in standby (about 5 watts) using the switch data.

Re: Samsung Smart TV (on or off)

Posted: Monday 22 December 2014 20:28
by proohu01
Haha Tony, you keep telling me stuff I already use :lol: ;) I use a Plugwise circle to monitor the power usage and a LUA script to switch the LED lights (Fibaro RGBW z-wave controller) behind the TV on or off automatically based on the power usage. So all is working. Wel, most off the time anyway. Sometimes the powerusage is not returned. Probably has something to do with the range op my Plugwise network.

It's just that there are APP's for your Android and iPhone that can controle certain aspects of the TV. If an APP can do that, why not Domoticz. At least, that was my way of thinking.
Btw, I have a UE40H6200 and a UE55F8000

Re: Samsung Smart TV (on or off)

Posted: Monday 22 December 2014 23:13
by tommit01
Just have a look..

Think there should also be a REST API

http://www.samsungdforum.com/Guide/

Re: Samsung Smart TV (on or off)

Posted: Monday 22 December 2014 23:20
by pvm
Possibly more information by Samsung, this needs some development...

And just for fun, sending commands to TV can be done from LUA, see this

Re: Samsung Smart TV (on or off)

Posted: Tuesday 23 December 2014 7:42
by proohu01
pvm wrote:Possibly more information by Samsung, this needs some development...

And just for fun, sending commands to TV can be done from LUA, see this
Thnx. I will give this a go...

Re: Samsung Smart TV (on or off)

Posted: Tuesday 23 December 2014 10:33
by pvm
Keep us posted, it would be nice to see webcam in dual screen view when doorbel rings, or things like that

Re: Samsung Smart TV (on or off)

Posted: Thursday 15 January 2015 15:01
by mlamie
Something like http://youtu.be/5uvGQ8TuWBg

That seems quite interesting.

Re: Samsung Smart TV (on or off)

Posted: Thursday 15 January 2015 17:20
by frostwork
the samsung remote sourcecode posted here might help:
http://forum.samygo.tv/viewtopic.php?f=12&t=5794
there doesn't seem to be a license though

it worked very fine on my samsungtv, but I decided that I do not want my tv to be in the network and thererfore control it via harmonyhub instead.
maybe also worth to mention that several (all?) samsung tvs can't be turned on via wol, as the network has no power when the tv is turned off.

Samsung Smart TV (on or off)

Posted: Thursday 25 June 2015 11:46
by Hesmink
Hi,

I'm checking if my Samsung TV is on or off using ping.
Since I'm using a dummy light switch for this, I thought it would be nice to be able to turn the tv off by clicking on the switch icon.

I have a working python script that turns the tv off. Can I use this as an 'off action' for the switch?
I tried, but it doesn't work. The python scripts works fine from the command line. Are script actions logged somewhere?

Re: Samsung Smart TV (on or off)

Posted: Thursday 25 June 2015 12:05
by proohu01
What is the exact line you entered in the 'off action' field?
And can you share you script?

Re: Samsung Smart TV (on or off)

Posted: Thursday 25 June 2015 12:14
by Hesmink
proohu01 wrote:What is the exact line you entered in the 'off action' field?
And can you share you script?
The off action is:
script://domoticz/scripts/samsung_tv_off.py

The script is a slightly modified version of something I found on the internet:

Code: Select all

#!  /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

#
# Variables
#
#IP Address of TV
tvip = "192.168.178.16"
#IP Address of TV
myip = "192.168.178.14"
#Used for the access control/validation, but not after that AFAIK
mymac = "b8-27-eb-f1-5a-f3"
#Might need changing to match your TV type
tvappstring = "iphone.UE46ES8000.iapp.samsung"
#What gets reported when it asks for permission
remotename = "Domoticz Samsung Remote"

#What the iPhone app reports (don't change this)
appstring = "iphone..iapp.samsung"

# 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
 dataSock.send(part3);

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

# 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
sock.send(part1)

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

# Now send the keys as you like, e.g.,
sendKey("KEY_TVPOWEROFF",sock,tvappstring)

# Close the socket when done
sock.close()

Re: Samsung Smart TV (on or off)

Posted: Thursday 25 June 2015 12:40
by proohu01
I presume that the Python file is executable for your pi user?
Have you tried this: "script:///home/pi/domoticz/scripts/samsung_tv_off.py"

I will try this script myself tonight.

Re: Samsung Smart TV (on or off)

Posted: Thursday 25 June 2015 13:11
by Hesmink
proohu01 wrote:I presume that the Python file is executable for your pi user?
Have you tried this: "script:///home/pi/domoticz/scripts/samsung_tv_off.py"

I will try this script myself tonight.
Yes! That works!

I also made the mistake to change the TV type to my own, but somehow that broke the script.
I changed the line back to:
tvappstring = "iphone.UE55C8000.iapp.samsung"
and using your full path, fixed it.

I'll probably never use is, but now I can turn my tv off using Domiticz 8-)

Re: Samsung Smart TV (on or off)

Posted: Tuesday 07 July 2015 19:53
by CalvinTy
Ok, I am an absolute beginner here. Can you guide us step by step exactly what we need to do to interface with the Samsung TV and execute the command please? Hopefully, when I understand how to do this properly, I can actually contribute back to the community.

Re: Samsung Smart TV (on or off)

Posted: Tuesday 07 July 2015 20:21
by Hesmink
CalvinTy wrote:Ok, I am an absolute beginner here. Can you guide us step by step exactly what we need to do to interface with the Samsung TV and execute the command please? Hopefully, when I understand how to do this properly, I can actually contribute back to the community.
First create a dummy switch for your TV, and ping it to know if it's on.
You can find how to do that in the wiki: http://www.domoticz.com/wiki/Presence_detection

Second, use the python script in this topic (samsungremote.py), and substitute your tv IP address in the script.

Then, use the script as 'off' action for your TV switch:
script:///home/pi/domoticz/scripts/samsung_tv_off.py