bwssytems / ha-bridge

Home automation bridge that emulates a Philips Hue light system and can control other systems such as a Vera, Harmony Hub, Nest, MiLight bulbs or any other system that has an http/https/tcp/udp interface. This is a compact impl to run on small format computers. This is impl started from this project https://github.com/armzilla/amazon-echo-ha-bridge.
Apache License 2.0
1.45k stars 198 forks source link

Support for Broadlink Rm2/pro #236

Closed merlin051 closed 6 years ago

merlin051 commented 7 years ago

Anyone know how to get the bridge to talk to a Broadlink IR/RF blaster?

audiofreak9 commented 7 years ago

http://milillicuti.com/an-api-to-connect-your-broadlink-rm-pro-irrf-wifi-bridge-to-your-home-automation-system/

merlin051 commented 7 years ago

Great, have you got this working fine?

audiofreak9 commented 7 years ago

No, sorry to say I just Googled: "Broadlink IR/RF blaster API" and it seemed descent after quickly reading. It allows HTTP calls, which is what you are after.

merlin051 commented 7 years ago

Yeah I've already read that article, got to the point when I needed an a droid device as a other bridge and stopped reading.

audiofreak9 commented 7 years ago

Yeah, even this github project requires an Android intermediary device: https://github.com/beckyricha/Broadlink-RM-SmartThings-Alexa

Sorry for the joykill!

merlin051 commented 7 years ago

I might have to write something to do this!

audiofreak9 commented 7 years ago

If you can read Chinese (or translate) here is the SDK: https://drive.google.com/file/d/0B65vYtefY0h2aE1LdWF5RG9sX00/view

merlin051 commented 7 years ago

My Chinese is a little rusty.

peadard commented 7 years ago

I spun up an android vm as I don't own an android and ran the bridge in that. The I used rm commander tools to generate the code. My home automation system then runs a batch file that contains the code. So far it works pretty well

farhanito commented 7 years ago

https://github.com/mjg59/python-broadlink

tuspam commented 7 years ago

Working via Android intermediary device and python broadlink also

tyjtyj commented 7 years ago

anyway to convert https://github.com/mjg59/python-broadlink to java ?

buserror commented 7 years ago

+1 for a 'native bridge' -- the android tasker plugin doesn't work here anyway.... The broadlink is otherwise pretty nice, and very cheap; handles 433Mhz devices too which is quite cool.

bwssytems commented 7 years ago

@tyjtyj That is the basis of what I am looking into to be able to control a Broad link. The only thing is, what to control and how. It is an IR/RF/SmartPlug/SmartPowerStrip controller.

tuicemen commented 7 years ago

Add me to the list of users looking for this!

I've used the RM bridge management Page to learn IR device codes http://rm-bridge.fun2code.de/rm_manage/index.html Running the RM Bridge on an android TV box I can manually send signals to a device via the https short link however I can't get the HA-Bridge to send these. Anyone got it working that way?

merlin051 commented 7 years ago

There are some python scripts kicking about but I haven't had the time to review them all yet. This should be possible.

It seems overkill to need an android running tasker for this to work.

farhanito commented 7 years ago

