Author Topic: BroadLink Mark II plugin  (Read 9931 times)

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 858
  • Karma: +63/-8
BroadLink Mark II plugin
« on: January 09, 2018, 08:25:59 pm »
A BroadLink Mark II plugin to try out.

The code can be found on GitHub here:

      https://github.com/a-lurker

You can install the plugin from the 'Alternate App Store' (once I set it up), which works together with the 'ALTUI' plugin.

      http://forum.micasaverde.com/index.php/topic,38102.0.html

Note that 'ALTUI' is highly recommended to all users, together with openLuup.

Caveats:
Only tested on the RM3 Pro 2 device. While other devices may be discovered, they might not work. This plugin is based on information from here:

https://github.com/mjg59/python-broadlink
https://blog.ipsumdomus.com/broadlink-smart-home-devices-complete-protocol-hack-bc0b4b397af1
https://github.com/sayzard/BroadLinkESP/blob/master/BroadLinkESP.cpp

The reverse engineering is ongoing. Consequently it may not be possible to have all functionality operational until that process is complete.

If the LED on your device flashes when you transmit a code, the plugin is working. It's a different matter whether you have the correct code or not. Many learnt codes have excessive replication and some codes are not replicated enough. ie some TVs, etc require a code to be sent two or three time, in close succession, for them to work. I propose not to engage in discussions on why your codes work or not. See this link instead:

www.remotecentral.com

Logging can be enabled by setting the DebugEnabled flag to '1'. You can use AltUI plugin to look at the log file:

See Misc-->Os Command--> Tail Logs Tab   Note: you can change the 50 to say 500 to see more log info.

In openLuup use the console logs:

http://<openLuup_ip_address>:3480/console?page=log

Or use the infoviewer plugin. Please provide a log file with any bug reports, otherwise the report may not be responded to.

What the plugin will do:
1) BroadLink and ProntoCodes can be used.

2) The one instance of the plugin can (in theory) handle multiple BroadLink physical  devices. The plugin will produce child devices as necessary, based on the capabilities of each BroadLink device discovered. eg a Broadlink Rm Pro will have a temperature and IR child device  associated with it.

3) BroadLink WiFi operated switches such as the SP1 & SP2 & SC1 should work but the MP1 may need work - I haven't been able to test this.

What the plugin will not do:
1) Wall switches operated locally will provide on/off status but the update period in the UI will be long (minutes) ie not instant status
2) The plugin does not interact with the "e-Control" phone app in any way. However e-control codes can be converted for use with the plugin - refer to:
    http://forum.micasaverde.com/index.php/topic,53871.msg380629.html#msg380629
3) The plugin doesn't store IR or RF codes - codes need to be applied to the IR child.


Potential problems:
1) RF codes may or may not work. Haven't tried it.

2) Getting codes:  As I understand it you can download codes held by the "e-Control" app  ie: in the file eControl-data.zip I haven't tried this. Presumably the "e-Control" app needs to be running on the phone and you get the codes by entering in your browser this link - note: insert the phone's ip address:

http://<PHONE_ip_address>:48815"

If some one can post the file proffered, that would be good, as I would like to review its contents - especially any file containing codes for 315 MHz, as well as 433 MHz, as I haven't be able to check RF code functionality.

3) Your router blocks UDP broadcast traffic - that will cause problems - read your router manual!

4) The BroadLink devices are identified by their MAC addresses. If you change the IP address of a BroadLink device for any reason, you need to restart the Luup engine. The new ip address will be discovered and used.

5) After a Vera Luup engine restart, there is 85 second delay before the plugin starts polling, then it polls at minimum of every five minutes. So temperatures, etc are updated at this rate.

6) Some BroadLink devices can control remote devices on 315 MHz, as well as 433 MHz. Some just allow 433 MHz (country based). The box the unit is delivered in, says what it contains. I'm unsure how this can be detected programmatically.


Usage:
Sending a ProntoCode:
luup.call_action('urn:a-lurker-com:serviceId:IrTransmitter1', 'SendProntoCode', {ProntoCode = 'your code here'}, DeviceID)

