How to send and receive raw HDMI CEC commands?

Hi everyone:) How do I send and receive raw HDMI CEC commands with HA? (e.g. 14:44:44 = Apple TV play/pause in my setup)

Been using the great cec-mqtt-bridge on Raspbian. Is there something similar for Home Assistant (Hass.io). I don’t see this functionality in the stardard cec integration (https://www.home-assistant.io/integrations/hdmi_cec/). I’m not using docker (yet).

yes you are using docker. hassio is docker.

If you want to stop and start playback on appleTV use the appleTV integration.

Hi,

if you go to Developer Tools (sidebar) -> Services, type “hdmi_cec.send_command” into the Service field. It should show you the parameters the service accepts, and I think you need to use “raw:”

'Raw CEC command in format "00:00:00:00" where first two digits
        are source and destination, second byte is command and optional other bytes
        are command parameters. If raw command specified, other params are ignored.'

Hi Lothar. Thanks for your help. Do I need a specific add-on for it to work? I’m not getting any info on the accepted parameters. It says “service not found” (image below)

This means your hdmi_cec component is not configured correctly and not active at all. Have a look at the logs to find out why it can’t start.

Thank you. Will try debugging and try again. Is there also a service called hdmi_cec.receive_command or hdmi_cec.read_command?

can I send and receive these commands from Home Assistant in Node-Red?

No such service exists. But there are two events that might give you what you need:

hdmi_cec.cec_command_received
hdmi_cec.cec_keypress_received

Go to the Events Tab in Developer Tools, then Start Listening to the event. If you do whatever you want to receive here, and something shows up, you can use the event for automations.

Neither the send_command service nor those events are mentioned in the documentation, and might not be very well tested. I have personally not used them either.

In general all services and events should be available in Node-Red if Home Assistant is properly integrated.

1 Like

Thank you very much. I will see if I can make this work.

HDMI CEC seems like very overlooked functionality. I’ve been using it to control all my HDMI enabled devices without having to find and setup complex integrations for each device.

Sending raw CEC commands works!

And it also works from Node-RED:

Can’t read any hdmi_cec.cec_command_received events, however:
12
56

Any idea how to read (preferably) all CEC commands?

In this screenshot you are not listening to the event at all. The name of the event hdmi_cec.cec_command_received needs to be what is in the input field when you press start listening. If the event works, and another device sends a CEC command this page will then show a JSON format of all data in the event.

I’m turning the volume up and down on my receiver with my tv remote via hdmi cec, and turning the tv on and off, but no events :frowning: Does this mean that this event does not work / is not supported?

46

50

Did you try hdmi_cec.cec_keypress_received too? There has to be a reason this exists as a separate event. Also have a look on the TV what CEC device is selected there to receive the input.

Yes, I also tried this with no luck :frowning:
Skærmbillede 2020-02-06 kl. 21.03.11
I think the difference between cec_commands and cec_keypress is that cec commands are predefined whereas a cec keypress can be anything (which enables two devices of the same brand to send non-standard commands).

There seems to still be problems. I also get nothing listening to the CEC events. My created switches all auto-generate as expected (proper names) but the switches themselves don’t work. The hdmi_cec.power_on and hdmi_cec.standby services both work. However, the hdmi_cec.send_command and hdmi_cec.volume do not.

Have you found a way to receive the Signals ?

1 Like

Yep. I just went back to using the cec-mqtt-bridge (https://hub.docker.com/r/jonaseck/rpi-cec-mqtt-bridge/)

Hi Guys,

I have added hdmi_cec integration to configuration.yaml file and declared the devices I have found on the bus via cec scan made directly in raspberry.

Now when I have tried the services tools to power on all hdmi devices I get this error:

2021-11-09 01:28:53 ERROR (SyncWorker_0) [homeassistant] Error doing job: Exception in callback CecAdapter.power_on_devices()
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.9/site-packages/pycec/cec.py", line 51, in power_on_devices
    self._adapter.PowerOnDevices)
AttributeError: 'NoneType' object has no attribute 'PowerOnDevices'

What does this mean?