# Read the main readme for this repository first! This document contains the setup instructions for the SmartApp version that uses the SmartThings hub for local LAN control and the app “RM Bridge” as a bridge.
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 the service. This code will only work while this service is running. 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 steps 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.
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. A “device” can be 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 fllowing steps while still in the smartthings IDE (the web 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). 5. In the dropdown for device type, select “RM Bridge Switch LAN” 6. Make sure to select your location and hub. this uses your hub so needs to be connected. 7. 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 LAN Multikey.” I would only use this one for devices that actually need multiple keystrokes as it is slower and less reliable than the main code. I set it up to take up to 4 keystrokes. It 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 are “device name on” “device name on2” “device name on3” and “device name on4”, with the same pattern for any “off” sequence. If any are not recorded it just sends a command that does nothing, but does not cause any errors. If you need more or fewer keys, change the lines of code at 36 and 40. Note that the number 1000 is milliseconds between commands. I found that my hub needs this long to clear and accept another command, but you may need to tweak this depending on how yours is responding. When you create the smartthings device, this is also as decribed above, but you need to select this device handler for your device type. If this does not work well, I have also developed a cloud-based version that may work more reliably if you want to open a router port. I don;t routinely usse this one, so please start an issue if you have trouble and I’ll try some things that may improve it. I don’t plan to do this until someone needs it.