Sending a BroadLink IR or RF code:
luup.call_action('urn:a-lurker-com:serviceId:IrTransmitter1', 'SendCode', {Code = 'your code here'}, DeviceID)

Using AltUI;  codes can be cut & pasted into the actions for easy testing.

This post provides an understanding how the IR devices should be used (using a GC100 device):
http://forum.micasaverde.com/index.php/topic,29685.msg234078.html#msg234078


Ver 0.51
Initial release.

This plugin has been tested using the AltUI plugin and the Vera UI7 interface with Firefox 57.0.2. It works with openLuup and on a Vera 3. UI5 may work.

Ver 0.52
The plugin can now learn codes. It works pretty well for IR codes but is a bit suspect when learning RF codes. To start the learning process issue these commands to the appropriate child device (not the parent):

luup.call_action('urn:a-lurker-com:serviceId:IrTransmitter1', 'LearnIRCode', {}, DeviceID)

luup.call_action('urn:a-lurker-com:serviceId:IrTransmitter1', 'LearnRFCode', {}, DeviceID)

The LED will light up on the BroadLink device and you have about 30 seconds to learn the code. For IR codes just tap the remote button. For RF codes it's more complicated. Once learning starts hold the remote button down for about four seconds (this gets the frequency). Wait a second and then tap the remote button (this gets the code). This sequence is not easy to do and codes may not be learnt or may be incorrect.

The parent device (not the child device) reports the learnt codes in "LearntIRCode" and "LearntRFCode" as seen under the variables tab. If a code is not learnt then the variable reports "No IR code was learnt" ditto for RF codes.

Ver 0.53
General bug fixes and support for BroadLink WiFi switches. If your switch doesn't work then provide logs. The MP1 four switch may need more work - provide logs.

Note RF code learning is a work in progress and may not function as desired.

Ver 0.54
Note: a JSON module is now required to be available to the plugin. This will mostly effect UI5 users as UI7 has one already available. If one is not found, you will be notified in the UI top banner at Luup engine start up. Refer to this post for a suitable module:

http://forum.micasaverde.com/index.php?topic=29989.0

Fixes a bug whereby if a device was offline and a Luup Engine restart occurred and subsequently the device went on line and another Luup Engine restart occurred; then the device's children would be deleted then recreated with new device IDs.

Measured temperatures can now have an offset applied. It's a crude approach to correction but may help those interested. In general expecting sub one degree Centigrade accuracy (or even two degree) from the BroadLink Pro(s) is probably overly optimistic.

Also misc general bug fixes.

Existing users just need to upload the "L_BroadLink_Mk2_1.lua" attached immediately below.
« Last Edit: April 25, 2018, 06:18:16 am by a-lurker »

Offline zedrally

  • Hero Member
  • *****
  • Posts: 1122
  • Karma: +11/-5
  • Black Cat Control Systems
Re: BroadLink Mark II plugin
« Reply #1 on: January 09, 2018, 09:19:49 pm »
Thanks a-lurker for doing this, it will get a lot of people out of a hole that they have been stranded in.


I'll trial it with a spare RMPro2 and report back, although I don't use Alt UI, I hoping that it will use UI7?
Living in the Land of Oz, give me a vegemite sandwich. Home Seer, Vera Lite & Edge, Popp, Black Cat Smart Hub & Vera G, Black Cat Lite 1 & 2's a Black Cat Dimmer or 2, Fantem Tec and then some  Black Cat Cat's Eye PIR's & Door-Window Sensors, RFXComm, Broadlink RMPro & Mini plus a Z-UNO or 2.

Offline damverda

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: BroadLink Mark II plugin
« Reply #2 on: January 26, 2018, 12:15:49 pm »
Thanks a-lurker this is really amazing.  I'm using an RM Mini3 and it appears your scripts found it and labeled it "RM Mini - IR 1", but when I go to Actions and send a code I don't see the light on the device.  Was their a step I missed in setup that would cause this to happened?  I did not pair it using your scripts as it was already on the network my Vera is on.  Thanks for any help you can provide.

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 858
  • Karma: +63/-8
