Making My Infrared Dumb Devices Smart with Google Home and Broadlink RM3

Author: mirai  //  Category: Life in general, Techie Stuff


Fast Tube by Casper

 

Introduction

A few weeks ago, I started a home automation project using my Google Home Mini.  With it, I was able to control “Smart-enabled” devices such as my Philips Hue and Sengled light bulbs, but I wanted to take it a step further by being able to my TV, DVR, ceiling fan, (non-smart) ceiling lights, and air conditioner -all of which work by controlling them with an old fashion 20th century infrared red remote control.  So I did a search on the internet to see if anyone else had tried this, and behold! I found several people who have converted their aging dumb devices, into 21st century internet aware smart machines -well sort of.  Thus began by mission to be able completely automate my home with Google Home.

Little did I know at the time that this would be no easy endeavor.  Although the components that I needed to accomplish my goals were relatively inexpensive and readily available, it took a lot of brain power,  and jumping through the proverbial hoop to make it happen.

Being a Johnny-come-lately, I soon found out that one very vital component called the Hue Bridge Emulator, which acts as the glue per se, to bring of the components together to talk to each other and work in harmony, had been debunked earlier this year, and was no longer available to use.  I immediately sought an alternative solution, but information was scarce. The majority of those who were able to get this to work, did it with use of the Hue Bridge Emulator within the Home Assistant Home Automation application – a free open sourced system.

After literally days of scouring the internet, watching several YouTube videos, and experimentation, I found one person who was able to do it without using the  Hue Bridge Emulator.  Instead, he used an Android device running app called “RM Bridge”, which acts a communication conduit between Home Assistant, Google Home, and IFTTT.  This sounded like the holy grail solution I was looking for, and even went as far buying a 6 year old Android phone from an internet auction for around $15.

However in the time it took to have it delivered to my door steps, I managed to come up with an even better solution that didn’t require an Android device, nor the Hue Bridge Emulator.  I don’t know if anyone else had managed to figure it out before me, but there was no information (that I could find) that indicated it.  So either this was still unscouted territory, or someone got this working but not sharing the love.  So being a good Samaritan,  I found that it’s my responsibility to educate others on how I did it.

What You’ll Need

You’ll need to the following:

  • Google Home (about USD $50)
  • Broadlink RM3 Blackbean IR blaster (about USD $30)
  • Home Assistant (a free download -latest and greatest version is best) running on Linux or on a Raspberry Pi device. (I have not tried it on Windows, but it probably can be done as well)
  • An IFTTT account (cloud service- also free at IFTTT.com)
  • Some kind of dynamic DNS service (I use no-ip.com, but any will do fine)
  • and of course your IR devices AND their IR remote controllers (if you have lost them or broken them, then sad day for you, as you’ll need them to teach Broadlink how to control your devices)

Now, I am not going to go through the specifics on how to install and setup Home Assistant.  There are PLENTY of videos and tutorials on how to do this.  I will only show how to set up Home Assistant as it pertains to getting Google Home to communicate with the Broadlink RM3 Blackbean.

I am going to go under the assumption that you know how to, or already have done the following:

  • Set up port forwarding on your home internet router
  • Set up dynamic DNS (duckDNS, no-ip are a couple of free dynamic DNS services)
  • You have setup and installed Home Assistant, and have a fair understanding on how it works and how to edit the YAML files.

So if you haven’t done these things, or don’t know how, again, there are PLENTY of videos and tutorials on how to do this, so bookmark this page and come back when you are ready.

 

Let’s Get Started

First thing you want to do is point your Home Assistant Server to the Broadlink (going forward, I will refer to the Broadlink IR blaster as just “Broadlink” as there are many incarnations of it)  I am using the RM3, but RM1/RM2 and Pro version “should” work too.

To point your Home Assistant the Broadlink, you’ll need to open the configuration.yaml file and enter the following lines:

switch:
  - platform: broadlink
    host: IP_ADDRESS
    mac: 'MAC_ADDRESS'

 

Make sure that your syntax and spacing are correct, otherwise you will have problems restarting your Home Assistant server.  For IP_ADDRESS, you’ll need to enter the IP address of your Broadlink.  This IP address should be static, because if it changes, your Home Assistant server will no longer be able to talk to it.  I basically reserved an IP address on my router, so that if I need to reboot it, or if some cluts  trips on the power cable, it will get the same IP address no matter what.  Refer to your router’s user manual on how to do IP reservation if you don’t know how.  You’ll also need to provide the MAC address as well.  On Windows, arp -a at the command line is your friend.  You’ll need to restart your Home Assistant server for the changes to take affect.

