Introduction: Amazon Echo Controlled IR Remote

Picture of Amazon Echo Controlled IR Remote

The Amazon Echo system can control a lot of aspects of a smart home, but a smart outlet can only turn off and on. Many devices do not instantly turn on by simple being plugged in and require additional steps, such as pressing buttons on a remote or the physical device to power on or get the desired settings.

In this guide, a Raspberry Pi Zero W will be configured to act as a smart home device that can be controlled by Amazon Echo, and send any desired IR commands to a device when requested to power on or off.

In this specific case, the Pi will be configured to learn the IR commands of a remote provided with a "ClassicFlame 23II310GRA 23" Infrared Quartz Fireplace Insert". An IR LED will then be used to send out the IR commands on demand, and finally the Pi configured to emulate a Philips Hue device that can be control be Echo.

Step 1: Materials

Picture of Materials

Required:

  • Raspberry Pi Zero Z
  • 4 GB or greater Micro SDHC Class 10 memory card (16 GB Example)
  • MicroUSB
  • 1 IR LED
  • MicroUSB Power Adapter (2.1 amps or higher recommended)
  • IR LED
  • IR Receiver VS/1838B
  • 100 ohm resistor
  • Misc. wire

Recommended:

To complete the initial configuration of a Raspberry Pi Zero W, a few additional peripherals will be required, but will not be in use full time by the completed project

  • Mini HDMI to HDMI Adapter: Used to connect Pi Zero W to a TV or monitor with a full sized HDMI cable
  • USB OTG Cable: Used to convert from micro-USB to full sized USB port(s) for connecting a keyboard and/or mouse
  • HDMI Cable: Used to connect to TV or monitor along with an adapter to mini HDMI

The first two items as well as a case are included various Pi Zero starter kits, such as: MakerSpot Mega Kit

Step 2: Setup Raspberry Pi

The Raspberry Pi website has an excellent walkthrough for setting up Raspbian OS on a Raspberry Pi. If you wish to have more Operating System options in the future, or a more simple setup, following the instructions for NOOBS will get you up and running in no time. This guide is based on Raspbian, which is included with NOOBS

https://www.raspberrypi.org/learning/software-guid...

Once Raspbian is running, enable SSH to allow remote connections to the device without needing a monitor/keyboard/mouse to be connected directly to the Pi. If you would like to optionally have remote access to the GUI, you can also enable VNC access

https://www.raspberrypi.org/documentation/remote-a...

It is also highly recommended you set a static IP on the wireless network configuration so it does not change over time. It is possible the IP may not change if new devices are not regularly connected to the wireless network, but configuring it as static will ensure it does not.

http://www.circuitbasics.com/how-to-set-up-a-stati...

Step 3: Learning IR Codes

Picture of Learning IR Codes

The following steps are highly based on the excellent guide found here:

http://alexba.in/blog/2013/01/06/setting-up-lirc-o...

The Linux Infrared Remote Control (LIRC) library is used to handle receiving IR commands through the receiver module, saving them to a file, and then sending the commands when desired through the IR LED.