Re: BroadLink Mark II plugin
« Reply #3 on: January 27, 2018, 01:33:19 am »
Quote
Was their a step I missed in setup that would cause this to happened?
All sounds OK to me. Post the IR code you are trying to send and I'll try it out here. And the debugging in the log is always worth a look.
« Last Edit: January 27, 2018, 01:55:47 am by a-lurker »

Offline PrincessCleavage

  • Sr. Member
  • ****
  • Posts: 260
  • Karma: +4/-1
Re: BroadLink Mark II plugin
« Reply #4 on: January 27, 2018, 10:56:22 pm »
Maybe a silly question but can the new broad link units control 433mhz units (blind motor)?

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 858
  • Karma: +63/-8
Re: BroadLink Mark II plugin
« Reply #5 on: January 28, 2018, 01:30:48 am »
Quote
can the new broad link units control 433mhz units (blind motor)?

Don't know for sure but it seems very likely. Given the Broadlink device is so inexpensive and if it didn't work for your blinds; you would still have an IR transmitter you could use. Give it a try?

I see also that some Dooya products support the Broadlink protocol directly:

https://github.com/mjg59/python-broadlink/commit/82172f54ab722fb9de998d0ae4c24337e41d5787
« Last Edit: January 28, 2018, 01:38:02 am by a-lurker »

Offline zedrally

  • Hero Member
  • *****
  • Posts: 1122
  • Karma: +11/-5
  • Black Cat Control Systems
Re: BroadLink Mark II plugin
« Reply #6 on: January 28, 2018, 01:33:14 am »

This may answer the question, copied from the below thread which has now been locked.
Re: PLUGIN: Broadlink RM Interface
? Reply #141 on: 29 December 2017, 05:50:49 ?


i have used the pluging with RF devices and works very well, in case of the RF, you need to import the devices from the e-Control APP.

in order broadlink learn a RF you need to go to "user-defined" then go to Sweap Frequency option




Living in the Land of Oz, give me a vegemite sandwich. Home Seer, Vera Lite & Edge, Popp, Black Cat Smart Hub & Vera G, Black Cat Lite 1 & 2's a Black Cat Dimmer or 2, Fantem Tec and then some  Black Cat Cat's Eye PIR's & Door-Window Sensors, RFXComm, Broadlink RMPro & Mini plus a Z-UNO or 2.

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 858
  • Karma: +63/-8
Re: BroadLink Mark II plugin
« Reply #7 on: January 28, 2018, 01:37:32 am »
Yes - it looks like the reverse engineering of the RF learn process needs more work. Hence the need to get them from e-control.

On the plus side; I now have the MK2 plugin learning IR codes. Code will be in version 0.52 (not on GitHub yet).

Quote
2) Getting codes:  As I understand it you can down load codes held by the "e-Control" app  ie: in the file eControl-data.zip I haven't tried this. Presumably the "e-Control" app needs to be running on the phone and you get the codes by entering in your browser this link - note: insert the phone's ip address:

http://<PHONE_ip_address>:48815"

If some one can post the file proffered, that would be good, as I would like to review its contents - especially any file containing codes for 315 MHz, as well as 433 MHz, as I haven't be able to check RF code functionality.

Any one got a zip file with RF codes?
« Last Edit: January 28, 2018, 01:39:44 am by a-lurker »

Offline zedrally

  • Hero Member
  • *****
  • Posts: 1122
  • Karma: +11/-5
  • Black Cat Control Systems
Re: BroadLink Mark II plugin
« Reply #8 on: January 28, 2018, 02:02:19 am »
Can your PI run from Vera?
I do have AltUI on a UI5 machine, but have problems on UI7 with the altUI PI and Appstore (get a failure message) so am unable to try it out.



Living in the Land of Oz, give me a vegemite sandwich. Home Seer, Vera Lite & Edge, Popp, Black Cat Smart Hub & Vera G, Black Cat Lite 1 & 2's a Black Cat Dimmer or 2, Fantem Tec and then some  Black Cat Cat's Eye PIR's & Door-Window Sensors, RFXComm, Broadlink RMPro & Mini plus a Z-UNO or 2.

Offline PrincessCleavage

  • Sr. Member
  • ****
  • Posts: 260
  • Karma: +4/-1
