OpenHAB, Raspberry pi, Samsung TV HDMI CEC integration

Hi All!

Can anyone please tell me if there is somewhere on the world wide web a tutorial about integration the OpenHAB with a TV through HDMI CEC?
I have googled and found a few but they are not so specific.
I have a Samsung TV (UE40H6400) and i want to make it start / stop using OpenHAB and because i understood that the model i have is not compatible with the OpenHAB Samsung .jar file (tested already) i would like to find another way to power on/off my TV.
I know that there are other ways to get this job done, like an IR transmitter / receiver using lirc here or the best way i think using the Logitech Harmony remote control but for the moment i understood the this can be possible using the HDMI cec.

Can anyoane please point me a step by step tutorial which will pass you through all the necessary steps?
Thanks in advance for any reply.

Me :slight_smile:

1 Like


You may want also to have a look at this discussion on . There’ a post where you can read :

I had read about the issue that XBMC has its own cec-client, but was never able to find/use it.

echo “on 0” | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s
echo “standby 0” | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s

works out of the box to turn on/off my samsung tv via ssh.

If you have Kodi/XBMC also installed on Raspberry PI you may want to try to call these instructions from whithin OpenHab (I have not tested it though)


Thanks Eurico, I don’t have XBMC and I would prefer not use it, I just want a direct connection between my TV on a specific Chanel and the rpi through the cec option.


You need to install libcec on your pi like described here.

Use the exec binding to execute the functions you need. In case you need more than one function create a script.

Example to turn on tv on hdmi1:
echo “on 0” | cec-client -s
echo “tx 1F 82 10 00” | cec-client -s

hope that helps.
br, Marc


Thanks Marc, this is indeed a step by step tutorial but just for the rpi. Tomorrow I’ll follow all steps and fortunately I’ll not meet any error.
What about OH?
How do I set in item to trigger this echo command?
And how to turn the TV ON?
How to use exec binding ? What command I need?


Use e.g. a switch and bind the exec binding to it.

echo "on 0" | cec-client -s
as the command.

I can’t follow the guide on rpi forum because something is wrong and I couldn’t find the answer in comments or other topics…
I’m stuck at this command: “sudo ./bootstrap” because “command not found”

Can anyone pls tell what should I do or where to find a good and updated tutorial?



check the github page for newer(?) instructions.

Scroll down to Raspberry Pi and use the libCEC on a new Raspbian installation instructions.
I haven’t tested myself, so good luck.


Thanks man for your interest but unfortunately looks like all the planets aligned especially for me to fail :frowning:
Every eg i try i fail to complete and now my RPI is full of wrong or no needed folders in different locations which i cant even delete them …
Using this command:

cat /etc/os-release

i get the OS version installed on my PRI:

PRETTY_NAME="Raspbian GNU/Linux 7 (wheezy)"
NAME="Raspbian GNU/Linux"
VERSION="7 (wheezy)"

Last eg tried was the one on Github here and i get errors on the last 3 steps:

make -j4
sudo make install
sudo ldconfig

What could possible go wrong during the installation? i can’t understand … i asked on the RPI forum but no answer! i know this should be easy even for a person like me who doesn’t have knowledge about Linux or so …

Can anyone who did this job recently, help with an advice?


I’ll get a PI of a friend and will try it hopefully on the weekend. In the meantime could you please post the errormessages you got.


Hi @ewgor,

I tried it some minutes ago with a new raspbian installation and it totaly worked for me.
I did all these steps below one by another. At the make -4j part there was a warning you can ignore.
Please note I’m using the latest raspbian (version 8). However I think it should work as well for you.
Can you please try again the steps and post the console output.

sudo apt-get update sudo apt-get install cmake liblockdev1-dev libudev-dev libxrandr-dev python-dev swig cd git clone mkdir platform/build cd platform/build cmake .. make sudo make install cd git clone mkdir libcec/build cd libcec/build cmake -DRPI_INCLUDE_DIR=/opt/vc/include -DRPI_LIB_DIR=/opt/vc/lib .. make -j4 sudo make install sudo ldconfig

Thank you Marc, I will try this today and I’ll come back to you with a feedback.

Thanks again :slight_smile:

Perhaps a more elegant solution would be to attach a separate RPi to your TV and control that RPi from your openHAB server through MQTT over Ethernet or wifi (RPi 3). And let MQTT control CEC.

1 Like

Hi @rtvb,
Why should that be easier?
You need to install libcec as well and in addition you would need a Mqtt client which then has to translate the mqtt message to libcec.
If the existing pi is near to the TV there is no reason to get a separate pi.

BR, Marc

Easier in the sense of separating logic and more future proof. If for some reason you install openHAB on a different machine or platform the solution will continue to work. My headless openHAB server is in a closet and nowhere near a tv.

I agree that it is a little more complex to setup initially.

Hi @rtvb
I get your points and they are of course true. What kind of tool do you use for the mqtt to libcec handling?

However, I just wanted to point out that this is a more advanced and optional solution. We should not confuse @ewgor with that advanced stuff yet, as he seems to have troubles with libcec itself right now.
If that is then fixed this may be a solution for him as well. I don’t know his setup.

I do not use libcec myself, so I cannot tell you exactly how to build this, but this would be my approach:

  • use OpenHAB to send/post MQTT triggers to an MQTT server (assuming this is running on the OpenHAB Pi)
  • let the MQTT client on the Pi listen to the triggers and execute shell commands to perform the actions
  • the listener job would be an agent/service running permanently on your machine that executes a command for a specific MQTT message, for example if you post a message /tv/cec/off then execute libcec command to switch the tv off.

Thanks guys for answers but unfortunately for me i tried again for a few times and still not working so i decided to choose another way by using a Logitech Harmony remote but for this ill try to find some instruction on the forum or ask for help but in another topic!
Thanks again all for support.

Thats up to you but I would be interested in the output.
Could you post it please

On a raspberry pi this little script might be useful:

if   [ "$1" = "OFF" ]; then
        /opt/vc/bin/tvservice -o
elif [ "$1" = "ON" ]; then
        /opt/vc/bin/tvservice -p

It converts the OpenHAB switch state into a command for the tvservice utility.
Create a Switch and use it in a rule with executecommandline
ssh user@system ./"+switch.state

The needs to be placed in the home directory of user@system
also you need to enable ssh-login with a key (ssh-keygen & ssh-copy-id for the user which runs OpenHAB)