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.

Broadlink Home Assistant Integration

Broadlink Home Assistant Integration Entries

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.

Broadlink codes file in .storage

Example of the learnt codes.

If you are using the File Editor in the sidebar you can unhide the .storage folder. Go to Settings, Add-ons, File Editor.

File Editor in Add-Ons

Go to the Configurations tab. From there delete the .storage folder. You will now be able to see it via the File Editor.

File Editor Configuration Page. .storage has been removed

The .storage file is visible in 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

Finding the 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

Remote: Learn command screen

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.

Press and hold the button you are learning. I was learning Fan Speed 2 at this point, not Fan Off

If this works and sometimes it did not, the notification will go away and then another one will pop up.

Press the button you are learning one more time

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

Searching for Remote: Send command

Now pick the Broadlink entity, enter your device name and the command you want to test. Press Call Service.

Testing the learnt command

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.

Deleting a command

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.

Button card to trigger the script

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
 
Michael Curtis

My introduction to computers started at my middle school in 1981 when our maths teacher brought in a ZX80. That led the computer club being founded and using a Research Machine 380Z

My first computer was a 48K ZX Spectrum which I loved to programme. Once I left school I worked as a photocopier engineer, then a fax engineer and finally moving on the Apple computers.

For the next 30 years I worked as a system administrator. I now work in the cyber security industry as a Sophos Professional Services consultant

https://www.bazmac.me
Previous
Previous

Sunsynk power flow card for LuxpowerTek Inverter (Update 3)

Next
Next

May Solar Generation and Export Numbers