Hdmi cec binding

I’am currently controlling and updating the powerstate of my Samsung tv using an HDMI CEC usb adapter using simple scripts and a cron job. But this also means that it takes up to a minute until openhab realizes that the tv has been turned on. I would like to use this event power on my sat receiver and at the moment this takes some time with this solution

I’ve looked at the cec-client and I think it would be possible to build a better solution by listening to the output of the process and immediateley update the item in openhab if a power change is reported. This would also block the device, so the solution should also be able to receive commands and send them to the cec-client’s input.

Is there some existing binding or script that could do that or do I have to create my own binding to do this?

How do you connect your script to openHAB (i.e. how do you get the result of the script execution into openHAB) right now?

I’m sending the powerstate to the HTTP rest interface from the shell skript.

I have a new Samsung TV and Sounbar in the home and still just getting it setup. But what model TV do you have?

I was going to try the SamsungTV binding soon. Does that work and have the ability to show the power state?

I have an Samsung UE32D5720 tv. The problem is that the tv shuts down the ethernet port when powering off. The only way to power it on again to to use an HDMI CEC adapter or via an infrared transmitter.

I did the following to power on my Philips TV via a RPI3. It might give you some hints to further explore your options:

From your post I don’t understand which device ‘sends’ the HDMI CEC commands, is that your openHAB raspberry pi or some other device?

I guess you could use the exec binding to control your script. Have you looked at this?

1 Like

I use the following adapter to send the hdmi cec commands: https://www.pulse-eight.com/p/104/usb-hdmi-cec-adapter

I cannot use the exec binding because it is not build to listen to a continuous stream of data. The exec binding simply starts a process and waits until the process is finished and then returns the output of the process. I would need something that listens forever to the output and supports callbacks if certain keywords appear in the output of the process. Also it should be possible to write to the same process to send the power on and off commands. (cec-client blocks the serial port, so only one process can be used for every port)

I think the only way to handle this properly is to build a new binding. If I get my build environment working again I will see what I can do.

Edit: I wrote a small java application to test this and I was able to detect the tv powering on. To monitor if the tv has been turned off I have to send a “pow” command every few seconds because there is no event from the cec client for this. I was also able to turn the tv on and off. (If Ayenet+ standby function is enabled on the tv) I will try to put my code into an OH2 plugin and test this for some time.

I know the current thought process is attempting to power the TV back on via an HDMI cord and CEC. But it was mentioned earlier about using an IR transmitter.

I think this would do the trick? Is it worth $80 bucks to try?

http://www.homecontrols.com/Zipato-Z-Wave-to-IR-Extender-ZPRMZXT120US

The problem is that an IR extender cannot determine if the tv is running or not. I do also cut the power to my tv completely at night, so the only other way would be to check via network ping. This would require a combination of several bindings and I’am not a fan of that because that could cause problems between the bindings.

I’ve now created a small OH2 addon binding that starts the cec-client executable as a separate process and parses the output in realtime. So far it works very good. I also implemented a 60 seconds poll to detect when the power to the tv was cut. (In this case no event is reported)

I just have to implement a reconnect method in case the connection to the device is interrupted. I will share the code here when I have a first stable version.

I’ve just finished the first beta version of my hdmicec plugin. If anyone is willing to test this, I’ve uploaded the addon jar to my GitHub account: https://github.com/TheNetStriker/openhab2-addons/releases/tag/2.1.0.beta1

I’ve also uploaded the source code: https://github.com/TheNetStriker/openhab2-addons/tree/hdmicec/addons/binding/org.openhab.binding.hdmicec

You just have to configure the path to the cec-client executable and set the name of the tty port to use. I provides one switch channel representing the current power status of the tv. The addon also tries to reconnect every 60 seconds if the connection was lost.

I use a 2 raspberrypi’s with RasPlex, which have HDMI-CEC control, how can i use your binding to control/make use of these so i can control my TV/AVR with it CEC?

br,
Raymond

The Binding work only for Openhab and I have no experience with RasPlex.

Hi @TheNetStriker

is there any documentation of this binding?

How do i use this? (i have the binding already in my OH folder)

I have a RaspPi2 with openhabian and its connected to the TV

I want to power On/Off the TV using this binding…

Any hints what item or sitemap entrys i need to do?

Thanks for contributing to OH :slight_smile:

Hi, you just must add the device manually using paper ui and provide the path to the hdmi-cec executable and the path to the serial port device. The hdmi-cec executable must be compiled from this source: https://github.com/Pulse-Eight/libcec

Hi mate, many thanks for this module!

Just so you are aware, raspberry pi comes with its own hdmi cec connection on the board, in this case we don’t use a usb device… what should go in the path for the serial port in this case?

You can list all com ports using “cec-client -l”. Have you tried if it works when you enter “RPI” as com port?

Will try tonight and let you know, I’ve been having a right nightmare with my setup so far! :slight_smile:

just tried with:
CEC Path: /usr/lib/python2.7/dist-packages/cec
Com Port: RPI

It is just stuck on initialising and in the error log I get the following:

2017-09-24 19:40:12.984 [ERROR] [nding.hdmicec.handler.HdmiCecHandler] - java.io.IOException: Cannot run program “/usr/lib/python2.7/dist-packages/cec”: error=13, Permission denied

is this because openhab user doesn’t have access?

I will note that I get the following when I do cec-client -l:

pi@raspberrypi:~ $ cec-client -l
libCEC version: 4.0.2, git revision: libcec-4.0.2+30-8adc786~dirty, compiled on Mon Aug 21 09:41:41 UTC 2017 by root@hostname: Name or service not known on Linux 4.4.0-92-generic (armv7l), features: P8_USB, DRM, P8_detect, randr, RPi
Found devices: 1

Shouldn’t the openhab user have access to this?

Yes this seams to be a permission problem. You have to check the file permissions of the cec-client file. The easiest way to give the OpenHab process access to execute the file is to add the group of the cec-client file to the openhab user. Of course the group also needs to have the right to execute the file. (In my case this was the group “staff”) Or you could just give every user the right to execute the file. After a reboot of Openhab the addon should be able to execute the file.

The output of cec-client -l on my machine is the following:

libCEC version: 4.0.2, git revision: libcec-4.0.2+30-8adc786~dirty, compiled on Thu Aug 24 19:17:56 UTC 2017 by root@OpenHabian01 on Linux 4.9.35-v7+ (armv7l), features: P8_USB, DRM, P8_detect, randr, RPi

device: 1
com port: /dev/ttyACM1
vendor id: 2548
product id: 1002
firmware version: 65535

device: 2
com port: RPI
vendor id: 2708
product id: 1001
firmware version: 1
type: Raspberry Pi