Control RF and Ir devices using SmartThings and Alexa.
This project is maintained by beckyricha
# Read the main readme for this repository first! This document contains the setup instructions for the SmartApp version that does not require a SmartThings hub, instead using cloud-based control and the app “RM Bridge” as a bridge. This requires that you open a port on your router. You should, at a minimum, set up the security features in the RM Bridge app, but may wish to consider other security concepts as well. Research and decisions about network security are your responsibility, and I won’t be liable for that if you use this code.
Obtain an externally accessible and stable ip address. This will be easiest if you use a dynamic DNS service, which can be obtained for free. Setting that up is outside the scope of this readme but can be found online easily.
Forward the proper port on your router to the android device you will be using as a bridge. The RM bridge app defaults to port 7474 but you can use whatever port you want. Instructions vary by router and you will need to find that online if you don’t already know how.
I used the app designed for this device by its manufacturer (e-Control, available in the play store) to set it up. I only use this app for this setup but it can be installed and run on multiple devices if you also want to control things using the app directly. It’s not bad on its own. My Broadlink arrived with a manual only in Chinese, but install the e-Control app and follow its instructions to add your broadlink RM device to your wifi network. Don’t worry - the app is in English. I did not take detailed notes during this section and mine is already set up, but it was like many other apps. You can also add devices in the Broadlink e-Control app as you wish (for instance if you also want to use that app for device control), but that does not affect anything in the RM Bridge app or in SmartThings if you are using this version of my code.
Install the RM Bridge app, change any of the settings you wish and press the red circle where it says “stopped” to start it. Note the ip address and port where the bridge is operating, as well as your user name and password if you are using them. It will be most reliable if you can set your android up with a static ip address, but that is beyond the scope of this tutorial (it can vary for different android devices but is usually accessible under wifi settings by long pressing the name of your wifi network and selecting the advanced options).
For this to work, you need to record devices directly using a web portal that is designed for setting up devices with the “RM Bridge” app. You might want to read through this whole section before trying one, as both the concept and the step details are important. To make devices work with this app, you need to set them up in a very specific way.
We are going to add devices here and assign them functions that happen when you turn them on and when you turn them off in smartthings. This doesn’t need to actually be the power button on your remote. Let’s walk through the steps, and then I will explain some creative ways to use them afterward.
Learning the code works like it did in the e-Control app, if you played with that duribg setup. There is a different approach for RF or IR device. For an IR device bring your remote close to the Broadlink, click “learn code” and then press the button you want to learn. The web site will indicate success or not. For an RF device, bring the remote close the the broadlink, click “frequency scan” and hold down the remote button for several seconds, until the indicator on the top right side stops spinning. This is not completely reliable and may need to be repeated. After this records, click “learn code” and press the button you want to learn. If an RF device is being stubborn about accepting the code it sometimes helps to go back out to the previous web page and go back in to start over. It can also help to wait a second or two after pressing the web site’s button and before pressing a remote button. If this gets frustating, the RM Tasker App version does record codes more reliably as you can use the e-Control app that came with the Broadlink.
Here’s where some creativity can help, now that you’ve seen what the steps are. Even though these are labeled as devices and their on and off switches, they don’t need to physically be exactly that. These can be named as any action you want to put into a smartthings scene or action, or to trigger with the echo by saying “Alexa turn on __” or “start __”. It sometimes even responds to “switch to ____” which can be very natural. For example, you could have something easy like a light switch or outlet controller that does have an on switch and an off switch. You could also have a TV, where on and off are the same button, but you need to program it in twice, once with the name “on” and once with the name “off” if you want it to respond to both commands.
The following examples are written the same way for all 3 versions, but recording devices that include multiple remote keys (e.g. etering sveral numbers on your TV remote to “turn on” a channel) requires additional work if using the rm bridge app, described at the bottom of this readme. RM Tasker does this easily but has other trade-offs.
You could get creative with your device definitions and add any number of things in a way where Alexa can control them. If you set up a device called ESPN, and its “on button” is programmed to the keystrokes for that channel, your Alexa can respond to “turn on ESPN.” “Turn on the television” for me turns on the TV, remote HD sender I have and switches the HDMI to the proper input. “Turn to the other input” activates my HDMI switch, or you could program the keystrokes needed on your TV remote. I programmed in a single fan remote as 3 devices: “low fan,” “medium fan” and “high fan.” Each one has its corresponding button set to “on” and the overall remote’s “off” switch assigned to all 3. I also made one just called “fan” and set its off switch as well. Now I can tell Alexa to turn on the “low fan” or just to turn off the fan. The possibilities are endless.
For each device you want to add, perform the following steps while still in the smartthings IDE (the we site where you added the code): 1. Click “my devices” near the top of the screen. 2. Click “New Device” 3. Make the Device ID the exact same name as you entered in the web site when you were setting up the code learning, but do not follow it with a space or the word “off” or “on” as you did there (note that this must be unique - if this doesn’t work for you, you will need to change the deviceID referencec in the code to whichever other device field you want to use). You can either make the device’s name and label match that, or call it something else. I believe label is optional. Either the name, or label if present, is what SmartThings and Alexa will use to control your device (i.e. when you say Alexa, turn on [device name/label]). Having this differ from the device ID may be useful, for example if you have a remote controlled plug that you attach different things to (like I do at Christmas). Your RM Bridge name and device ID might be something boring like outlet1, but you could easily change the label to “Christmas Tree”, “Living room lamp” etc in the SmartThings app withut having to repeat this setup. (hat tip to user itsamti for making this suggestion and coding the change, along with upgrades to the switch controls in the ST app). 4. In the dropdown for device type, select “RM Bridge Switch Cloud” 5. Click “create”
Your device should now appear in the SmartThings app and work properly, and you can import it into Alexa for use there.
RM Bridge was not set up to directly use multiple keys. To make this work, I set up a separate device handler for these, called “RM Bridge Switch Cloud Multikeys.” I would only use this one for devices that actually need multiple keystrokes as it is somewhat slower than the main code. I set it up to accept up to 4 keystrokes but this is easy for you to adjust. This is installed just as the other device handler above was, including manually changing the ip, port and authorization information. The device codes are also recorded the same way, but now their names need to be “device name on” “device name on2” “device name on3” and “device name on4”, with the same pattern for any “off” sequence. If any of these are not recorded it will just send a command that does nothing, but does not cause any errors. If you need more or fewer keys (fewer just to speed it up if you don’t need them but doesn’t hurt anything to leave it alone), change the lines of code at 35 and 41. Note that the number 0 is milliseconds between commands. Some devices need a little time to process between commands, but usually the cloud processing lag will cover it. If you are getting bad behavor in this area, you can tweak this number. When you create the smartthings device, this is also as decribed above, but you need to select this device handler for your device type.