I recently bought a Broadlink RM4 Mini for not very much money in the hope that I could use it to control my stereo, TV and air conditioning using my Home Assistant setup. The device itself is smaller than I realised (a bonus!) and is powered via usb cable plugged into a 5V/1A charger - I just used an old iPhone charger.
The device has Broadlink integration…but boy did I have to wrestle with it to get it working! I figured I’d record my progress getting it set up incase anyone finds it of use (and when I forget what I did and once again curse myself for not ever writing documentation!).
1. Adding the device to my iOT VLAN
Ok, this bit is irritating to anyone wishing to maintain a vestige of digital privacy. You NEED an account to get the device on your network with the Broadlink app (although it’s possible you could use various badly-documented utilities on GitHub- I couldn’t get these to work however). You don’t need the app beyond this, so it’s worth signing up with a burner account - I’ve been experimenting with SimpleLogin for burner email addresses I can delete if junk starts coming through.
The device broadcasts its own wifi network for setup which you connect your phone to. It’s easy enough to then input the network details you want it to connect to (in my case my iOT VLAN firewalled off from the rest of the network and the internet). Once the phone app prompted me to also connect to network I had just added the RM4 to I simply hopped onto my main VLAN and closed the app - job done. There is no need to complete the setup beyond placing the device on the network and, if you want to use it with Home Assistant, you absolutely SHOULD NOT complete the setup as connecting the device to the cloud service makes it impossible to control with Home Assistant. The app is probably crap anyway - and who needs ANOTHER APP to control iOT devices when Home Assistant can control it instead?
Now this bit was a mission…There are some guides out from the last few years that at least gave an overview of the process. The guides didn’t work for me for learning the IR codes - I think this might be due to the device being on a different VLAN. This video was helpful;
But ultimately after trying to get BroadlinkManager working on windows and docker for nearly a whole day with no luck I was beginning to lose the faith a little.
That’s when I discovered python-broadlink which I got to work! That said, I think it works with Python 2, so obviously not ideal…
The documentation for the project assumes you know how to use a Python interpreter already, so not the most inclusive thing going but hey-ho.
Once I had the code archive extracted I moved to the cli folder in the terminal and issued
$ python ./broadlink_discovery
From which I got the information
# broadlink_cli --type 0x62bc --host <the device ip> --mac <device mac>
Device file data (to be used with --device @filename in broadlink_cli) :
0x62bc <the device ip> <device mac>
Awesome! Now I might be able to actually start learning commands.
At this point you should see a Learning... prompt in the terminal. Point a remote at the device and press the button down you want to record for about a second or so.
You’ll get two sets of data - we want the Base64: information. Copy/Paste this somewhere as we’re going to give this to Home Assistant.
Rinse & Repeat for all the different buttons/ remotes you want to record.
A note about air conditioning units - in my experience the remote synchronises with the unit it is used with and the IR data that is sent is literally every setting for the unit to work with. That means that, even though it might have a temp up and down button on the remote, the signal that is being sent is not just temp up or down, but rather things like the blow angle, speed, cold or dry settings etc. This means that you have to think a bit about how you want to access this is in Home Assistant as EVERY combination of button presses would need to recorded if you wanted to incorporate the full funcionality of the remote - an intimidating job!
3. Testing Configs in Home Assistant
First the integration has to be enabled in Home Assistant. If you have the File editor Add-on enabled (VERY RECOMMENDED!), head to your configuration.yaml file. My config is:
Remember to save, check the config and restart Home Assistant.
Testing
This is straightforward enough with the Developer tools section of Home Assistant. Head to Developer Tools → Services and select the service broadlink.send.
In the service data type:
host: <ip of device>
packet: '<One of the learned buttons Base64 codes>'
and hit Call Service. With a bit of luck it should execute the command that was learned earlier. Make sure there is a space between the colon and the values (same as in the configuration.yaml file) as without one it didn’t work for me - cue an awful lot of head scratching until I figured it out!
4. Scripts, Switches and Buttons
This is where things get even more complicated. It seems to me that you have to make a choice between a button being part of a switch or a script. If you go for a switch you need to have an On and Off command. I found that my remotes used the same button for both, so you can just use the same value for both. This can also work for things like Volume up and down, but I wasn’t a huge fan of the default icon in Home Assistant for the up/down values. I decided to create scripts instead.
Rather than going through the rationale, I’ll just post my configs and some notes to explain what they are doing.
First, make sure that you have script: !include scripts.yaml or similar in your configuration.yaml so that a scripts.yaml file will be loaded.
Below is the section in my scripts.yaml to control my stereo. Only four buttons have been recorded - Power, EQ select, Volume Up and Volume Down. The packet: data is the Base64 value I recorded for each button.
This should like:
Which I think looks pretty snazzy. Each item in the menu is a separate button.
And that’s it - from this point onwards it’s a case of mining the Home Assistant documentation for automation and making buttons for the GUI interface.
I felt that all of this knowledge was a bit hard-won as, despite there being a fair amount of documentation for how to get this all working, a lot of assumptions are made by authors regarding prior knowledge. Home Assistant can be a bit of a beast to set up - there are just so many options and the online manual is not always either up to date or particularly helpful in the examples given for configuration of devices. That’s my impression anyway…it could just be I’m a bit thick.
Links that were somewhat helpful in getting all of this setup: