Samsung Smart TV Plus

Questions and comments specific to a particular plugin should go here.
jachin99
Experienced User
Posts: 557
Joined: Sat Feb 13, 2016 8:39 pm

Re: Samsung Smart TV Plus

Post by jachin99 » Wed Sep 26, 2018 2:00 pm

If you can't do that via this plugin then maybe you could accomplish this via HDMI CEC. CEC is always a risk though because you never know if your TV implements the CEC function you need. Another way to do this that you might be able to look into is something like a ZWave powered outlet, and a Zstick. Maybe, if the ZWave plug will let you do this, you could check to see how much voltage the plug has passing through it, and build a macro with that variable. This is going out on a limb, and you would have to make sure its even possible but its a thought. Either way, hopefully Samsung Smart TV Plus does the job.

holdestmade
Experienced User
Posts: 174
Joined: Thu Dec 04, 2014 2:44 pm

Re: Samsung Smart TV Plus

Post by holdestmade » Fri Sep 28, 2018 6:27 am

I've been using this plugin for a while now with a 2017 and a 2018 model and it doesn't seem to create events, just works great for commands. Just wish the TV had direct HDMI selection and not a HDMI toggle sequence. I use it to switch inputs based on usb devices connected to a usb switcher with keyboard and mouse attached to 2 PCs.

