HomeAssistant AIO HDMI CEC error (clean install)

Hi,
I have a clean install of HASS AIO for my pi 3, however, trying to do:

#HDMI CEC
hdmi_cec:
  devices:
    TV: 0.0.0.0
    #PC: 1.0.0.0 (Not using CEC compatible HDMI cable.)
    Raspberry Pi: 2.0.0.0
    Chromecast: 3.0.0.0

Gives the following error:

2017-09-19 21:10:36 ERROR (MainThread) [homeassistant.setup] Error during setup of component hdmi_cec
Traceback (most recent call last):
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/setup.py”, line 194, in _async_setup_component
component.setup, hass, processed_config)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/hdmi_cec.py”, line 184, in setup
adapter = CecAdapter(name=display_name[:12], activate_source=False)
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/pycec/cec.py”, line 20, in init
import cec
ImportError: No module named ‘cec’

Really not sure where to go from here - I have checked that the CEC references are correct (yes they exist), however it just won’t work… I have tried simplifying with:

hdmi_cec:
  platform: media_player

But same result… I don’t think it’s the config file, more that the config file calls on something not correct…
I have tested HDMI_CEC from commandline with cec-client and it works, so definitely not the libcec package itself… I am thinking that it is the symlink? the only reference from this forum I can get is from February where the version was 0.38 - However I would have thought this would be fixed by now?

Additionally the instructions need to be updated for HDMI-CEC - Home Assistant as this references python3.4, but we are now python3.5, also the symlink is now out of date?

anysuggestions?

Gonna try another clean install and check the install log for CEC… I just read another thread where the symlink failed in install - however I didn’t check the whole install log as it completed with success message.

yep, just checked my install log and I can confirm the last log is it failing on cec:

[localhost] sudo: make install
[localhost] out: [ 83%] Built target cec
[localhost] out: [ 88%] Built target cec-client
[localhost] out: [ 92%] Built target cecc-client
[localhost] out: [100%] Built target _cec
[localhost] out: e[36mInstall the project...e[0m
[localhost] out: -- Install configuration: ""
[localhost] out: -- Installing: /usr/local/bin/./cec-client-4.0.2
[localhost] out: -- Installing: /usr/local/bin/./cec-client
[localhost] out: -- Installing: /usr/local/bin/./cecc-client-4.0.2
[localhost] out: -- Installing: /usr/local/bin/./cecc-client
[localhost] out: -- Installing: /usr/local/bin/./pyCecClient
[localhost] out: -- Installing: /usr/local/lib/python3.5/dist-packages/_cec.so
[localhost] out: -- Set runtime path of "/usr/local/lib/python3.5/dist-packages/_cec.so" to ""
[localhost] out: -- Installing: /usr/local/lib/python3.5/dist-packages/cec/__init__.py
[localhost] out: -- Installing: /usr/local/lib/pkgconfig/libcec.pc
[localhost] out: -- Installing: /usr/local/include/libcec/cec.h
[localhost] out: -- Installing: /usr/local/include/libcec/cecc.h
[localhost] out: -- Installing: /usr/local/include/libcec/cecloader.h
[localhost] out: -- Installing: /usr/local/include/libcec/cectypes.h
[localhost] out: -- Installing: /usr/local/include/libcec/version.h
[localhost] out: -- Installing: /usr/local/lib/libcec.so.4.0.2
[localhost] out: -- Installing: /usr/local/lib/libcec.so.4
[localhost] out: -- Installing: /usr/local/lib/libcec.so
[localhost] out: -- Set runtime path of "/usr/local/lib/libcec.so.4.0.2" to ""
[localhost] out: 

[localhost] sudo: ldconfig
[localhost] sudo: ln -s /usr/local/lib/python3.4/dist-packages/cec /srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages
[localhost] out: ln: failed to create symbolic link '/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages': No such file or directory
[localhost] out: 

Warning: sudo() received nonzero return code 1 while executing 'ln -s /usr/local/lib/python3.4/dist-packages/cec /srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages'!

Below is a similar thread that goes back as far as March!:
https://community.home-assistant.io/t/all-in-one-on-a-rapsberry-pi-3-fails/

Further research:

A few tickets are on the forums:
HomeAssistant AIO HDMI CEC error (clean install) (mine)
All in one on a Rapsberry PI 3 fails (This goes back to March)
https://github.com/home-assistant/fabric-home-assistant/issues/47 (This was closed because it was successful on jessie lite but a poster later said they also get this issue.
https://github.com/home-assistant/fabric-home-assistant/issues/55 (This finds the cause and lists the next steps to take, however libcec itself is still broken for Raspberry pi at time of writting)

Libcec research:
https://github.com/Pulse-Eight/libcec/issues/362#issuecomment-317258888 the issue tracker of the libcec fault
https://github.com/Pulse-Eight/libcec/commit/5b4faecdeb1d6f8b27822fc50f4b49f6f5c66b95#diff-b81d8c50f4b84adb2a4bb9138dbbf2d3 (The file that is commiting the break in libcec)

So for those with this issue - it is not HomeAssistant at fault, but libcec. I don’t know if following that issue and updating will resolve the issue, I’ll probably just start from scratch to be sure :stuck_out_tongue:

there is a temporary work around here: error installing libcec using hassbian-config · Issue #38 · home-assistant/hassbian-scripts · GitHub

If anyone is still need it…
I Mannaged to install libCEC by removing lines 191-199 in the file:
~/libcec/src/libcec/cmake/CheckPlatformSupport.cmake

This is my new installation process:
sudo apt-get update
sudo apt-get install cmake libudev-dev libxrandr-dev python-dev swig
cd
git clone GitHub - Pulse-Eight/platform: Platform support library used by libCEC and binary add-ons for Kodi
mkdir platform/build
cd platform/build
cmake …
make
sudo make install
cd
git clone GitHub - Pulse-Eight/libcec: USB CEC Adapter communication Library http://libcec.pulse-eight.com/

sed -i ‘191,199d’ ~/libcec/src/libcec/cmake/CheckPlatformSupport.cmake
•If you want to manually edit the file see below.
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

Test it
echo scan | cec-client -s -d 1

To manually edit CheckPlatformSupport.cmake
sudo nano ~/libcec/src/libcec/cmake/CheckPlatformSupport.cmake
Remove those lines:
SET(PYTHON_LIB_INSTALL_PATH “/cec” CACHE STRING “python lib path”)
if (${CMAKE_MAJOR_VERSION} GREATER 2 AND ${CMAKE_MAJOR_VERSION} GREATER_EQUAL 7)
SET(PYTHON_LIB_INSTALL_PATH “” CACHE STRING “python lib path” FORCE)
else()
if (${CMAKE_MAJOR_VERSION} GREATER_EQUAL 3)
SET(PYTHON_LIB_INSTALL_PATH “” CACHE STRING “python lib path” FORCE)
endif()
endif()