The first step is to record the IR signals from our existing remote using the IR Receiver and saving them to a file. The IR Receiver is only needed initially to learn the IR signals and then could be removed, so a temporary connection could be used.

    Connect the IR Receiver to the Raspberry Pi. Use the attached picture to identify the VCC, GND, and Signal pins. Using a breadboard, hookup wires, or creative bending of the pins to the following connections

    VCC connects to 5 volt pin
    GND to a ground pin
    Signal to Pin 23

    Power on and connect to the Raspberry Pi through either by opening the terminal on the local device, or creating an SSH connection using a program such as Putty for Windows. The remaining steps will be typed into the command line interface


    Install LIRC

    sudo apt-get install lirc

    Add required information to the modules file

    sudo nano /etc/modules

    Add the following lines to the end of the file

    lirc_dev

    lirc_rpi gpio_in_pin=23 gpio_out_pin=22

    When finished, press CTRL+X, then Y, then Enter to exit and Save

    Modify the hardware.conf file with the following data

    sudo nano /etc/lirc/hardware.conf

    LIRCD_ARGS="--uinput
    # Run "lircd --driver=help" for a list of supported drivers.
    DRIVER="default"
    # usually /dev/lirc0 is the correct setting for systems using udev
    DEVICE="/dev/lirc0"

    MODULES="lirc_rpi"

    When finished, press CTRL+X, then Y, then Enter to exit and Save

    Modify config.txt so the LIRC kernel module is loaded on boot. Add to the end of the file.

    sudo nano /boot/config.txt

    dtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=22

    When finished, press CTRL+X, then Y, then Enter to exit and Save


    Reboot RaspberryPi

    sudo shutdown -r now


    Test IR Receiver by stopping LIRC and monitoring the input. First LIRC will be stopped, and then the LIRC device will be monitored

    sudo /etc/init.d/lirc stop
    mode2 -d /dev/lirc0
    Aim an IR remote control at the receiver and press a button and ensure data appears on the screen
    CTRL+C to stop

    At this point, the LIRC program is installed and we are able to view IR information. Now, either a remote profile can be downloaded from the LIRC website, or a custom profile can be created with your own remote.

    During this process, you will enter the name of the key you are recording. Only valid names are allowed, so run the following command to view all available names

    irrecord --list-namespace

    Example: I used the name KEY_POWER when I recorded the Power button on my remote and KEY_TIME when recording the timer button.

    If more than a few keys are being recorded, I recommend documenting the key names used and what button they map to, as there may not be a perfect name for the button being recorded. This will make it easier to reference in the future.

    Generate a Remote Configuration file

    # Stop lirc to free up /dev/lirc0
    sudo /etc/init.d/lirc stop

    # Create a new remote control configuration file (using /dev/lirc0) and save the output to ~/lircd.conf
    irrecord -d /dev/lirc0 ~/lircd.conf

    Follow the directions on the screen. Once the record is initialize, enter the key name you are going to used, and then press the button on the remote while pointing it at the receiver until several dots appear. Repeat this step for each button on the remote you wish to record.

    #Rename the remote in the configuration file
    sudo nano ~/lircd.conf
    Modify the line starting with name to reflect the device you are recording. In this case, it was renamed to Spectrafire

    When finished, press CTRL+X to exit and Save

    # Make a backup of the original lircd.conf file
    sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd_original.conf

    # Copy over your new configuration file
    sudo cp ~/lircd.conf /etc/lirc/lircd.conf

    # Start up lirc again
    sudo /etc/init.d/lirc start

    At this point, remote codes have been recorded to a file.

      Step 4: Headphone Jack (Optional)

      Picture of Headphone Jack (Optional)

      To make running wires and modifying the Raspberry Pi more modular, I hot glued a 1/8 inch headphone audio jack to the case and connected wires to the jack. Headphone wires with the matching plug were used to connect the IR LED, so this wire could be routed to an inconspicuous locate to point at the IR receiver of the device I wanted to connect, but could easily be unplugged from the Pi without needing to remove all of the wires.

      This is purely optional, but has come in handy.

      Step 5: Connecting IR LED (Quick)

      Picture of Connecting IR LED (Quick)

      Connecting the IR Emitting LED to the Raspberry Pi can be done multiple ways. This step shows the quick way I connected it, but which I found out later can exceed the current limit on the Pi's pins. So far I have not run into any problems, but a more ideal way of connecting is described in the next step

      Calculate the resistor needed for your IR LED. http://ledcalculator.net/ can assist with determining the proper resistor value if you have all specifications of your LED. In this case, the voltage of pin 22 is 3.3 volts, the LED voltage drop is 1.2 volts, current rating is 20 ma, and 1 LED was used, resulting in a value of 110 ohm resistor needed. I used a single 100 ohm resistor.

      Note: It was later brought to my attention that the max current of all pins at any given time is 16 ma, so this configuration could exceed that. A better configuration with a transistor and 5 volt supply is described in the next step, but after several weeks of running in this configuration, I have not encountered any problems yet.

      Pin 22 on the Raspberry Pi will be connected to the anode of the IR LED, which is the longer leg by default.

      The shorter pin of the LED connects to the resistor and then to the ground pin. I cut off most of the wire on the resistor and soldered it directly to a ground pin and to the ground wire going to the LED.

      Step 6: Connecting IR LED (correct Method)

      Picture of Connecting IR LED (correct Method)

      To properly connect the LED without exceeding the draw limit of the Raspberry Pi, connect the LEDs to the 5 volt supply with appropriate resistor, connect the cathode pin to the collector pin of a 2N2222 resistor, connect the Emitter pin of the transistor to ground, and connect pin 22 of the Pi to a 1K ohm resistor to the base pin of the transistor. This allow a very small current from pin 22 to connect the LED to ground, completing the circuit without over drawing the Pi.

      In my example, I wired up 2 IR LEDs, so I could control ambient lighting as well as the electric fireplace.

      Step 7: Testing Sending IR Commands

      Picture of Testing Sending IR Commands

      To send an IR command, the program irsend is used.

      Syntax: irsend

      Example: irsend SEND_ONCE Spectrafire KEY_POWER
      This sends the power button command from the Spectrafire remote once. Repeat with other key names used when recording the file.

      At this stage, you are able to send any commands previously recorded using the IR LED connected to the Raspberry Pi.

      Step 8: Installing Ha-bridge

      To allow the Echo to be able to control our device, we will emulate a Philips Hue bulb using ha-bridge. Once configured, the Echo will be able to detect this device and send power on/off commands to it.

      The website for ha-bridge clearly outlines the process for the current version and is highly recommended to review.

      https://github.com/bwssytems/ha-bridge

      Install HA-Bridge

      sudo apt-get install oracle-java8-jdk

      mkdir /home/pi/habridge

      cd /home/pi/habridge

      wget https://github.com/bwssytems/ha-bridge/releases/download/v4.3.1/ha-bridge-4.3.1.jar

      Run HA-Bridge

      sudo java -jar /home/pi/habridge/ha-bridge-4.3.1.jar

      To setup ha-bridge to run on startup using Systemctl

      cd /etc/systemd/system

      sudo nano habridge.service

      Copy and paste the following lines

      [Unit]

      Description=HA Bridge

      Wants=network.target

      After=network.target

      [Service]

      Type=simple

      WorkingDirectory=/home/pi/habridge

      ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge-4.3.1.jar

      [Install]

      WantedBy=multi-user.target

      Save and Exit (CTRL+X then Y and Enter)

      Reload system control

      sudo systemctl daemon-reload

      Start the service

      sudo systemctl start habridge.service

      Configure service to start on boot

      sudo systemctl enable habridge.service

      Step 9: Emulating a Philips Hue Bulb

      Picture of Emulating a Philips Hue Bulb

      With ha-bridge running, open a web browser and enter the IP address of the Raspberry Pi, and the interface for ha-bridge should appear.

      Click the Add/Edit link at the top of the page

      Name: Enter the name you want to use when speaking commands

      At the section labeled "On Items" set the type "Execute Command/Script/Program and enter the command in the Target Item box. If multiple commands are desired, click the Add button to save the current line and enter another command. It is also possible to set a delay and repeat a command a certain number of times. In this case, the power button needed pressed first, then the Timer button pressed 3 times to set the auto-off timer for 3 hours.

      Repeat the same idea for the "Off Items" area, clicking Add when finished.

      At the top of the page, click "Add Bridge Device" to save it as a new item, or Update Bridge Device if modifying an existing one.

      Aim the IR LED at the device. On the Bridge Devices page, click the Test ON or Test OFF button to verify it is acting as desired.

      Step 10: Connecting to Amazon Echo

      Picture of Connecting to Amazon Echo

      The last step is to allow the Amazon Echo to communicate with this device. Note: Both devices must be the same network.

      Option 1) say "Alexa, discover smart home devices"

      Option 2) Open the Alexa app, tap on Menu>Smart Home and click the "Discover Devices" link

      After a few moment, the device should be recognized.

      Speak, "Alexa, turn the bedroom fireplace on" and verify that the device turns on as expected. Replace Bedroom Fireplace with whatever you name your device in ha-bridge. Repeat the process to turn off the device.

      If you haven't mounted the IR LED yet, find an inconspicuous place to mount it while allowing it to point in the general direction of the IR receiver in the device. You may need to move it around to point at different areas to find the best location.

      Comments

      DIY Hacks and How Tos (author)2017-04-29

      Nice controller design. You've got my vote.

      About This Instructable

      2,973views

      37favorites

      License:

      More by MallocArray:Amazon Echo Controlled IR Remote
      Add instructable to: