Sunday, 4 June 2017

HOME AUTOMATION: Using the Black Bean RM Mini 3 with openHAB

While there are a number of options out there for controlling infrared appliances like your TV and Air conditioner from your smartphone, none have come in at the price point of the Broadlink Black Bean RM Mini 3. I purchased 3 of the units from gearbest on flash sale for 12.89USD each with plans to use them only with the Broadlink app.

The app got old pretty quick so I started to dig in to openHAB integration. While there isn't an official openHAB binding for the devices there are a few python libraries out there for controlling the black bean. Combine those python scripts with the Exec binding and we can roll our own openHAB solution.


Requirements



Python Library Setup

Go ahead and configure the RM Mini devices per the Broadlink instructions, then set a static IP on your router for each of the devices. We need to do this because the python control script reference the device by IP address. 

Install the python-broadlink library and test the basic functions to ensure the library is working. 
 cd ~/addons/  
 git clone https://github.com/mjg59/python-broadlink.git  
 cd python-broadlink  
 python setup.py build  
 python setup.py install  

Test the installation by running python in the command line and testing a few of the functions in the readme:
 python  
 >>> import broadlink  
 >>> print broadlink.discover(timeout=5)  
 [<broadlink.rm instance at 0x7661XXXX>, <broadlink.rm instance at 0x7661XXXX>, <broadlink.rm instance at 0x7661XXXX>]  
 >>> quit()  

The above confirms that the library found 3 devices on my network.


Now that we have confirmed the python-broadlink library is working, install the blackbeancontrol library:
 cd ~/addons/  
 git clone https://github.com/davorf/BlackBeanControl  
 cd BlackBeanControl  

Test the library is working as expected by first configuring a default unit in the BlackBeanControl.ini and then attempting to learn a command. If the command argument name exists then it will be executed by the device, otherwise it will put the device in to the leaning state and wait to lean the command and save it for future use:
 python BlackBeanControl.py -c LG_TV_Vol_Down

If everything went to plan you should have seen the device go in to learning mode, learn the command, then if running the same command again you should have seen the command executed.
Next step is to pair this python script with the exec binding to enable control from openHAB.


openHAB Setup

Depending on how you would like to control your RM Mini from openHAB there are a few ways to configure your items and sitemap. I've previously written up a few examples on this topic.

Typically I want my IR devices to function like a push button remote so I use items and rules to create my buttons (as opposed to things and items with the exec binding).

Item
String TV_GF_Power "TV Power"

Rules
 rule "LG TV Power"  
 when  
     Item TV_GF_Power received update  
 then  
     executeCommandLine("python /home/openhabian/addons/BlackBeanControl/BlackBeanControl.py -c LG_TV_Power -d Lounge", 1000)  
 end  

Sitemap
Switch item=TV_GF_Power mappings=[OFF="Power"]  

2 comments:

  1. Thank you! You made my day. I had some issues running these because i used python3. With python 2 everything went smooth.

    ReplyDelete
  2. Hello mate!!
    How to write rule for a keypad??I have a keypad in my UI, but not sure how to send the command to each one of them.

    ReplyDelete