kdschlosser / samsungctl

Remote control Samsung televisions via a TCP/IP connection
MIT License
148 stars 34 forks source link

CEC support #107

Open kdschlosser opened 5 years ago

kdschlosser commented 5 years ago

OK folks I have added another feature into the library. This was not to hard to add because I had already had done work in the past with libcec. So I had a whole nice python module already written to handle all of the various bits of CEC. I really only needed to add the parts to the config file. and add in the pieced that we are going to use in the library.

The reason for this addition is it makes it possible for those users that have legacy TV's to be able to power on the TV.. YAY!!! and for the folks that have 2016+ TV's that do not support discrete remote codes for the sources and also do not support listing the sources thee CEC addition will provide these. Another cool thing is if you have CEC enabled and you have an AVR that is set as the audio controller the library is now going to set the volume on that instead of the TV. as well as the mute. Overall for the power of the TV. if CEC is available then there will be no WOL packets used to turn the TV on. and the remote codes are not gonig to be used to turn it off. the CEC portion is used instead.

So lets recap. If CEC is enabled this is what it is going to do powering on and off of the TV enumerating the sources only if this cannot be done via UPNP volume changes only if you have an AVR set as the audio controller mute is the same as volume

here is an example config file.

name = Samsung TV Connector [OFFICE-PC]
description = OFFICE-PC
host = 192.168.1.122
port = 55000
id = 8121e10-963e-45b3-8279-81da75ceae4
method = legacy
timeout = 0
token = None
upnp_locations = http://192.168.1.122:52235/dmr/SamsungMRDesc.xml, http://192.168.1.122:52235/MainTVServer2/MainTVServer2Desc.xml, http://192.168.1.122:52235/rcr/RemoteControlReceiver.xml,
paired = True
mac = D0:66:7B:A3:DD:0E
model = UN55D8000
app_id = None
uuid = 2c782d5f-9fd1-9152-41e1-0af79c23d484
display_name = None
// ****** CEC MUST REMAIN AT THE END OF THE FILE ******
cec:
  name = SamsungTVCEC
  port = COM15
  types = 4,
  power_off = 0
  power_standby = 0
  wake_avr = 0
  keypress_combo = 113
  keypress_combo_timeout = 50
  keypress_repeat = 200
  keypress_release_delay = 0
  keypress_double_tap = 100
  hdmi_port = 1
  avr_audio = False

to enable CEC you only need to specify the hdmi_port parameter. this is what will turn it on. From there it will automatically discover the device and the port it is used on. it is then going to save that information to the config file (faster loading next time around,, it bypasses the discovery). The hdmi_port parameter is the HDMI number that the adapter or the raspberry pi is plugged into on the TV. HDMI1 = 1 HDMI2 = 2... I think you get the point.

config file to enable CEC

name = Samsung TV Connector [OFFICE-PC]
description = OFFICE-PC
host = 192.168.1.122
port = 55000
id = 8121e10-963e-45b3-8279-81da75ceae4
method = legacy
timeout = 0
token = None
upnp_locations = http://192.168.1.122:52235/dmr/SamsungMRDesc.xml, http://192.168.1.122:52235/MainTVServer2/MainTVServer2Desc.xml, http://192.168.1.122:52235/rcr/RemoteControlReceiver.xml,
paired = True
mac = D0:66:7B:A3:DD:0E
model = UN55D8000
app_id = None
uuid = 2c782d5f-9fd1-9152-41e1-0af79c23d484
display_name = None
// ****** CEC MUST REMAIN AT THE END OF THE FILE ******
cec:
    hdmi_port = 1

if you want the discovery process to go a bit faster and you already know the port the adapter is on then add that to the config file. RPI is the port that is used on a raspberry pi.

You are going to need to have libCEC installed for this to work. There is a windows binary file that will install it if you have a CEC USB adapter.

and for the folks with a Raspberry Pi https://github.com/Pulse-Eight/libcec/wiki/Raspberry-Pi-set-up Not all Raspberry Pi's have a CEC adapter.

For those of you that are using Home Assistant. It too does CEC and when this library gets added into Home Assistant you will need to make a decision. You can only use either the one that is built iin or the one that is apart of the library. you will not be able to use both.

for those of you running on crapintoshes or other flavors of Linux. you will need to do the legwork to find out how to get libCEC installed.

the updated code is in the develop branch that has these additions.