TL:DR
My old Logitech universal remote, with the help of my new dog, finally kicked the bucket so I decided to make my own using a raspberry pi. After getting it all put together, I thought linking it with Home Assistant would be the easy part figuring there must be some sort of integration I could use with LIRC. I was partially right: there is a LIRC integration, but it’s only for input from an IR remote, not output for a controller. I started searching and came across this post Automating "unsmart" IR devices using lirc_web to send IR commands via http calls, but lirc_web didn’t work with Raspbian Buster for me. I then had the idea to try to use Node-RED and MQTT to coordinate everything, and luckily there is a LIRC node for Node-RED which makes it easy. This was my first time using Node-RED and the documentation for the LIRC node was kinda vague, but once you get the hang of it, it’s easy.
Pre-requisites/Links
1.) Raspberry Pi IR Remote: http://www.piddlerintheroot.com/ir-blaster-lirc/
2.) LIRC Rasbian Buster Configuration: https://www.raspberrypi.org/forums/viewtopic.php?t=243583
3.) Node-RED: https://pimylifeup.com/node-red-raspberry-pi/
IMPORTANT Node-RED needs to be installed on the LIRC raspberry pi. Unless Home Assistant is on the same machine as your IR remote, don’t download Node-RED via HA.
4.) LIRC Node-RED Node: https://flows.nodered.org/node/node-red-contrib-lirc
5.) Home Assistant with MQTT
Set-up
I mainly followed the first link for creating my remote. The tutorial is a little old and there are some changes you need to make. Essentially you change lirc_rpi to gpio-ir-tx and add the settings from hardware.conf to the lirc_options.conf file instead. I also got an error when I did the sudo modprobe lirc_rpi step, but I just contributed on and it worked fine from there.
Once LIRC is working, I install Node-RED on the your remote. Again, install Node-RED on the remote, don’t use HA to install it. Once node red is installed, download the LIRC module by clicking on the Menu in the upper right corner, then Manage pallete:
Then go to the Install Tab and search for node-red-contrib-lirc and install the node:
Now it’s time to set up Node-RED workflow. First lets setup the LIRC-Out node on the right side:
This is where it gets a little tricky, but in most fields, I just put the name of the remote I wanted to control. For example, I have a TV, DVD player, Receiver and Cable box I control my pi with. In mylircd.conf file, I have 4 remotes named tv, dvd, recv, cable, and we want to make an LIRC output node for each of remotes. For the TV remote, I used tv for the Controller and Device name fields. For Output, you have to put 1. It looks like it’s already there, but it’s really greyed out so be sure you put a 1 in that field. I also had to add a Controller for each entry, and again, it should match the name of the remote in your config file.
At this point, you can test everything to make sure it works. Drag an inject node out to the left:
By default it sends a Timestamp. Change that to string, and then enter the name of the button you want to test. I used KEY_POWER for my tv remote as the string:
Then connect the Ineject and LIRC nodes by using the boxes to the right of Inject and left of LIRC and hit deploy in the upper right and any blue circle above the nodes should go away:
Now if you hit the box on the left side of inject, it will send KEY_POWER to LIRC which should turn the tv on/off.
IF the test works, it’s time to set up MQTT to send the various button commands, that way we can use HA to send the messages and control the remotes. Again, you want wach remote to have it’s own mqtt.in node, so drag them out and place them to the left of the LIRC nodes. Enter in your mqtt info, and then decide on a topic for each remote. I kept it simple and used the remote/tv topic for TV and changed it accordingly for each remote:
Connect each MQQT node to it’s LIRC node, hit deploy again and you are all set:
As long has you have HA set up for MQQT, you can now control you LIRC by sending the key command your topic. No need to add irrsend or anything, Node-RED fills in all that info, just be sure you have a node and topic for each remote. Below you’ll see a picture of the remote I made in HA by creating a Vertical Stack card that is a bunch of Horizonat Stacks of buttons that send mqtt messages. I’ll post the raw configuration to github and put a link to it once I’ve posted it.