I use smartthings, mainly for my ZigBee bulbs now, and this does connect to my Samsung TVs and they have a new (incomplete) REST API now. I checked and I am able to query smartthings to whether the TVs are on or off (and what's playing, channel etc) from a python script in EG.

User avatar
kgschlosser
Site Admin
Posts: 4313
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Samsung Smart TV Plus

Post by kgschlosser » Fri Sep 28, 2018 7:35 am

well how deee do. I will take a look at the REST API for smart things.
actually i will honestly be shocked if it is REST and not SOAP. I now there is a massive amount of stuff with the SOAP on Samsung TV's, what I do not know is if there is some kind of an authentication to it. I have not messed around with it to much.

Do you know if the samsungctl library generated and kind of feedback from the TV? I do not believe it did. I believe the websocket connection is one way. just for control.

Also have you tried out all of the extended commands. You may find the ones that will change the source discretely. There is a HEAP of remote actions.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4313
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Samsung Smart TV Plus

Post by kgschlosser » Fri Sep 28, 2018 8:16 am

I do not know what smart things is using to make the connection. i wish i could get my hands on one of those things to hack it and grab the code from it.
If you like the work I have been doing then feel free to Image

holdestmade
Experienced User
Posts: 174
Joined: Thu Dec 04, 2014 2:44 pm

Re: Samsung Smart TV Plus

Post by holdestmade » Fri Sep 28, 2018 12:12 pm

Hi, hope you're recovering well.

The TVs get added a devices and have remote control and 2-way feedback, think they call the communication OCF ?

Here's the link for the API, sure Samsung said it was REST but who knows. Don't think they have completed it yet and they are going through a lot of changes at the minute.

https://smartthings.developer.samsung.c ... ag/devices

Seems pretty straightforward, even I managed to get it to work from a script in EG, albeit only sending commands and reading states; I can set colours on my zigbee bulbs etc

There is a 'plugin' in smartthings that sends every event to EG via webserver so I use that for triggers in EG.

The Samsunctl library never had 2 way actions, not that I could tell anyways.
I did try all the commands and none will do a direct HDMI channel, I can select everything else discretely just not HDMI, seems OK for me as only have 2 HDMI connections so EG just toggles between the 2.

Reason I'm using smartthings at all is it has an app on my 2018 TV so I can control lights etc from my TV remote.

The V2 hubs (what I have) do pop up on ebay pretty regularly for peanuts really as there is a new V3 out now

holdestmade
Experienced User
Posts: 174
Joined: Thu Dec 04, 2014 2:44 pm

Re: Samsung Smart TV Plus

Post by holdestmade » Fri Sep 28, 2018 12:20 pm

This is script I am using. I have another script that runs every hour to check for any new devices and writes them to eg.globals.devices.
Gives you an idea anyway, sure it can be improved upon !

For example, called with:

Code: Select all

DeviceColour('Kitchen Unit Lights', 'red')

Code: Select all

#Turn on a Device
#{"commands": [{"component": "main", "capability": "switch", "command": "on"}]}

#Turn off a Device
#{"commands": [{"component": "main", "capability": "switch", "command": "off"}]}

#Dim a device
#{"commands":[{"component": "main", "capability": "switchLevel", "command": "setLevel", "arguments": [0]}]}

#Change a Colour
#{"commands":[{"component": "main", "capability": "colorControl", "command": "setColor", "arguments": [{'hex':'#ffffff'}]}]}

import urllib2, json, requests, time

devices = eg.globals.devices
API_ADDR = 'https://api.smartthings.com/v1/devices/'
API_KEY = 'Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

RGB_COLOURS = { 'RED':          '#FF0000',
                'GREEN':        '#008000',
                'BLUE':         '#0000FF',
                'WHITE':        '#FFFFFF',
                'BLACK':        '#000000',
                'LIME':         '#00FF00',
                'YELLOW':       '#FFFF00',
                'CYAN':         '#00FFFF',
                'MAGENTA':      '#FF00FF',
                'MAROON':       '#800000',
                'OLIVE':        '#808000',
                'PURPLE':       '#800080',
                'TEAL':         '#008080',
                'NAVY':         '#000080'
                }

def Request(device, data):
    req = urllib2.Request(API_ADDR + str(eg.globals.id) + '/commands')
    req.add_header('Content-Type', 'application/json')
    req.add_header('Authorization', API_KEY)
    response = urllib2.urlopen(req, json.dumps(data))

def CheckStatus(device):
    GetDeviceID(device)
    url = API_ADDR + str(eg.globals.id) + '/status'
    headers = {'Authorization': API_KEY}
    r = requests.get(url, headers=headers)
    j = r.json()
    try:
        eg.globals.health = j['components']['main']['healthCheck']['healthStatus']['value']
        print str(eg.globals.name) + " is " + eg.globals.health 
    except:
        pass
    try:
        eg.globals.status = j['components']['main']['switch']['switch']['value']
        print str(eg.globals.name) + " is " + eg.globals.status 
    except:
        pass
    try:
        eg.globals.power = j['components']['main']['powerMeter']['power']['value']
        print "Power: " + str(eg.globals.power) + "W" + ",  Current: " +str(eg.globals.power/12) + "A"
    except:
        pass
    try:
        eg.globals.state = j['components']['main']['contactSensor']['contact']['value']
        print str(eg.globals.name) + " is " + str(eg.globals.state)
    except:
        pass

def ListDevices():
    headers = {'Authorization': API_KEY}
    r = requests.get(API_ADDR, headers=headers)
    j = r.json()
    print j

def GetDeviceID(dev):
    for a in range(0,len(devices)-1,4):
        if dev == devices[a+1]:
            eg.globals.name = devices[a+1]
            eg.globals.id = devices[a+3]

def ToggleDevice(device):
    CheckStatus(device)
    if eg.globals.status == "off":
        print "Turning on"
        data = {"commands": [{"component": "main", "capability": "switch", "command": "on"}]}
    else:
        print "Turning off"
        data = {"commands": [{"component": "main", "capability": "switch", "command": "off"}]}
    Request(device, data)
    CheckStatus(device)

def DeviceColour(device, colour):
    CheckStatus(device)
    for x in range (13):
        if colour in RGB_COLOURS:
            hex = RGB_COLOURS.get(colour.upper())
        else:
            hex = "#FFFFFF"
    data = {"commands":[{"component": "main", "capability": "colorControl", "command": "setColor", "arguments": [{'hex': str(hex)}]}]}
    Request(device, data)

User avatar
kgschlosser
Site Admin
Posts: 4313
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Samsung Smart TV Plus

Post by kgschlosser » Sun Sep 30, 2018 10:15 am

@ therealbiglou

Sorry I must have missed your comment.

But to answer your question. Samsung has locked out the API on the TV's// actually well most of their devices. we are lucky to even have the ability to send remote commands to the TV. Depending on what year TV you have is going to dictate if you can turn the TV on over the network. On older(ish) TV's when you put the TV into standby "off" the network adapter/wifi adapter gets powered down. On newer TV's there is a way to get the TV to turn on. I believe I have programmed this in already. Honestly I do not remember. So knowing which state the TV is in might be a moot point depending on how old your TV is. If you do have a newer TV you can use the Ping plugin to detect the power state of the TV. because when the TV is powered down it will not respond to a ping packet. and that lack of an answer will generate an event in eventghost. it will do the same when it turns back on. when you get that event you can set a global to True or False. and this global can be checked to see if the TV is on or off.

Another option for ya is you can buy an esp8266 micro controller for a few dollars USD and this can be used to detect the power and send an event over wifi to EG. How this would work is you would take a USB cable that has a USB A male end on it. cut the other end off. jump a 10K OHM resistor across the red and black wires in the USB cable tie the black to ground on the ESP and the red to one of it's analog pins. and plug the USB into one of the USB ports on the TV. when the TV turns on the USB on the TV outputs +5volts the ESP will see this. The purpose to the 10K ohm resistor is to stop what is called float. this will occur when the TV is off. because there is a disconnect of power. so there is no reference to ground. so even waving you hand near the USB can cause the ESP to think the TV turned on. so when the TV is in the off state the resistor will "pull down" the red wire to ground so you will have a binary switch state.

I did this exact thing with my Samsung TV (UN55D8000). It actually worked out really well. because what i did was EG knew if i used the remote control. and if i didn't press the power button on the remote but the TV turned off then EG knew i pressed the button directly on the TV. and it would then power down my whole theatre. i set it up like that so if i was too lazy to go digging through the sofa to locate the remote I still had the ability to shut everything off with a single press of a button.
If you like the work I have been doing then feel free to Image

therealbiglou
Experienced User
Posts: 113
Joined: Sat May 19, 2012 4:33 am

Re: Samsung Smart TV Plus

Post by therealbiglou » Tue Oct 23, 2018 10:10 pm

@ kgschlosser

Thanks for the ideas. I actually was doing some monitoring of what goes on in EG when I turn on and off my display. It just so happens that the HDMI changes trigger events. So, whenever the TV turns off, it triggers:

System.DeviceAttached [u'\\\\?\\DISPLAY#SAM094D#5&133f93b4&0&UID257#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}']

And then when it turns off:

System.DeviceRemoved [u'\\\\?\\DISPLAY#SAM094D#5&133f93b4&0&UID257#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}']

This ID is static so I can rely on it as a way to set a global to true or false. This also happens quicker than a ping and doesn't require any additional hardware!

User avatar
kgschlosser
Site Admin
Posts: 4313
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Samsung Smart TV Plus

Post by kgschlosser » Wed Oct 24, 2018 5:14 pm

That is true. the only issue (and I know this is 100% with Samsung) is if the HDMI cable gets to a certain length (do not know what the exact number is) when the TV turns on it will connect and generate that event. then when the TV turns on the actual panel. it will disconnect and then connect again. Sometimes the EDID data gets all goofed up during this process and it will throw those events but not with the hardware ID's being correct.

This only happens on long HDMI runs tho.
If you like the work I have been doing then feel free to Image

therealbiglou
Experienced User
Posts: 113
Joined: Sat May 19, 2012 4:33 am

Re: Samsung Smart TV Plus

Post by therealbiglou » Wed Oct 24, 2018 6:26 pm

Fortunately, I am not experiencing this issue. I've fully integrated this setup into my tree and it has GREATLY reduced the complexity of starting up and powering down my TV setup on the HTPC.

User avatar
kgschlosser
Site Admin
Posts: 4313
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Samsung Smart TV Plus

Post by kgschlosser » Wed Oct 24, 2018 9:23 pm

If you are not having the problem that's awesome. I know it has to do with the length of the HDMI cable and a voltage drop on the EDID wire. It would cause all kinds of hell with my desktop layout and icons. Drove me bonkers. the HDMI cable i was using was 50 or maybe 75 feet long can't remember. I know it is the fault of the TV because I am now using a projector and I am using the same HDMI and no problems. and it would only do it when I turned the TV on. If I used a shorter cable and brought a computer close tho the TV the problem would disappear.
If you like the work I have been doing then feel free to Image

therealbiglou
Experienced User
Posts: 113
Joined: Sat May 19, 2012 4:33 am

Re: Samsung Smart TV Plus

Post by therealbiglou » Thu Oct 25, 2018 6:07 pm

Yeah, I'm just using a 15' HDMI so looks like no problems there. What's really awesome is that since the triggers for automation are now based on the TV's power instead of button presses on a special remote, it doesn't matter how I turn on the TV (TV's remote, on-board power button, etc), it will still run the EG scripts.

User avatar
kgschlosser
Site Admin
Posts: 4313
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Samsung Smart TV Plus

Post by kgschlosser » Fri Oct 26, 2018 9:11 am

well if ya get a little crafty as I did. You are going to love this one.

I used a universal remote and deep sixed using the stock remote. I picked up a Pinnacle MCE remote with ir receiver/blaster. i didn't use the remote it came with. I then set EG up to blast the power on codes to the TV. so that fixed the issue with turning the TV on. Because you get the events for the TV turning on you get set up a timer that will reblast the codes if the TV does not turn on. This is the kicker. because I use network to control the TV i set up mappings for the universal remote to the samsung plugin actions.

I have my whole theater system attached to EG. not just the TV. so this is what's handy.
Now EG knows if you press the power button on the remote or not. if the TV turns on or off and it didn't get an event from the remote to turn the power on or off. EG is going to assume my dumbass lost the remote and that i am to lazy to go and dig it out of the sofa. so it will automatically power on or off my whole theater system. by simply pressing the power button on the TV it's self.

Now that's automation!

It does get a wee bit better then that. things like if the AVR is set to say a video input it will automatically power on the TV. and if I switch the AVR to CD or some kind of audio input. it will automatically power off the TV.
If you like the work I have been doing then feel free to Image

holdestmade
Experienced User
Posts: 174
Joined: Thu Dec 04, 2014 2:44 pm

Re: Samsung Smart TV Plus

Post by holdestmade » Tue Nov 06, 2018 3:13 pm

Just a heads up, I just got an auto update on my 2017 and 2018 4K TVs (v1250) and this plugin no longer works.

After a brief trawl around the internet, I did discover that Samsung have apparently closed a "wireless security hole", which apparently means they have disabled the websocket API.

I have my TVs working in my Smartthings app and they have an API.

I have tried using the API and I can turn the TV on and off, change channel, change volume but cannot select inputs, I'll keep digging.

User avatar
kgschlosser
Site Admin
Posts: 4313
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Samsung Smart TV Plus

Post by kgschlosser » Tue Nov 06, 2018 6:50 pm

that API is for Samsung only. and a lot of the time that doesn't even work properly.

Samsung has their head shoved so far up their asses so far they can't see anything going on around them. while most of the TV manufacturers embrace the whole IOT thing. and they expose their API Samsung goes and does the complete opposite and makes it so that the crappy smart things is the only device able to talk to them. People will get tired of buying their stuff and them doing crap like that. I did. my washer and dryer was the last straw. 3200 dollars to be able to "control" the things remotely. it has never worked for more then a single day before the connection simply disappears. and when that happens it literally takes 4-5 minutes for the machine to turn on because they are to busy trying to connect to something they are not able to. 4-5 minutes it keeps on trying for before it will let you use the machine. and the washing machine as nice as it is as far as the water consumption and the size is so friggin sensitive to being level.. and I mean it can't be a 1\16th of an inch out. if it is the vibrations are horrid. and the legs they put on the things are for shit and it never stays level. I went nuts with the thing. I built a false floor with double 2x10 framing 1.5" thick decking tied the whole thing to the concrete floor with ramset nails. I made sure that the floor was level. perfect. and the machine still comes out of level on it's own.

Their phones are priced outrageous You can get a phone with almost identical specs (little lower on the screen resolution) for 1/2 the price. literally half the price.
If you like the work I have been doing then feel free to Image

Post Reply