Skip to content

RM4 PRO not supporting a certain frequency for RF signal learning #834

@isur3n

Description

@isur3n

I have roller shades that work on RF remote with frequency 433.8hz. I have tried app to learning shade up and down commands. However, roller shade motors operate only after long press. App is generating a short burst of signal which only moves shade by few milimeters.

Hence I moved to home assistant. But home assistant is not able to learn the command. When I researched, I found Home Assistant is doing sweep and not able to detect signal of 433.8 hz frequency. LED on RM4 PRO turns amber so home assistant is indeed trying to learn a command throug RM4 PROD.

I took refuge to google gemini which gave me 2 versions of code. Both of them fail with same error.

Script 1

`
import broadlink
import time
import binascii
DEVICE_IP = "192.168.1.222"
DEVICE_MAC = "e8:70:72:ba:68:de"
RF_FREQUENCY_MHZ = 433.8

def set_rf_with_frequency(ip_address, mac_address, frequency):
mac_bytes = binascii.unhexlify(mac_address.replace(':', ''))
print(f"Converted mac address {mac_bytes}")

try:
	print(f"Connecting to BroadLink RM4 Pro at {ip_address}")
	rm4_pro = broadlink.hello(ip_address, timeout=5)

	if not rm4_pro:
		print(f"Error: Could not find device at {ip_address}")
		return
	rm4_pro.auth()
	if rm4_pro.mac != mac_bytes:
		print(f"Error: Device at {ip_address} has the wrong MAC address.")
		return
	print(f"Authentication successful for device with MAC {mac_address}.")
	print(f"Setting RF learning frequency to {frequency} MHz")
	try:
		print(f"Locking device to {frequency} MHz...")
		rm4_pro.set_rf_frequency(frequency) 
			
	except AttributeError:
		print("Standard method failed, sending raw frequency header...")
		try:
			rm4_pro.sweep_frequency()
			print("Sweep started. Please tap the remote button repeatedly.")
		except Exception as e:
			print(f"Could not initiate frequency set: {e}")
			return
	print("Now waiting for data... Call the Home Assistant 'learn' service now!")
	rm4_pro.find_rf_packet()
	time.sleep(30)
	print("Entering RF learning mode (waiting for short press)...")
	rm4_pro.find_rf_packet()
	print("Script finished. Check Home Assistant for the learned code.")

except broadlink.exceptions.AuthenticationError:

if name == "main":
set_rf_with_frequency(DEVICE_IP, DEVICE_MAC, RF_FREQUENCY_MHZ)`

Error -

Converted mac address b'\xe8pr\xbah\xde' Connecting to BroadLink RM4 Pro at 192.168.1.222 Authentication successful for device with MAC e8:70:72:ba:68:de. Setting RF learning frequency to 433.8 MHz Locking device to 433.8 MHz... Standard method failed, sending raw frequency header... Sweep started. Please tap the remote button repeatedly. Now waiting for data... Call the Home Assistant 'learn' service now! Entering RF learning mode (waiting for short press)... Script finished. Check Home Assistant for the learned code.

Script 2
`
import broadlink
import binascii

--- Configuration ---

DEVICE_IP = "192.168.X.X" # Example IP address
DEVICE_MAC = "XX:XX:XX:XX:XX:X" # Example MAC address (hex string without colons)
RF_FREQUENCY_MHZ = 433.8

def learn_rf_with_frequency(ip_address, mac_address, frequency):
mac_bytes = binascii.unhexlify(mac_address.replace(':', ''))

# Manually create the device object as an RM4 Pro
# 0x6026 is a common Product ID for RM4 Pro, but the IP/MAC is what matters most
dev = broadlink.rm4pro((ip_address, 80), mac_bytes, 0x6026)

try:
    print(f"Connecting to {ip_address}...")
    dev.auth()
    
    # Convert MHz to Hz for the library
    freq_hz = int(frequency * 1000000)
    
    print(f"Setting frequency to {frequency} MHz...")
    # This method is specific to the rm4pro class
    dev.set_rf_frequency(freq_hz)
    
    print("Entering learning mode. Press your remote button now.")
    dev.find_rf_packet()
    
    # After this, you can call the Home Assistant 'remote.learn_command' 
    # service as usual to capture the actual data.
    
except Exception as e:
    print(f"Error: {e}")

if name == "main":
learn_rf_with_frequency(DEVICE_IP, DEVICE_MAC, RF_FREQUENCY_MHZ)
`

Error -
Connecting to 192.168.1.222... Setting frequency to 433.8 MHz... Error: 'rm4pro' object has no attribute 'set_rf_frequency'

Please help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions