HDMI CEC to turn on TV and AVR no longer working

I just moved my Kodi to a raspberry 4 which have HDMI-CEC support which is awsome!
Finally I can make this a bit more wife friendly! :slight_smile:

However this was working for me for a day but now I can’t possibly make it work again.

This is the script I’m using

    - service: kodi.call_method
        entity_id: media_player.kodi
        method: Addons.ExecuteAddon
        addonid: script.json-cec
          command: activate

And the log displays this

 ERROR (MainThread) [homeassistant.components.kodi.media_player] Run API method media_player.kodi.Addons.ExecuteAddon({'addonid': 'script.json-cec', 'params': OrderedDict([('command', 'activate')])}) error: {'code': -32602, 'message': 'Invalid params.'}

I can’t recall changing anything but now it’s no longer working.
Any thoughts?

Responding to myself
To be able to use above the addon jscon-cec needs to be installed:

Why it was working day 1 must have been that I accidantally must have been invoking this ssh command instead of the kodi addon:
/usr/bin/ssh [email protected] "systemctl restart kodi"
I can’t explain it in any other way.

Hope this helps others starting with home-assistant and libreelec

1 Like

I have noticed that the android remote control app for kodi (libreelec) called yatse is able to switch on the TV by using CEC activate found on the apps power menu.

This works very smooth and no need to restart kodi like the ssh commands

I can’t work out what command yatse is sending to kodi but I suspect it is the JSON-CEC Activate so I tried this using the same yaml as the original post and getting the same error in the logs.

I am fairly certain that JSON-CEC is installed as you can send other commands to kodi from the browser to look at the media library, etc

The error in the log is suggesting that the format of the command is wrong but the yaml matches the documentation as far as I can tell.

Does anyone have an idea how to edit the code to get it to accept the format?

the error I am getting is

Run API method media_player.kodi.Addons.ExecuteAddon({'addonid': 'script.json-cec', 'params': {'command': 'activate'}}) error: {'code': -32602, 'message': 'Invalid params.'}

1 Like

I am trying to work out how it does it too, I suspect not with the following

As I don’t have json-cec installed. Debug logs don’t seem to show the jsonrpc payload

I installed the network tool add-on and captured a tcpdump… it is not a HTTP request to the jsonrpc at all. Yatse sends some form of UDP packet which I’m not sure how to interpret

See CECActivateSource() from my phone clicking “CEC Activate” below

Ah ha! I found the UDP protocol and extracted a very small script to wake the TV

See kodi_send_udp_action.py · master · Kevin / Kodi send UDP action tool · GitLab

For completeness in case someone else wants to try this. Placing the script into /config/ and the following shell command

  kodi_cecactivate_for_tv: >-
    python /config/kodi_send_udp_action.py {{ kodi_ip }} '{{ command }}'

Can be used like so:

service: shell_command.kodi_cecactivate_for_tv
  command: "CECActivateSource()"

Which is handy for old LG netcast tvs like mine

# lg 55la6620 tv
  - platform: lg_netcast
    name: LG Living Room TV
    access_token: 412205
      service: shell_command.kodi_cecactivate_for_tv
        command: "CECActivateSource()"

Hopefully hijacking this old thread will be useful for someone else one day