Raspberry Pi Turn Tv On/Off CEC

When building a dashboard using a Raspberry Pi, I wanted a way to schedule the tv to turn on/off automatically. Below are the steps using Consumer Electronics Control (CEC).

  1. sudo apt-get install cec-utils

Once everything is installed you should be able to control the tv using the command below:

Turn tv on: echo on 0 | cec-client -s -d 1
Turn tv off: echo standby 0 | cec-client -s -d 1
Tv status: echo pow 0 | cec-client -s -d 1

Troubleshooting Tips:

  • Make sure your tv supports cec and that it is enabled. Tv manufactures call CEC by different names so you may have to do some research depending on your brand.
  • Make sure you are using a new hdmi cable that is at least HDMI 1.2a

Different names for HDMI CEC

  • Samsung – Anynet+
  • Sony – BRAVIA Link or BRAVIA Sync
  • Sharp – Aquos Link
  • Hitachi – HDMI-CEC
  • AOC – E-link
  • Pioneer – Kuro Link
  • Toshiba – Regza Link or CE-Link
  • Onkyo – RIHD (Remote Interactive over HDMI)
  • LG – SimpLink
  • Panasonic – VIERA Link or HDAVI Control or EZ-Sync
  • Philips – EasyLink
  • Mitsubishi – NetCommand for HDMI
  • Runco International – RuncoLink

 

Credits: http://raspberrypi.stackexchange.com/questions/7054/cec-wake-up-command


Thanks for reading. Make sure you follow me on Twitter to stay up to date on the progress of my side projects T.LYWeather Extension, and Link Shortener Extension. If you are interested in the tech I use daily, check out my uses page.  