Re: BroadLink Mark II plugin
« Reply #9 on: January 28, 2018, 05:16:40 am »
Quote
can the new broad link units control 433mhz units (blind motor)?

Don't know for sure but it seems very likely. Given the Broadlink device is so inexpensive and if it didn't work for your blinds; you would still have an IR transmitter you could use. Give it a try?

I see also that some Dooya products support the Broadlink protocol directly:

https://github.com/mjg59/python-broadlink/commit/82172f54ab722fb9de998d0ae4c24337e41d5787
Thanks for the info,
I wish I had found this flexible device earlier as I have just added 2x global cache flex wifi device at more cost that one of these and a mini:-/ and also just ordered a rfxcom USB unit for 433mhz:-(

Offline stefanradu5

  • Sr. Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
  • Vera Plus UI7
Re: BroadLink Mark II plugin
« Reply #10 on: February 05, 2018, 06:41:42 pm »
Any chance to work with Broadlink SC1  (tcp/udp wifi relay control box) ?

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 858
  • Karma: +63/-8
Re: BroadLink Mark II plugin
« Reply #11 on: February 05, 2018, 10:16:04 pm »
@stefanradu5

I haven't got a SC1, so I can't test it but I think the plugin can be made to work it, given the correct info. At a minimum turn it off and on. Not so sure about reading its status or anything else that it might do.

I haven't been able to find its internal device ID (on the internet that is) but the plugin should be able to determine it. If you install the plugin from the code in GitHub (ver 0.52 that I have just updated to-day. see next post) and with the SC1 running on the LAN:  then once the plugin is installed then:  do a Luup engine restart and in the log you should see:

Code: [Select]
50      02/06/18 13:38:34.757   luup_log:151: BroadLink_Mk2 debug: Initialising plugin: BroadLink_Mk2 <0x2b833680>
50      02/06/18 13:38:34.758   luup_log:151: BroadLink_Mk2 debug: Using: Lua 5.1 <0x2b833680>
50      02/06/18 13:38:34.758   luup_log:151: BroadLink_Mk2 debug: 0.52 --> PluginVersion <0x2b833680>
50      02/06/18 13:38:34.762   luup_log:151: BroadLink_Mk2 debug: xxx.xx.xx.xx <0x2b833680>

50      02/06/18 13:38:34.805   luup_log:151: BroadLink_Mk2 debug: xxx.xx.xx.xx <0x2b833680>
50      02/06/18 13:38:34.807   luup_log:151: BroadLink_Mk2 debug: Rx'ed a discovery response: rxMsg length = 128 <0x2b833680>

128 lines of log here with the Rx'ed message values and then this message:

The BroadLink device at IP address %s and of type 0x%04x is not known to this plugin

I need to know the hex reported in the message above as a starting point. It represents the BroadLink SC1 that is on your LAN. Note the various methods to get access to the log are explained widely in this forum.
« Last Edit: February 06, 2018, 12:02:48 am by a-lurker »

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 858
  • Karma: +63/-8
Re: BroadLink Mark II plugin
« Reply #12 on: February 05, 2018, 10:35:09 pm »
Ver 0.52 - see first post - now allows code learning.

Offline stefanradu5

  • Sr. Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
  • Vera Plus UI7
Re: BroadLink Mark II plugin
« Reply #13 on: February 06, 2018, 04:42:46 am »
I have not fully understand how to install this plugin.
I installed AltUI (with some problems) .. but it works on a modified link (Vera plus)  ..<my_local_ip>/port_3480/...
I installed App Store for AltUI
Updated AltUI and App Store...
Try to search for Broadlink Mark II and didn't find it in app store.
I am beginner with vera...



« Last Edit: February 08, 2018, 04:35:12 am by stefanradu5 »

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 858
  • Karma: +63/-8
Re: BroadLink Mark II plugin
« Reply #14 on: February 07, 2018, 01:50:21 am »
I've not set up the plugin in the 'Alternate App Store' - as noted in my original post. Note that devices can be installed manually by just uploading the files and entering the correct info into the correct boxes. Refer to forum. However I will endeavor to get the plugin into the 'Alternate App Store' asap.