Showing posts with label Home Automation. Show all posts
Showing posts with label Home Automation. Show all posts

Sunday, 28 July 2013

Apple TV and F&H TV Remote Control with Arduino

One of the things I've been wanting to get working for a while is to 'script' some TV Infra-Red commands so that with one button I could make the TV turn on and switch to a certain channel, or to switch to HDMI and turn on the Apple TV. You can buy devices that will do this, but as usual if you build it yourself then you have much more flexibility over what you can do in the future. These are the two remotes I need to automate (an F&H TV remote, and an Apple TV):



There are two stages to this: one is to record the IR signals, the other is to then replay these signals. Fortunately both of these are made very easy using existing libraries. Ken Sherriff's blog has information about the Multi-Protocol Infrared Remote Library for the Arduino. I'm not going to repeat the information here, because the blog post is well written and I just used a very slightly modified version of the IRsend and IRrecv scripts in his examples.

With the IRrecv script you can record and decode the IR signals from an existing remote. Basically you need to:

- Install the library
- Use IRrecvDump sketch from the examples
- Use the Serial Monitor in the Arduino IDE to monitor the output of the Arduino
- Note the hexadecimal codes for the remote

For example, this video shows the recording of commands from the Apple TV Remote:



This was then performed for selected remote control button presses on the F&H TV and the Apple TV. Some of the identified codes are below:

F&H Codes

Power: Decoded NEC: 20DF10EF (32 bits)
Mute: Decoded NEC: 20DF906F (32 bits)
Up: Decoded NEC: 20DF02FD (32 bits)
Down: Decoded NEC: 20DF827D (32 bits)
Left: Decoded NEC: 20DFE01F (32 bits)
Right: Decoded NEC: 20DF609F (32 bits)
OK: Decoded NEC: 20DF22DD (32 bits)
Input: Decoded NEC: 20DFD02F (32 bits)
TV: Decoded NEC: 20DF0AF5 (32 bits)

Apple TV Remote Codes

Up: Decoded NEC: 77E15057 (32 bits)
Down: Decoded NEC: 77E13057 (32 bits)
Left: Decoded NEC: 77E19057 (32 bits)
Right: Decoded NEC: 77E16057 (32 bits)
Centre button: Decoded NEC: 77E13A57 (32 bits)
Menu: Decoded NEC: 77E1C057 (32 bits)
Play/Pause: Decoded NEC: 77E1FA57 (32 bits)


You can then modify the IRsend Example to send the particular codes for your TV. You need to call a specific function in the library for the "type" of remote, e.g. NEC, and then pass the hexadecimal for the actual code.  I've been making specific functions for particular IR codes, e.g. power_tv() in this case:

void power_tv(){
  irsend.sendNEC(0x20DF10EF, 32); 
}

... but I think this was a bad idea and I'll probably replace it with something more generic at some point.

What is slightly annoying is that the TV doesn't have a single button way of changing to a particular HDMI input. Therefore you have to do a really stupid hack where you activate the input menu and scroll down a specified number of times to get to HDMI 1 input!



The code for doing this is:

void switch_to_hdmi1()
{
  irsend.sendNEC(0x20DF0AF5, 32);  // switch to TV (not DTV)
  delay(5500);
  irsend.sendNEC(0x20DFD02F, 32);  // input menu
  delay(800);
  for(int i=0;i<5;i++)     // go down the menu 5 times
  {
    irsend.sendNEC(0x20DF827D, 32);  // down
    delay(400);
  }
}

So I can now get the Arduino to switch to particular channels on the TV, switch on the Apple TV and navigate menus. This is also integrated with the rest of my home automation system.

This was the Arduino setup during the development phase... it is slightly more discrete now :)



Note: in the picture on the right you can see that I'm using a XRF module from Ciseco to wirelessly send signals to the Arduino.

Tuesday, 21 May 2013

Tellstick on Raspberry Pi to control Maplin(UK) remote lights

This is a short post just to describe the setup of the Maplin (UK) lamp remote control switches so that you can control them using a Raspberry Pi.

The lamp controls come in packs of three or you can buy them individually.


They come with a remote, which from the back you can see uses 433.92 MHz.


However, to control these from the Raspberry Pi, I obtained a TellStick for about £20 on ebay. 

To get the TellStick set up on the Pi I followed this guide and I'm not going to repeat it here as it covers all the key steps.

The part that you need to know for these particular lamp controllers is when you come to the 'Configure Receivers' section. This is where you edit to configuration files for the telldusd service.

The file to edit is:

/etc/tellstick.conf

There are a number of different protocols that can be used for different brands of light switches. In this case, the configuration that worked for me was the risingsun protocol. 

user = "nobody"
group = "plugdev"
ignoreControllerConfirmation = "false"
device {
  id = 3
  name = "Living room light 3"
  protocol = "risingsun"
  model = "codeswitch"
  parameters {
    house = "4"
    unit = "3"
  }
}


The "name" can be defined by you. The "protocol" needs to be risingsun, "model" needs to be codeswitch, and the parameters for "house" and "unit" need to match what you set on the remote and the switches. In the diagram above on the remote you can see that the "house" is set to 4 ( IV ) and the buttons on the reverse of the remote provide on/off switches for each unit (1-4). In the picture below of an individual  switch, you can see house is also set to 4 ( IV ) and this particular unit is number 3. 


Once you save the configuration file, you need to remember to restart the service using:

sudo service telldusd restart

To actually control the lights you use:

tdtool --on 3
tdtool --off 3

... where the number following the on or off argument matches the "id" that you set in the configuration file. In the above example it was defined to be 3. 

You can add multiple units to the configuration file by duplicating the device section, making sure you add a new id and modify the "house" and "unit" values to match those on your switch. 

It is then fairly easy to create a simple web server to generate an interface and make calls to the tdtool in order to control the lights from a computer or smartphone.