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?
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 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?
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.
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?
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
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?
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
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