I have a Samsung TV i’d like to switch off.
It’s not possible with the SAMSUNG TV Binding.

I have a PI connected to the TV with KODI running.

[EDIT: the KODI addon is not necessary see below]

There’s a KODI addon to control CEC via RPC JSON

My rule to switch the TV ON or OFF is not working, here it is

var String kodiUrl = 'http://kodi:kodi@'

rule "kodi CEC activate"
	Item MENU_VIDEO_TV_ON received command

  var String content1 = '{"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.json-cec","params":{"command":"activate"}},"id":"1"}'

rule "kodi CEC standby"
	Item MENU_VIDEO_TV_OFF received command
	  var String content2 = '{"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.json-cec","params":{"command":"standby"}},"id":"1"}'

The error I got

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'kodi CEC standby': 1

Any idea ?

Do you get the same error on the “kodi CEC activate” or just this the one rule?

I’ve not seen quite so unhelpful of an error from the rules in a long time.

I’d recommend the following:

  • make kodiUrl be a val, not a var to ensure that it is never changing
  • add some logging to determine which of the two lines you are failing on
  • log what is getting returned by the sendHttpPostRequest
  • what is content2? is it valid?

There is another option that doesn’t require the use of any Kodi addons, which can potentially be broken by a Kodi update…

Given the Pi will be running a flavour of linux you can configure OpenHAB to execute a command remotely on the Pi to send the cec commands to the television using the exec binding with SSH key access.

I use exactly this method to switch my Samsung TV and Virgin Media set top box on and off via a voice command thru Alexa.

Are you running Kodi on Raspbian or via something such as OSMC or RaspBMC?

install sshpass
you have to connect once to kodi box with user openhab from linux to generate the passkey

Thing exec:command:systemOFFs   [command="sshpass -p password ssh osmc@ kodi-send --action='CECStandby'", interval=0, autorun=false]
Thing exec:command:systemONs    [command="sshpass -p password ssh osmc@ kodi-send --action='CECActivateSource'", interval=0, autorun=false]
1 Like

The later possibility is so easier …

My PI attached to the TV is running Libreelec KODI (IP I didn’t change anything on it.
root user’s password is ‘libreelec’

Here’s what I did on the PI running Openhabian

  • Install sshpass
sudo apt-get install sshpass
  • Connect once to librelec to validate the certificate (with user openhab, because this is with this user’s context the Exec Binding is executed)
sudo -u openhab ssh
The authenticity of host ' (' can't be established.
ECDSA key fingerprint is SHA256:iPpN3RPJdbnMm/b8iY6SwAsvmBExgQgYTbvkpwljayA.
Are you sure you want to continue connecting (yes/no)? yes
  • test (again, under user openhab)
sudo -u openhab sshpass -p libreelec ssh root@ kodi-send --action='CECStandby'
Sending action: CECStandby

And it worked perfectly ! Thanks a lot to everyone !