currently I am using broadlink-mqtt (https://github.com/eschava/broadlink-mqtt), another excellent project based on the python-broadlink. since HA-Bridge also has support for mqtt, everything works nicely.

merlin051 commented 7 years ago

Farhanito,

Can you give us any more detailed information on this?

I've never used mqtt before. Do I need something running a mqtt broker?

Alexa > Habridge > Mqtt broker > Broadlink ?

farhanito commented 7 years ago

hi @merlin051,

yes, I'm running an mqtt broker (mosquitto) on the same machine (RaspberryPi) as HA-Bridge. and then run the broadlink-mqtt script to make RM device subscribed to certain topics.

after that you can tell Alexa to publish commands to that topic via HA-Bridge

merlin051 commented 7 years ago

@farhanito

I think I'm missing something, and i think I've misunderstood what MQTT(Mosquitto) does.

I've got mosquitto installed and running as a service on my windows box( same machine running HA Bridge)

I was expecting some sort of interface where i can map devices/commands?

I've got python installed, i use it for my Orvibo s20 control scripts, not sure how I can feed the broadlink script you pointed out into my environment?

any guidance much appreciated.

tuicemen commented 7 years ago

Not sure if the new version of the HA-Bridge helped but I can now send the links for IR signals to the RM Bridge ( https://play.google.com/store/apps/details?id=de.fun2code.android.rmbridge) Alexa now turns on/off my TV

merlin051 commented 7 years ago

@tuicemen i really want to try and avoid setting up an adroid bridge to act as a middleman in an already complicated setup.

tuicemen commented 7 years ago

@merlin051 As would I, but setting up another server using MQTT(Mosquitto) is even more complicated I feel. Since I already had an Android TV box for streaming this was the best solution for me (for now).

farhanito commented 7 years ago

@merlin051 if you already have mosquitto running, then just run the broadlink-mqtt. make sure you already installed the required python modules (paho-mqtt and broadlink)

here's my broadlink-mqtt config:

Type of device. Valid options are 'lookup', 'rm', 'sp1', 'sp2', 'a1'

device_type = 'rm' # I use rm

lookup parameters

lookup_timeout = 20

local_address = '127.0.0.1'

parameters for direct connection

device_host = '192.168.31.108' # rm ip address device_mac = 'B4:43:0D:xx:xx:xx' # rm mac

MQTT connection parameters

mqtt_broker = 'localhost' # default: 'localhost' mqtt_port = 1883 # default: 1883 mqtt_clientid = 'broadlink' mqtt_username = '' mqtt_password = '' mqtt_topic_prefix = 'rm3/'`

after that, you can try publishing an mqtt message for example

topic = rm3/tv/samsung/ON content = record

this will make your rm goes into learning mode, ready to copy your remote button. when finished, it will automatically save the code in a file (named ON) inside this directory

../broadlink-mqtt/commands/tv/samsung/ON

to execute the command, publish this message

topic = rm3/tv/samsung/ON content = replay

good luck,

merlin051 commented 7 years ago

@farhanito thank you for your help.

I now have everything up and running. although I couldn't get the MQTT native stuff to work in HA Bridge. so I've just used a custom execution and [mosquitto_pub.exe] like this as a command:

C:\Program Files (x86)\mosquitto\mosquitto_pub.exe -t rm/soundbar/HDMI2 -m auto

any chance you can screenshot one of your devices config pages for me?

Matt8119 commented 7 years ago

@farhanito sounds like you have mastered it!

a screenshot of your settings would be great! i've been racking my brain how to integrate my RM PRO also. i'm using FIBARO HC2 and everyone i have communicated with, said id have to install home assistant as "another" bridge just get this thing communicating with my two google home's...

Matt8119 commented 7 years ago

@farhanito are you talking about this python module "eclipse/paho.mqtt.python" or this one "eclipse/paho.mqtt.java"?

merlin051 commented 7 years ago

@Matt8119 since I installed it using pip it's got to be paho.mqtt.pyhton I think.

tyjtyj commented 7 years ago

hi all,

I am using just python code below


# file send_rf.py
import time
import sys
import broadlink

def senddatahex( hex_data ):
    #print hex_data
    #count zero padding
    pad_len = 32 - (len(hex_data) - 24) % 32
    hex_data = hex_data + "".ljust(pad_len, '0')
    #print hex_data
    myrm2.send_data(hex_data.decode('hex'))
    #print "Success"
    time.sleep(0.5)
    return

def get_rm2():
    myrm2 = broadlink.discover(1)
    myrm2 = devices[0]

    #or you can hard code it 
    #myrm2 = broadlink.rm(host=("192.168.1.10",80), mac=bytearray.fromhex("b4 43 00 00 00 00"))
    myrm2.auth()
    return myrm2

#Begin 
command = sys.argv[1].lower()
if sys.argv[2:]:
   btnOnOff = sys.argv[2].lower()

myrm2 = get_rm2()

if command == 'raw':
    senddatahex(btnOnOff)
    exit()

based on https://github.com/mjg59/python-broadlink

Under HA Select Script Program On URL X:\python-2.7.12.amd64\python.exe X:\2broadlink\send_rf.py raw 260058000001289313121212143513121411131114111411133614361311133613361336143514361312131212371311141114111435133614351435141212371336133614101411140005260001264913000c4f0001274814000d05

Above is On code for LG tv.

Hope this helped

farhanito commented 7 years ago

@merlin051 @Matt8119

sorry I'm on mobile right now, can't give you proper screenshots.

first, don't forget to add your broker settings in the HA-Bridge config http://i.imgur.com/TBBPAAy.png

after that, you can go to the MQTT Messages tab and add your topics and content (auto or replay). http://i.imgur.com/oSf8SK4.png

pressing "Build publish Message" button will open the Device creation page. Modify the device name as needed, and review the On/Off items rows. and finally, press the "Add Bridge Device" button.

merlin051 commented 7 years ago

What do the 433mhz playback files look like?

I can't get mine to record the signal for the boiler so looking at an arduino to record and playback on the Broadlink, I just need to get it in right format..

tyjtyj commented 7 years ago

There is already java api for broadlink

just need some java expert for integration

https://github.com/mob41/broadlink-java-api

Matt8119 commented 7 years ago

that would be awesome to have "one" bridge. it looks very promising! this is just way over my head... i wouldn't mind testing it when its almost ready.

merlin051 commented 7 years ago

What do the 433mhz playback files look like?

I can't get mine to record the signal for the boiler so looking at an arduino to record and playback on the Broadlink, I just need to get it in right format..

ghost commented 7 years ago

Guys, I have had this working with ha bridge ages ago and it works flawlessly with Alexa. And it's much simpler. Just install jeedom server. Log in and get broad link plugin. Then make sure advanced mode or something's on. Go in the plugon, register the code and copy the command URL. Then add that in manual add in ha bridge. If you want a more detailed instructions just ask! Hope this helps PS use chrome with its built in translator to translate French jeedom into English Jev

darth-hp commented 7 years ago

The amazing thing about HA-Bridge is it's simplicity. I had a look at most of the current HA solutions and I still don't have a use case that HA-Bridge cannot cover.

Matt8119 commented 7 years ago

@jevtheboss ive found the french site with the jeedom server info, but the directions show doing it from scratch. can this run on the same PI that the ha bridge is running on?

ghost commented 7 years ago

@Matt8119 Yes unfortunately. You can use it on the same pi the ha bridge is on, but the easiest way is to start from scratch, get the jeedom pi image, flash iT and it will setup MySQL and jedom and everything. You can then install ha bridge. I believe you can install it without flashing the image but it's a lot harder, the jeedom image automatically does a load of pre built scripts on first boot. Just flash it, plug it in to ether net, turn it on , go to its IP address on your computer and watch the magic happen! It takes a while though😠 just be patient Jev

Matt8119 commented 7 years ago

@jevtheboss i was watching a few jeedom videos on youtube concerning plugins. now i guess my question is; is the plugin for the broadlink self contained, meaning it has its own discover button, and settings? also one last question, when after i activate the plugin, in the video i watched they used an RFXCOM as an example. he selected the port to use it on, now the broadlink plugin isnt using a physical port, what do you point it to?

alzzy commented 7 years ago

I would also like to see HA-Bridge fully support the BroadlinkRM Pro and eliminate the need for an Android device to run RM bridge.

ghost commented 7 years ago

@Matt8119 yes it is self contained. No need for an Android device! Anyway, I not sure what you mean about the port thing but you just put the plugin in discovery mode and it finds the broad link. Click it and press learn a code. Use rm or rf . Then press the settings cog and then right click and copy the URL that's there. Also, I had to assign a static IP from my router to my broadlink as it kept giving it a different IP and so heeding couldn't find it. I'll do a guide when I get round to it of you want Thanks Jev

Matt8119 commented 7 years ago

@jevtheboss I'll be sure to remember those things! It's seems quite straight forward with a friendly UI compared to command prompts. A tutorial wouldn't hurt! When you get the chance.. thanks!

Matt

darth-hp commented 7 years ago

What a pain ... I was searching for the plugin on github but wasn't able to find anything. So I installed Jeedom using docker which was quite simple and straight forward as described in the docs.

When switching the UI to any other language nothing happend. So I had to use a translator ... uhm. Indeed the plugin is available in the store but also this is only french. I had a look at the code - it has a Python based daemon to communicate with the Broadlink and a mixture of PHP/JS for the web-parts.

Since the plugin is delivered under the GNU v2 license it could be re-used for other projects as well. I pushed the current version to github to start playing with it once I have the RM pro.

UPDATE: The plugin is available here - no idea why wasn't able to find it

bwssytems commented 7 years ago

@tyjtyj Unfortunately, that java library is incomplete. Commands are not yet defined.

ghost commented 7 years ago

Ok Guys and @Matt8119 So this is what I did to use my broadlink with HA bridge. I figured this out (it took me ages) and requires some patience and common sense. THIS METHOD DOES NOT REQUIRE AN ANDROID DEVICE I ran all this on the very first model raspberry pi (very old but works fine)but i assume you could use this on any Anyway,

  1. Download the jeedom iso here. Click the one that has the words raspberry pi in it.
  2. extract it and flash the image onto an sd card using etcher or win32diskimager
  3. plug it into ethernet (you can set it up for wifi later but theres a delay when using commands with Alexa) and then plug in the power
  4. Find the ip adress of the pi and go to it in aweb browser
  5. You should see a whole setup-download script happening, it takes about an hour so sit back and have a coffee
  6. Then eventually you'll see a jeedom login page. At this point you want to set your raspberry pi with a static ip adress. If you dont know how go here
  7. Also, you need to assign a static ip adress to the broadlink as many routers change ip adresses for connected things on reboot, and then you would need to manually change it in the jeedom settings so it can talk to the broadlink. This varies between routers but look for something like DHCP Reservation as you cant set a static ip in the broadlink app as far as I know.
  8. Then load up the new static ip of the rpi (preferably in chrome because it has built in translation) and login with admin as username and password
  9. also, you cant change the language of the jeedom for some reason
  10. Then you want to press the person icon in the top right and tick mode expert or expert mode
  11. reboot your pi using putty. The shh username is root and password is Mjeedom96
  12. Then press the settings cog and press configuration (top one)
  13. Then press network configuration and type in the ip adress of your pi and port 80 in the field internel access and external access.
  14. Scroll down and press save.
  15. Then press plugins -> plugin magagement and press the cart
  16. search for broadlink and press install
  17. Then go into plugins > plugin management again and press broadlink.
  18. I dont remember exactly but press a button that says something like download or activate or something and wait for that to finish. It should say status ok and configuration ok
  19. then press plugins -> protocole domotiqe and then broadlink
  20. click mode inclusion. Wait a while and your broadlink device should appear under Mes équipements broadlink or my broadlink equipment
  21. Click on it and press learning an order
  22. Point your ir or rf remote at it and press it once and it should detectet it. If not try a few methods. Then you should be redirected to a page. Under the name column, the box opposite icon, give a name for the code it just learned. Press save.
  23. At this point, install, ha bridge using putty username is root and password is Mjeedom96. I had a few tries to get it working. Also, add it to startup script so ha bridge automaticly starts every boot (here) and make sure you set it to start on a different port ( i use 8080)
  24. Go back to the command grid and press test to see if its working. if it isnt, learn the code again
  25. If it is, press the cog and right click where it says url and copy the link adress.
  26. Go to your ip adress and : then the port you set for ha bridge
  27. Press Add/Edit
  28. Type a name for the device you are controlling, and in device type, select custom
  29. Then go to on items. Paste the link to turn on the device in target item. If you want it to execute multiple commands, press add at the end and paste another url and for some reason, you need to press add and leave a blank entry under your others and make the delay 1000 for your second command
  30. repeat for the off commands and scroll backup and press add bridge device.
  31. Now just say alexa, discover devices and it should say its found 1 smart home device.
  32. Now say alexa, turn on/off (device name) and it should do it!
  33. Sucess 👍 Hope this helps, Any questions, just ask Jev
Matt8119 commented 7 years ago

@jevtheboss perfect, these are extremely detailed!!! i already went ahead and ordered a second PI3 from modmypi.com in the UK just so if i run into any issues on my main PI that the Ha-bridge is running on, incase of any issues i may run into or just format the SD card if need be... not sure if you have yours up and running yet, but could you post a few examples of what your commands look like?

much appreciated!

matt

darth-hp commented 7 years ago

I used this https://github.com/davorf/BlackBeanControl which is a much lighter approach

Matt8119 commented 7 years ago

I read the readme.File and didn't see anything about the discovery process... Do you have any experience using it?

darth-hp commented 7 years ago

All of the groundwork is done using https://github.com/mjg59/python-broadlink - can already be installed using pip install broadlink. Getting your devices ... yeah, that part is missing from the BlackBeanControl.

You can use search-bl.sh listed here https://wiki.fhem.de/wiki/Broadlink - of course you could use all the scripts there but the BlackBeanControl is more user friendly.

Extracting existing codes also works using this https://github.com/NightRang3r/Broadlink-e-control-db-dump

Matt8119 commented 7 years ago

Having to install four different java files, On top of all the separate command line needed, seems a bit much just to control an ir/rf plug etc... I appreciate the input, but I'll stick with jeedom. Being, it's one program with only a separate plugin and the UI is just way more friendly vs all those command lines id need and jumping back and forth between Java files. I can just see something going wrong and not knowing how to remedy it, without to just start all over again....