Automating "unsmart" IR devices

This follows up on the Feature Requests thread “Support for more universal remote controls”.

I am able to control and automate my unsmart IR devices through Home Assistant:

The toggle “Regarder TV”, which stands for “Watch TV”, for instance, is turning ON my TV, my DAC and HiFi amp.
“Eteindre TV” turns off everything.

I also have a web interface that I use to turn my smartphone (or any smart device) into a universal remote.


Tutorial

Hardware parts

  • Raspberry Pi and its accessories. Needs to be connected to your network. It can be the one your are running HASS on (my case) or another one or several ones.

  • IR emitter on the Pi’s GPIO

     * Easy/Lazy solution (I went for this one): purchase an IR extension board for the Pi ([http://www.ebay.fr/itm/IR-infrared-remote-Shield-V1-0-expansion-Transceivers-Module-for-Raspberry-pi-B-/291205297766](http://www.ebay.fr/itm/IR-infrared-remote-Shield-V1-0-expansion-Transceivers-Module-for-Raspberry-pi-B-/291205297766) or [http://www.aliexpress.com/item/Original-Raspberry-Pi-Accessories-RPI-Infrared-Remote-control-IR-Receiver-and-Transiver-2-in-1-Module/32243792691.html](http://www.aliexpress.com/item/Original-Raspberry-Pi-Accessories-RPI-Infrared-Remote-control-IR-Receiver-and-Transiver-2-in-1-Module/32243792691.html), for example)
    
     * DIY solution: there are a bunch of tutorials online ([http://alexba.in/blog/2013/06/08/open-source-universal-remote-parts-and-pictures/](http://alexba.in/blog/2013/06/08/open-source-universal-remote-parts-and-pictures/)) and it is not so difficult. If you want to customize your hardware setup, this is probably the best solution. 
    

In any case, carefully note the GPIO on which your emitter and receiver are wired as you’ll need those values later.

Software

Raspberry Pi side

For the record, all credits should go to Alex Bain for his Open Source Universal Remote as I mainly followed his tutorials for this part. I’ll be putting a lot of links directly to his website. Hope that’s fine.

You have to install LIRC (Linux Infrared Remote Control) on your Raspberry Pi.

sudo apt-get install lirc

Then, you have three files to upgrade:
Edit /boot/config.txt by adding:

#Added for lirc_rpi
dtoverlay=lirc-rpi,gpio_in_pin=18,gpio_out_pin=17

Replace 18 and 17 by the adequate values for your setup.
Reboot your Pi.

Edit /etc/modules by adding:

lirc_dev
lirc_rp

Change /etc/lirc/hardware.conf to:

#/etc/lirc/hardware.conf

Arguments which will be used when launching lircd

LIRCD_ARGS=“–uinput”

#Don’t start lircmd even if there seems to be a good config file
#START_LIRCMD=false

#Don’t start irexec, even if a good config file seems to exist.
#START_IREXEC=false

#Try to load appropriate kernel modules
LOAD_MODULES=true

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”

Default configuration files for your hardware if any

LIRCD_CONF=“”
LIRCMD_CONF=“”

Restart lircd:

sudo /etc/init.d/lirc stop
sudo /etc/init.d/lirc start

Lirc is installed!

You then have to test your receiver and emitter, and create configuration files for each of your remotes.
I suggest that you follow directly Alex Bain explanations there:
http://alexba.in/blog/2013/01/06/setting-up-lirc-on-the-raspberrypi/, starting from “Testing the IR receiver” section.
You’ll have to be patient as this can take a while.

Once your remotes are configured and you can control your IR devices through command lines, move on to the web part.
Intsall NodeJS: http://alexba.in/blog/2013/01/15/installing-nodejs-on-your-raspberrypi/
Install lirc_web: https://github.com/alexbain/lirc_web/blob/master/README.md

The web interface is accessible at: http://IP_OF_YOUR_PI:3000/

What is awesome with lirc_web is that it supports macros which allow you to sned IR commands to several appliances in sequence with a delay that you can define.

Home Assistant side

Since lirc_web provides RESTful API and there is a HASS RESTful Switch component, this part was quite straightforward :slight_smile:
I have included only the commands that I am using from HASS, either for the control panel or for automations:

  • Macros:
- platform: rest
  resource: http://IP_OF_YOUR_PI:3000/macros/Regarder%20TV
  name: "Regarder TV"
- platform: rest
  resource: http://IP_OF_YOUR_PI:3000/macros/Eteindre%20TV
  name: "Eteindre TV"
- platform: rest
  resource: http://IP_OF_YOUR_PI:3000/macros/Ecouter%20Musique%20NAS
  name: "Ecouter Musique NAS"
  • Basic keys:
- platform: rest
  resource: http://IP_OF_YOUR_PI:3000/remotes/SamsungTV/KEY_PAUSE
  name: "TV Pause"
- platform: rest
  resource: http://IP_OF_YOUR_PI:3000/remotes/SamsungTV/KEY_PLAY
  name: "TV Play"
- platform: rest
  resource: http://IP_OF_YOUR_PI:3000/remotes/Harman-Kardon_HK3490/KEY_MUTE
  name: "Mute Amp"
14 Likes

Very timely - I have just ordered an IR board for my spare PI and was mulling over the best way to integrate with HA :slight_smile:

1 Like

Thanks for sharing this. May I know for the IR emitter, between the easy solution vs. DIY solution do you think are there any pros and cons between the two, particularly the signal range or coverage? I notice the cost for DIY is significantly higher. Just wondering what justify the higher cost.

I don’t think that you will have significant difference between DIY and easy solution in terms of range or coverage.
However, DIY solution will bring more flexibility as you will be able to position the IR emitter exactly where you want, with the orientation that you want. And if your RPi has a case, it will be easier to put the emitter outside of it, somehow.
About the cost, I don’t know. For the easy solution, you can find a wide range of prices. Given the components needed, a fair retail price should be 5-8$. I think the DIY solution will be cheaper if you already have some parts from other projects.

i plan use the easy way and put it inside a transparent casing. shouldn’t be a problem right?

The reason I am saying the DIY cost more is because the first item in the list (Adafruit RaspberryPi Protoboard) already cost USD $12.66. I haven’t include other parts yet.

Transparent case should be fine.
I don’t have any case so far on my side.
Always wanted to do a nice one including a light guide (to gain flexibility on the position of my RPi) but never moved forward with this. I have no hardware skills so never really looked into it…

I have ordered a couple of the boards you recommended. ETA around 1 month. Once I have tested it, I will let you know how it turns out.

FYI, I just created a LIRC component for getting IR commands into HA. https://github.com/home-assistant/home-assistant/pull/2139

That’s cool! May I know is the transmitter and receiver install on the same Pi with your HASS? Can it work on separate pi?

I think it could work on a separate Pi if they had a network connection. LIRCD has listen and connect modes that can work over the network. I have not tried this myself, but it appears doable.

1 Like

great one !
where is the part when you “listen” to your devices to see their IR CODE and change the lirc file?
you dont need it? (hope i explained my self well :slight_smile: )

@faljeremy, you do need this part.
You have to follow the steps as explained by Alex Bain on his site, under “Testing the IR LED”.
This specific command is the one that will start irrecord:

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

Once you use it, it will prompt you to press keys and then type the name of each key.
It is very important to use only names that are understandable for LIRC.
To list such names, you need to run the following command:
irrecord --list-namespace

have you tryed to record air condition IR?

No, but it shouldn’t cause any trouble. I use only A/V devices but with many different standards and frequencies.
Lirc might not offer standard names that fit well with air conditioning but with lirc_web, you can change the names of the keys to put friendly names instead of the Lirc ones so in the end, the names you give to each key when using irrecord won’t matter.

lirc_web? i know lirc but what is lirc_WEB? :slight_smile:

@faljeremy, check the README here, as per my initial post:

i will read it ! thank you!!

is this insted of using lirc_web? and HASS RESTful Switch?

LIRC (Linux Infrared Remote Control) is mandatory to interface your IR emitter with a Linux environment. So you need it anyway.
However LIRC only allows to send IR signals through command lines.
This is where lirc_web jumps in : it provides a Web interface to LIRC instead of command lines.
lirc_web also provides RESTful API which I use to control my IR emitter directly from HASS via the RESTful switch.

So the flow is :
HASS - > RESTful switch - > lirc_web - > LIRC - > IR emitter - > your IR receiver

i will try it.
i am using hass with shell commands and scripts to activate command line for my IR as you mentioned