m0ngr31 / kanzi

Alexa skill for controlling Kodi
https://lexigr.am
MIT License
427 stars 149 forks source link

Add support for switching TV on and off via CEC #240

Open dieterrosch opened 6 years ago

dieterrosch commented 6 years ago

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.

jingai commented 6 years ago

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.

m0ngr31 commented 6 years ago

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

dieterrosch commented 6 years ago

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.

willhowlett commented 6 years ago

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 thezappa tailcommand.', 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

pittbull commented 6 years ago

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?

dieterrosch commented 6 years ago

@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.

pittbull commented 6 years ago

@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.

GrahamTheCoder commented 6 years ago

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 👍