kanzi icon indicating copy to clipboard operation
kanzi copied to clipboard

Add support for switching TV on and off via CEC

Open dieterrosch opened this issue 6 years ago • 8 comments

Added two extra Alexa action to allow switching on and off the currently active CEC device by saying "Alexa, ask Kodi to switch (on/off) the (tv/television).

These two actions require the plugin from https://github.com/joshjowen/script.json-cec to be installed on Kodi, as there is currently no JSON API exposed for the CEC functionality.

dieterrosch avatar Dec 09 '17 06:12 dieterrosch

In my opinion, this belongs somewhere else, like home automation software. I don't think this skill is the place to turn on and off other equipment.

jingai avatar Dec 09 '17 18:12 jingai

I'd hate to get involved with having to have a list of compatible plugins people need to install as well.

m0ngr31 avatar Dec 09 '17 19:12 m0ngr31

Hi Joe,

It's obviously up to you, but to be fair this is is a Kodi skill, and switching on and off the currently active CEC device IS a function Kodi supports out of the box using libCEC (since all the Raspberry Pi's have CEC Hardware). It even has functionality built-in to switch off the device when the screensaver kicks in. It's not like one is asking Kodi to switch on the kettle or some other device that has nothing to do with watching movies. Kodi and the TV it is connected to, are tightly coupled.

I agree having to use the plugin sucks, but at the moment Kodi doesn't expose the CEC functionality via JSON-RPC, so the plugin is the only way. If people don't need the functionality, they needn't install it. If the plug-in changes or stops working (unlikely since it is tiny and simple), it still doesn't break the skill, it just means that function won't work.

dieterrosch avatar Dec 10 '17 00:12 dieterrosch

As this is a feature I would love to see I thought I'd give the pull request a go (using git fetch origin pull/240/head:240_cec to get the branch locally), however once deployed it breaks my endpoint with this error

"{u'message': u'An uncaught exception happened while servicing this request. You can investigate this with the zappa tail command.', u'traceback': ['Traceback (most recent call last):\\n', ' File \"/var/task/handler.py\", line 452, in handler\\n response = Response.from_app(self.wsgi_app, environ)\\n', ' File \"c:\\\\users\\\\will\\\\appdata\\\\local\\\\temp\\\\pip-build-4ykpow\\\\Werkzeug\\\\werkzeug\\\\wrappers.py\", line 903, in from_app\\n', ' File \"c:\\\\users\\\\will\\\\appdata\\\\local\\\\temp\\\\pip-build-4ykpow\\\\Werkzeug\\\\werkzeug\\\\wrappers.py\", line 57, in _run_wsgi_app\\n', ' File \"c:\\\\users\\\\will\\\\appdata\\\\local\\\\temp\\\\pip-build-4ykpow\\\\Werkzeug\\\\werkzeug\\\\test.py\", line 884, in run_wsgi_app\\n', \"TypeError: 'NoneType' object is not callable\\n\"]}"

Reverting back to Master and redeploying fixes the issue

willhowlett avatar Dec 21 '17 10:12 willhowlett

Getting this error message when merging:

Traceback (most recent call last):
  File "/var/task/handler.py", line 509, in lambda_handler
  return LambdaHandler.lambda_handler(event, context)
  File "/var/task/handler.py", line 237, in lambda_handler
  handler = cls()
  File "/var/task/handler.py", line 129, in __init__
  self.app_module = importlib.import_module(self.settings.APP_MODULE)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
  __import__(name)
  File "/var/task/alexa.py", line 1849
  kodi.AddonExecute(self, addon_id="script.json-cec", params={"command":"activate"}):
                              ^
SyntaxError: invalid syntax

How can I add this modification?

pittbull avatar Jan 11 '18 13:01 pittbull

@bigwillch @pittbull - I have been away on holiday, so haven't seen these messages. I will pull the latest master over the weekend, and see if I run into the same issues.

dieterrosch avatar Jan 11 '18 20:01 dieterrosch

@dieterrosch I were able to run the code by merging and altering the following:

Removed the " : " and "self" from these two lines:

kodi.AddonExecute(self, addon_id="script.json-cec", params={"command":"activate"}): kodi.AddonExecute(self, addon_id="script.json-cec", params={"command":"standby"}):

The code now executes upon calling Alexa. I am fairly new to Python and doing my best to learn so I am not sure if these changes are correct, but it runs - for now. :)

I would appreciate some feedback when you've tested it.

pittbull avatar Jan 11 '18 21:01 pittbull

Great work on this project. The only thing I was surprised was missing in the project was actually turning on the TV. I can't use it with the TV off, and once I'm already holding the remote, it seems silly to use voice commands. Hope the kinks get worked out and it's merged 👍

GrahamTheCoder avatar Aug 27 '18 20:08 GrahamTheCoder