Home Assistant Setup

Now, go into Home Assistant and click on the services icon on the bottom left of the page.  It kind of looks like a TV remote control. You’ll then be taken to the ‘services’ page.

Click on the down the down arrow within ‘services’ and you will given a list of all of the services available.  You’ll need to choose ‘broadlink.learn_command_IP_ADDRESS’ (where IP_ADDRESS is the address of your Broadlink.  This tool will allow you to capture the IR signal code from your devices’ remote control.  You’ll need these codes to ‘teach’ Home Assistant how to control your device.

Next, click on the “Call Service” button.  This will put your Broadlink into “learn mode” and a little LED should light up indicating that its ready to learn the IR code. If your Broadlink doesn’t light up, you’ll need to check your IP address or MAC address setting within your Home Assistant’s configuration.yaml file.  If you are sure that the settings are correct, try using the Broadlink app for IOS or Android and make sure that the hardware is working properly.  If everything is working properly, the Broadlink should respond like this (see pic):

Broadlink LED indicator

 

If all is working well and your Broadlink is in standby mode, take the remote control for the device in question, and point it at the Broadlink, and press the button that you want want Home Assistant to learn.   If successful, the LED light will go off. Don’t press the button too long, otherwise you’ll get repetition which could be bad.

Next, you’ll need to go into  Home Assistant, and click on the “Overview” link on the left hand side. You’ll be taken to the Home Assistant default view page, where you should now see “Broadlink Switch” and “Received Packet” in one of the windows on the page.   You should also see a long string of seemingly random letters and numbers that may run off the page.  Something like this (see pic):

Captured IR Code

If your code is long and runs off the page, you’ll have be careful when copying it.  If you copy only part of the code that’s showing, your device will not behave correctly, so make sure you copy the entire code.   The way to do this is to place your mouse pointer BELOW the code, just above the “DISMISS” link, and highlight everything all the way up to “Received packet is:”.  This will ensure that the entire code is copied.   Then, you should paste into notepad first so that you can delete the extra stuff that you copied before pasting it into your yaml file(s).  If successful, the code should be fairly long and end in one or more “=” signs.  Here is an example of a code that changes channels on my TV:

JgDMAG44DQ4NKgwPDSoMDw0pDQ8MKg0PDCoNDg0qDSoNDg0qDA8NKQ0qDSoNKQ0PDA8NDg0qDQ4NDg0ODQ8MKg0qDQ4NDg0PDA8NDg0qDA8NDg0ODQ4NKg0ODQ8MDw0ODSoMDw0ODQACmG43DQ4NKg0ODSoNDg0qDA8NKgwPDSkNDwwqDSoNDg0qDQ4NKgwqDSoNKgwPDQ4NDg0qDQ4NDg0PDA8NKQ0qDQ4NDwwPDQ4NDg0qDQ4NDg0PDA8MKg0PDA8NDg0ODSoNDg0ODQANBQAAAAAAAAAAAAAAAA==

As you can see, it can get very long, so make sure you copy everything.

After, you have edited what you copied to notepad (so that you only have the IR code, you’ll need to copy the code into your yaml file.  There are several ways you can do this depending on how you want to activate and control your device, but since the end game for this tutorial is so that you can send a voice command to your device via Google home, I will show you how to create a script to do this.

Teaching Your Home Assistant New Tricks

The next step is to create a button within Home Assistant so that you can control your device with Home Assistant.  This part is very essential, because if  Home Assistant doesn’t know how to control your device, neither will Google Home.

You will need to open your scripts.yaml file.  You can also put this in your configuration.yaml file, but if you have a lot of devices with a lot of buttons, then your configuration.yaml could become very cluttered very quickly, which will make it difficult to troubleshoot and mange if there is a problem.

I guess the best way to explain how to put this into your scripts.yaml file is to show you a sample of what I have.  Below is the IR (infrared) code for the power buttons on my TV and DVR.  Since my DVR acts as the the tuner for my TV, I want them both to power on at the same time, so I put the IR code for both the TV and DVR under the same entity:

tv_dvr_on:
  sequence:
  - data:
      packet:
      - JgD+AW44....
      - JgDMAHI5Dg8....
   alias: TV and DVR Power (on)

Please note that I have truncated the IR codes because they are super long and would take a half a page each.  This is just to give an idea as to what a script for a button may look like. This is what it looks like in my text editor:

script yaml entry

This is what it looks like in my front end interface:

TV Power Button

Once the scripts appear in the front end of your Home Assistant, the next step is to test it.  Click on “Activate” next to your switch to send the command to your device to see if it controls your device.  If it didn’t work, the problem is likely with the IR code.  The best indicator is to see if the the LED blinks on the Broadlink.  If it blinks but your device doesn’t do anything, you’ll need to recapture the code.  It took me a few tries to get this right.  If it doesn’t blink at all, then there may be a syntax error somewhere, or the Broadlink doesn’t recognize the code as a legitimate IR code.  You need give it few tries.

If your button worked then we can move on the fun part -getting Google Home to call the script using your voice command!

However, before you start, there are few prerequisites.  Unless your internet provider gave you a static public IP address, you will need to create a dynamic DNS account.  Basically what this does is assigns a name like yourserver.duckdns.com to you.  This name is then mapped to your public IP address, so instead of having to remember a long series of numbers like 192.100.203.101, you simply have to remember your DNS name.

Now the other catch is that unless you are a business hosting your own on premise website, or are paying a lot of $$$ for premium service, you are most likely provided a dynamic IP address by your internet provider, which means that your public IP will changes periodically.  For IFTTT to work, it will need to know where to find your Home Assistant server at all times.  In order to do this, you’ll need to subscribe to a dynamic DNS server (most are free for their basic package -if you want something more customized and personal, then there’s a charge).  The service will then most likely require your to download and install a small piece of software on your OS to send updates to the DNS services, which will remap your public IP to DNS. And every time your public IP address changes the software will update the DNS service with your new IP address.  This is essential in that if you don’t do this, then eventually IFTTT will not be able to send commands to your Home Assistant server because its public IP has chnaged, and everything will stop working.

Another thing you’ll need to do is to create port mappings on your home router.  Most routers will have this functionality. A few may not, so definitely check!  Port mappings are a way for your home router to direct requests from the internet to specific web-enabled servers, devices, or services on your home network.

In this case, you want to tell your router that any requests coming in on port 8123 or 443 (if you are using https), needs to be sent to homeassistant_ipaddress:8123 or 443.  If you know how to do this, then proceed, otherwise look for some tutorials on how port mapping works and how to apply it to your home router.

If you are not clear on any of this, then stop here and learn more about dynamic DNS services and port mapping or port forwarding and how they work otherwise nothing else will work right.

 

If This Then That

If you ever did any command line scripting or any programming using BASIC, then you’ll feel right at home with using IFTTT.  An IF/THEN statement is a conditional statement that exists in most programming languages, and IFTTT has simplified it so that that even non-programmers can do simple conditional statements.  In other words, IF something happens THEN do something.  In this case the IF is going to be your voice command to Google Home, and the THEN will be the activating of the of the corresponding script that you created earlier, and that you’re going to link with IFTTT.  Example, if I say, “Ok Google, turn on my TV”, IFTTT will send a command to my Home Assistant server to activate the “turn on the TV script” and then the magic happens.  As I said in the beginning of this write up, I scoured the net for a device or service that’ll link Google Home with Broadlink and this is it! Sounds cool right?  Let’s get started then.

Firstly, if you haven’t already, you’ll need to go to ifttt.com and create an account. This takes about 2  minutes and its really easy.  If you have a gmail or facebook account, then its even easier.

Next, you’ll need to enable both Google Home and Home Assistan to communicate with IFTTT. To do this, edit the configuration.yaml file to point your Home Assistant server to the right IFTTT account.  To do this you’ll need to enter the following lines:

ifttt:
  key: xxxxx-x-xxxxxxxxxxxxx

To get the key, you’ll need to do the following:

  • Login into you IFTTT account (if you haven’t already)
  • Do a search for “Webhooks”.  This is basically an applet that makes API calls to specified systems or services.  In this case, your Home Assistant server.
  • Click on the Webhooks applet
  • Click on Settings in the top right corner
  • scroll down a bit and under “account info” you’ll see a URL like this:

 

 

 

The last portion of the URL is your key. Copy it and paste it next to “key:” in your configuration.yaml file. Save/check/restart.

Next, you’ll need to link the email account that is associated with you Google Home account to IFTTT.  You do this by doing the following:

  • Click on the menu on the top right corner and select “settings”.
  • Scroll down a bit and you’ll see an option to link to a gmail account.  Click on it and enter the same gmail account that you used for Google Home.

 

Creating API Calls from Google Home to Home Assistant Using IFTTT

Next is the part that brings it all together.  First thing you are going to do is create the condition or the trigger that makes the magic happen.  You do this by doing the following:

  • Within your IFTTT account, click on “My Applet” at the top of your screen.
  • Next, click on the “New Applet” button on the top right of the page.  You should now see this:
  • Click on “+this
  • Next you’ll need to choose from a choice of services.  In the search field, type “Google” and you see “Google Assistant” as one of the choices of services.  Click on “Google Assistant”.
  • Then, select “Say a simple phrase”

 

This is where you are going to enter your voice command.  If you want Google Home to turn on your TV for example, you’ll enter what you want to say here. For example, you could keep it simple and say “turn on the TV”, or you can mix it up and say something like, “it’s show time!”  You are given three different ways to tell Google Home to turn of the TV.  Theoretically, you could create a lot more phrases by creating multiple applets, but for for the sake simplicity, we’ll keep it down to just three.

Next, you’ll enter a response that you want Google to say back.  Example, you can have it say, “Ok, powering up the flux capacitor”.  Here’s what my applet looks like.  As you can see, I have chosen to keep it simple and boring.

Once you are satisfied with your commands for Google Home, next you’ll need to link it up with an action you want Home Assistant to take.  To do this, do the following:

Click on “Create Trigger” to save the conditional.

  • Form the screen below, choose “+that”
  • From the next screen, do a search for “WebHooks”:
  • Click on the Webhooks applet.
  • Then choose “Make a web request”

Now, this is where things can get a bit complicated for some, but if you’ve already successfully completed all of the steps above, then it should be very easy and straight forward.  In this applet, you are going to tell IFTTT to send commands to your Home Assistant so that it can operate Broadlink to send the proper commands to your device.  Here’s how to do it:

When you open your “webhooks” applet you will need to fill in the fields needed for IFTTT to properly send commands through your router to you Home Assistant server.

In the URL field, you will need to enter the public URL (DNS name) of your Home Assistant server followed by the port number. If you are not using SSL, the default port is 8123, otherwise you would type https: instead of http and no port number at the end, as https generally uses port 443 by default. You’ll type the path were the api hook is, followed by the command, then your api password of your Home Assistant server, if you have one.  (The api password is set in the configuration.yaml file.)  So the URL should look something like this:

Example: http://yourserver.example.com:8123/api/services/script/turn_on?api_password=your_password

Under method, you’ll be using the POST method.

Under “Content Type”, select Application/JSON (the screenshot above is incorrect)

Next, you are going to point the Webhook applet to your script.

Within the “Body” field, you’ll type the following:

{ “entity_id”: “script.your_script_name” }

where your_script_name is the name of the script you created.  If you have forgotten you can easily find this by going into the services page in Home Assistant and finding the script name in the right plane.  You can then simply copy and paste it replacing “script.your_script_name”

 

When you’re finished populating all of the fields with the CORRECT information, click on “Create Action”.

Optionally, you can choose to have IFTTT send notification to your mobile every time the command is used, but it can get grating after a while so I suggest not using the notification feature.

 

And that’s all there is to it!  You should now be able to say, “Ok Google,” give your command, it will magically happen!

One thing about IFTTT is that it’s not exactly screaming quick nor accurate.  Sometimes it can take up to five seconds to process a command.  But my personal experience with it has been good.  On average it takes 1 to 3 seconds to process a command.  Sometimes its pretty instantaneous, while other times it doesn’t work at all, and I would have to say the command again.  I assume that IFFT will get better and faster as time progress and more people sign on to it.

There’s another similar service called “Stringify”, that is more accurate, faster, and MUCH more easier to use.  The only issue is that it currently supports far less services.  I am currently experimenting with their version of Webhooks called “Maker”, but it’s been hit and miss.  I figure that it was due to my lack of knowlege and not the service itself.  Hopefully I can get it to work, because its much easier to configure, but for now, IFTTT is the go to app for me.

Happy Googling!

4 Responses to “Making My Infrared Dumb Devices Smart with Google Home and Broadlink RM3”

  1. Shai Naor Says:

    Hi,
    many thanks for the tutorial !!!
    I tried following your steps but I keeps failling in the scripts parsing.
    this is the only entry in scripts.yaml

    tv_on:
    sequence:
    – data:
    packet:
    – JgDSAJeREzcTNh……
    alias: TV Power (on)

    ERROR (MainThread) [homeassistant.config] Invalid config for [script]: [data] is an invalid option for [script]. Check: script->script->tv_on->sequence->0->data.
    can you please advise

  2. mirai Says:

    looks like your config format is off…make sure that you use the proper spacing. If you are new to HA, might want to watch a tutorial on how to edit the yaml file. HA is very temperamental about format, so you got to get it right. The syntax looks about right though

  3. Eee Says:

    I followed you as step by step. You explain it’s very clear, finally, i can have Jarvis haha.

  4. mirai Says:

    Fantastic…glad to be of help. I will write a tutorial on how to do this with stringify soon….

Leave a Reply