Using Broadlink RM4 Pro with Home Assistant
I have a Hunter ceiling fan that uses a RF remote control. I have always wanted to get it into Home Assistant and be able to set the fan speed and turn it off from there.
I had found this video on YouTube and so ordered a Broadlink RM4 Pro from Amazon. Adding it to the network was straight forward via the Broadlink iOS app. It is worth noting that I used the General Wi-Fi Device option at the bottom. I did not use the Universal Remote option. It immediately showed up in Home Assistant where I could add it.
The codes will be stored in a file that is written to the .storage folder in Home Assistant. That folder is hidden. I logged into Home Assistant via SMB and then unhid the folder. On a Mac that key command is command-shift-. I then opened the file in BBEdit (any text editor should do) and watched the codes get populated live.
If you are using the File Editor in the sidebar you can unhide the .storage folder. Go to Settings, Add-ons, File Editor.
Go to the Configurations tab. From there delete the .storage folder. You will now be able to see it via the File Editor.
Learning the codes was a bit fiddly. Go to Developer Tools, Services. Then do a search for Learn. You should see the below. Select: Remote: Learn command
You will then see the screen below. In my case the remote is an RF remote. IR is the default. Pick the Broadlink as the entity. Set the timeout to 60 seconds.
Give your device a name, in my case, Office_Ceiling Fan
Name the command you want to learn., in my case, it was turning the fan off. I used Fan_Off. I also used Fan_Speed_1, Fan_Speed2, Fan_Speed_3
This is where it got a bit strange and having the codes file open was helpful. When you press the Call Service button the LED on the Broadlink will go red. This means it is in learning mode. At this point I noticed a notification pop up in Home Assistant but didn’t think anything of it. Turns out, it was important.
If this works and sometimes it did not, the notification will go away and then another one will pop up.
Give it a few seconds, around ten and the code should appear in the file. All you need to do now, is go back to the learning command screen, you can keep the Device name and change the command you are learning and repeat the process. in my case, Fan_Speed_1, Fan_Speed2, Fan_Speed_3
If you watch the Broadlink the red light will go off when it has completed the frequency scan (this is the press and hold request), it will then come back on again. This is the press one more time request. If it is not working the red light will go off after 60 seconds and not come back on again. If needs be, just press Call Service again.
Now we need to test the command. Go back to the search at the top of the Services tab and search for, Remote: Send command
Now pick the Broadlink entity, enter your device name and the command you want to test. Press Call Service.
If you want to delete a command. You can again go back to the search and search for Delete. You can then add the device name and the command you want to delete, then call the service. Again, this is where having the code file open was handy. You can see the command being deleted.
Now we need a way to use this command in Home Assistant. We will have to use a script. Go to Settings, Automations & Scenes and the Script tab.
Click Add Script and choose create new script. Go to the three dots in the top right hand corner and choose, Edit in YAML. Below is the YAML I used to set the fan speed to level 1.
Change the alias and description to the name you want for the script. The entity_id is the Broadlink entity_id. The command is the name of your command. Here it is Fan_Speed_1. You can change the icon to whatever you want. This is a very handy site to find MDI icons. Make scripts for your other commands.
alias: Office Fan 1
sequence:
- service: remote.send_command
target:
entity_id: remote.office_broadlink_rm4_pro
data:
num_repeats: 1
delay_secs: 0.4
hold_secs: 0
device: Office_Ceiling_Fan
command: Fan_Speed_1
description: Office Fan Off
icon: mdi:fan-speed-1
mode: single
Now we need to trigger this script. The easiest way to do this is via a Button card. Go to your Dashboard and add a Button Card. In the Entity section add the name of the script you just made. Save it and trigger the command.
You should be good to go.
This is the YAML for the Button card
show_name: true
show_icon: true
type: button
tap_action:
action: toggle
entity: script.office_fan_off