Friday 24 May 2013

Tasker for android and XBMC on a Raspberry Pi: Home Automation madness

Hello back, it´s been a while. But I have been playing with interesting toys lately. And this post is here to describe some of it.

Let us introduce the toys first:
1. Tasker for android : On Android market and project website. This is an automation app for android platform. It is very easy to use, there are tutos everywhere online, I won´t cover this part.
2. XBMC on a raspberry Pi computer. If you don´t know what this is, learn. It is worth it.
3. A Samsung Smart TV (model 40UE6300).
4. Json - RPC framework. This is the way to communicate with the XBMC on the raspberry Pi and create all the magic tricks. This is just for reference, I will create another post to describe more magic tricks.
5. Autovoice plugin for Tasker. This will help you be the master of your own android device, namely by allowing you to command it. Directly.
6. Tasker SSH Command launcher.

How? Read on!


First I installed the latest (FRODO) OpenElec distribution on my raspberry pi. This amazing little PC provides support for HDMI-CEC modules. That is, it can directly be used with a Samsung Smart TV (and not only), quietly obeying to the telly`s remote control. This is something that I took advantage of in order to control power of the TV via my android phone.

To achieve that I needed to be able to send SSH commands to XBMC through my android device. Tasker SSH command launcher helped me with that. After installing Tasker and the SSH plugin, I created a new task called "Turn TV On" and in there I placed an ssh command (it can be found under the plugins).
The procedure is straightforward: Define the IP of the raspberry pi, username and password (root and openelec are the standards) and sent the following command:

echo "on 0" | cec-client -s

There is a problem though: after sending this command, the HDMI CEC bridge is restarted and the TV remote no longer works. I need to find a way to overcome this problem, otherwise all you need for the command to work is to be on the same wifi (both android and XBMC).

Using the exact same procedure I implemented commands for turning off the TV:

echo "standby 0" | cec-client -s

and switching to XBMC input:

echo "as 0" | cec-client -s

Magic. Now I needed to bind the tasks to Autovoice...

Created a new Task in Tasker, named it Autovoice Recognize and inserted Autovoice Recognize (duh) in there. Then I connected this task with a shortcut on my android desktop, so that everytime the shortcut is hit, I am asked to give voice input.

Furthermore, I created 3 profiles in tasker under the names "Turn tv on", "off" and switch to XBMC. Each one of them triggers on the autovoice recognize state (new profile => state => plugin => autovoice recognize) with different keywords. It is important not to forget selecting "event behaviour" and defining the command filter.

This is how it is done. I just realized, I talk too much. Need to shoot a video...





7 comments:

  1. Hi there,

    Thank you for your post - do I need the SSH login if all I wish to do is run a JSON RPC command? How does the authentication work?

    Thank you

    James

    ReplyDelete
  2. I do that by using the "HTTP Poster and Locale Plugin" from android market. It installs an Action handler in Tasker which you can configure to your needs to make a POST to the xbmc pc.

    Apart from the Data / File field which is actually the JSON RPC command that you want to execute, don´t forget to fill in the Server:port field (for example http://192.168.1.15:8080) then the path which is most likely to be /jsonrpc and the content type set to application/octet-stream. Check out my other post "Tasker and XBMC, part 2", there is also a screenshot in there that corresponds to your question.

    Thanks for your interest. Cheers,
    Achilles

    ReplyDelete
  3. Hi,
    did You ever found a way to overcome the problem with TV remote, after sending " echo "on 0" | cec-client -s " command?

    ReplyDelete
    Replies
    1. No, unfortunately I haven´t. If anyone out there has, please share it with us!

      Delete
  4. I understand all of this and I thank you for posting the info. I was wondering if you knew how I can get the ssh commands to switch inputs on say... a samsung smart tv. Switching inputs to XBMC gave me an idear but the tv already switches inputs when power is applied to HDMI Devices. I just want to switch back.

    ReplyDelete
  5. I will write a small post for this :)

    ReplyDelete
  6. Check this out... http://kinkeadtech.com/2014/09/ok-google-turn-off-downstairs-lights/

    ReplyDelete