24 thoughts to “Raspberry Pi Turn Tv On/Off CEC”

  1. Thank you for this post !
    After searching and trying hours and hours it helps me.
    But…
    On my Pi B+ with Debian Wheezy 1.4 I only need to install by:
    sudo apt-get install cec-utils
    That’s all
    Sorry… You have error’s in the documentation for switching on and off.
    You must type in:
    echo standby 0 | cec-client -s -d 1
    or
    echo on 0 | cec-client -s -d 1
    without ‘

    1. Thanks glad it helped you! Most likely it’s because I was using an older os version. Hopefully this comment will help someone else. I’ll update the post.

    1. From the libCEC Vendor Compatibility Site:
      Concerning “Samsung” and “Power Off”
      “Some models require you to turn on “Auto-Standby” in the Anynet+ settings to enable this feature”

      1. “Some models require you to turn on “Auto-Standby” in the Anynet+ settings to enable this feature”

        That did the trick for me, thanks!

  2. Hi there,

    thank you for the tutorial provided. I am able to turn on and off my Panasonic E-30. However it takes some seconds to execute. Turning on debug out I can see many timeouts:

    opening a connection to the CEC adapter…
    DEBUG: [ 63] Broadcast (F): osd name set to ‘Broadcast’
    DEBUG: [ 63] Open – vc_cec initialised
    DEBUG: [ 63] logical address changed to Free use (e)
    NOTICE: [ 64] connection opened
    DEBUG: [ 64] processor thread started
    DEBUG: [ 64] < TV (0): POLL
    DEBUG: [ 64] initiator ‘Broadcast’ is not supported by the CEC adapter. using ‘Free use’ instead
    TRAFFIC: [ 64] << e0
    DEBUG: [ 1065] command 'feature abort' timeout
    DEBUG: [ 1565] initiator 'Broadcast' is not supported by the CEC adapter. using 'Free use' instead
    TRAFFIC: [ 1565] <> POLL sent
    DEBUG: [ 1599] TV (0): device status changed into ‘present’
    DEBUG: [ 1599] << requesting vendor ID of 'TV' (0)
    TRAFFIC: [ 1599] << e0:8c
    DEBUG: [ 2600] command 'give device vendor id' timeout
    TRAFFIC: [ 3100] << e0:8c
    WARNING: [ 3130] unhandled response received: opcode=0 initiator=e destination=0 response=0
    DEBUG: [ 4100] command 'give device vendor id' timeout
    NOTICE: [ 4600] registering new CEC client – v4.0.2
    DEBUG: [ 4601] detecting logical address for type 'recording device'
    DEBUG: [ 4601] trying logical address 'Recorder 1'
    DEBUG: [ 4601] < Recorder 1 (1): POLL
    TRAFFIC: [ 4601] << 11
    TRAFFIC: [ 9254] <> POLL not sent
    DEBUG: [ 13852] using logical address ‘Recorder 1’
    DEBUG: [ 13852] Recorder 1 (1): device status changed into ‘handled by libCEC’
    DEBUG: [ 13852] Recorder 1 (1): power status changed from ‘unknown’ to ‘on’
    DEBUG: [ 13852] Recorder 1 (1): vendor = Pulse Eight (001582)
    DEBUG: [ 13852] Recorder 1 (1): CEC version 1.4
    DEBUG: [ 13852] AllocateLogicalAddresses – device ‘0’, type ‘recording device’, LA ‘1’
    DEBUG: [ 13852] logical address changed to Recorder 1 (1)
    DEBUG: [ 13853] Recorder 1 (1): osd name set to ‘CECTester’
    DEBUG: [ 13853] Recorder 1 (1): menu language set to ‘eng’
    DEBUG: [ 13853] GetPhysicalAddress – physical address = 1000
    DEBUG: [ 13853] AutodetectPhysicalAddress – autodetected physical address ‘1000’
    DEBUG: [ 13853] Recorder 1 (1): physical address changed from ffff to 1000
    DEBUG: [ 13853] < broadcast (F): physical address 1000
    TRAFFIC: [ 13853] << 1f:84:10:00:01
    DEBUG: [ 14853] command 'report physical address' timeout
    TRAFFIC: [ 15354] << 1f:84:10:00:01
    NOTICE: [ 15386] CEC client registered: libCEC version = 4.0.2, client version = 4.0.2, firmware version = 1, logical address(es) = Recorder 1 (1) , physical address: 1.0.0.0, git revision: libcec-4.0.2+8-8563411, compiled on Do 23. Mär 16:17:50 UTC 2017 by pi@Montyhub on Linux 4.4.50-v7+ (armv7l), features: P8_USB, DRM, P8_detect, randr, RPi
    DEBUG: [ 15386] < TV (0): OSD name ‘CECTester’
    TRAFFIC: [ 15386] << 10:47:43:45:43:54:65:73:74:65:72
    DEBUG: [ 16387] command 'set osd name' timeout
    TRAFFIC: [ 16887] << 10:47:43:45:43:54:65:73:74:65:72
    WARNING: [ 16921] unhandled response received: opcode=84 initiator=1 destination=f response=0
    DEBUG: [ 17887] command 'set osd name' timeout
    DEBUG: [ 18388] << requesting power status of 'TV' (0)
    TRAFFIC: [ 18388] << 10:8f
    WARNING: [ 18452] unhandled response received: opcode=47 initiator=1 destination=0 response=0
    DEBUG: [ 19388] command 'give device power status' timeout
    TRAFFIC: [ 19888] << 10:8f
    WARNING: [ 19983] unhandled response received: opcode=47 initiator=1 destination=0 response=0
    DEBUG: [ 20889] command 'give device power status' timeout
    DEBUG: [ 21390] << requesting vendor ID of 'TV' (0)
    TRAFFIC: [ 21390] << 10:8c
    WARNING: [ 21518] unhandled response received: opcode=8f initiator=1 destination=0 response=0
    DEBUG: [ 22390] command 'give device vendor id' timeout
    TRAFFIC: [ 22891] << 10:8c
    WARNING: [ 23053] unhandled response received: opcode=8f initiator=1 destination=0 response=0
    DEBUG: [ 23892] command 'give device vendor id' timeout
    NOTICE: [ 24392] << powering on 'TV' (0)
    TRAFFIC: [ 24392] << 10:04
    WARNING: [ 24588] unhandled response received: opcode=8c initiator=1 destination=0 response=0
    DEBUG: [ 25393] command 'image view on' timeout
    TRAFFIC: [ 25893] << 10:04
    WARNING: [ 26122] unhandled response received: opcode=8c initiator=1 destination=0 response=0
    DEBUG: [ 26893] command 'image view on' timeout
    DEBUG: [ 27394] unregistering all CEC clients
    NOTICE: [ 27395] unregistering client: libCEC version = 4.0.2, client version = 4.0.2, firmware version = 1, logical address(es) = Recorder 1 (1) , physical address: 1.0.0.0, git revision: libcec-4.0.2+8-8563411, compiled on Do 23. Mär 16:17:50 UTC 2017 by pi@Montyhub on Linux 4.4.50-v7+ (armv7l), features: P8_USB, DRM, P8_detect, randr, RPi
    DEBUG: [ 27396] Recorder 1 (1): power status changed from 'on' to 'unknown'
    DEBUG: [ 27396] Recorder 1 (1): vendor = Unknown (000000)
    DEBUG: [ 27396] Recorder 1 (1): CEC version unknown
    DEBUG: [ 27396] Recorder 1 (1): osd name set to 'Recorder 1'
    DEBUG: [ 27396] Recorder 1 (1): device status changed into 'unknown'
    DEBUG: [ 27397] unregistering all CEC clients
    WARNING: [ 27652] unhandled response received: opcode=4 initiator=1 destination=0 response=0
    DEBUG: [ 28068] UnregisterLogicalAddress – releasing previous logical address
    DEBUG: [ 29064] logical address changed to Broadcast (f)
    Speicherzugriffsfehler

    Everything works but still the long delay is kind of disturbing. Any idea what could be the problem?

    Cheers,

    Matthias

  3. Thanks for the post!

    I’ve got my pi successfully turning the TV on (Kogan TV) however the standby command isn’t working. I’ve got auto-standby and auto power on set to on in the cec menu. Anything else I should try?

  4. Does this turn it on and off automatically on a schedule? What time of day Does it turn it on and off? I’d love to see like auto on at 6am and off at 11pm.

  5. I’m looking for a solution the other way round: I want my tv (Samsung with hdmi-cec) to switch on or wake up my Rasberry Pi. Is that possible?

Leave a Reply

Your email address will not be published. Required fields are marked *