BroadLink Mark II plugin

I removed the block comment, with the same result. Then removed the action list tag and received the same error.

2018-04-17 16:48:19.106 openLuup.http:: GET /data_request?id=action&output_format=json&DeviceNum=0&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=CreateDevice&Description=Broadlink&UpnpDevFilename=D_BroadLink_Mk2_1.xml&UpnpImplFilename=I_BroadLink_Mk2_1.xml&RoomNum=0&Reload=1 HTTP/1.1 tcp{client}: 0x1007ceb8 2018-04-17 16:48:19.108 luup.call_action:: 0.urn:micasaverde-com:serviceId:HomeAutomationGateway1.CreateDevice 2018-04-17 16:48:19.113 luup.create_device:: ERROR [76] D_BroadLink_Mk2_1.xml / I_BroadLink_Mk2_1.xml / : ./openLuup/loader.lua:330: bad argument #1 to 'ipairs' (table expected, got string)

I don’t see any other errors in my logs, and I have loaded several other plugins manually without a problem so I don’t think it’s related to my openluup installation.

I knew it wasn’t the block comment itself - it’s one of the things explicitly tested in my openLuup unit testsfor the XML reader.

I’ll take a look at the plugin code on GitHub. It looks as though I don’t need the actual hardware to see this error.

What device and implementation files are you using when you create the device?

Had a look at this to-day.

First trick is that openLuup caches files it reads with a routine called: memoize() in loader.lua. This means that if you change a service file before attempting to install a related plugin, you must restart the openLuup engine before attempting to create the plugin with the modified service file.

A couple of observations:

This is OK:

<actionList><action></action><action></action></actionList>

but causes an error:

<actionList><action></action></actionList>

There is some problem with empty tags or tags that contain no ‘child’ tags being searched for when there is a single ‘parent’ tag. Just white space, or missing child tag or completely empty is allowed between tags but in this case needs to be ignored.

Re: the BroadLink plugin remove:

.... <actionList> <action> <!-- <name>Test</name> <argumentList> <argument> <name>Var1</name> <direction>in</direction> <relatedStateVariable>A_ARG_TYPE_Var1</relatedStateVariable> </argument> <argument> <name>Var2</name> <direction>in</direction> <relatedStateVariable>A_ARG_TYPE_Var2</relatedStateVariable> </argument> </argumentList> --> </action> </actionList> ....

but be absolutely sure to restart the openLuup engine before attempting to create the plugin.

Yes, this is certainly the case. The caching significantly improves startup performance and reduces disk I/O for frequently read service and device files. Lua files are not cached, since they’re almost always uniquely read once, and in fact, are the most likely ones to be changed during development.

ALWAYS reload if you hack the device files of already-loaded devices.

A couple of observations:

This is OK:

<actionList><action></action><action></action></actionList>

but causes an error:

<actionList><action></action></actionList>

There is some problem with empty tags or tags that contain no ‘child’ tags being searched for when there is a single ‘parent’ tag. Just white space, or missing child tag or completely empty is allowed between tags but in this case needs to be ignored.

Interesting, thanks. I’ll extend the unit tests to catch this, then fix it. It’s a bit of a strange one.

Re: the BroadLink plugin remove: [code].... .... [/code]

but be absolutely sure to restart the openLuup engine before attempting to create the plugin.

Absolutely!

Yes, was able to create the plugin with a luup restart after deleting the block quote and the tag. Logs show that the plugin is communicating with my RM mini.

Hi, I’ve install this plug in, it discovered my broadlink, I’ve create a device but I don’t know how to use it… I don’t understand very well the first post…need more help and a little more step… Need to record IR code and know how to send it… please can you help me to understand?

[quote=“a-lurker, post:63, topic:198239”]A couple of observations:

This is OK:

<actionList><action></action><action></action></actionList>

but causes an error:

<actionList><action></action></actionList>

There is some problem with empty tags or tags that contain no ‘child’ tags being searched for when there is a single ‘parent’ tag. Just white space, or missing child tag or completely empty is allowed between tags but in this case needs to be ignored.[/quote]

Thanks for that further investigation. The problem is now fixed in development branch 2018.04.23, and my unit tests updated to check for this.

Sorry for the inconvenience.

mmmm…so… I understand that there are some problem…
…PLEASE… for days I try to work with broadlink rm pro + don’t using the e-control app…
…I need automation…please explain me how to correctly install and use this feature…

EDIT: I use standard UI7 interface… I’ve just tryed ALtui…but I prefer standard UI…
the broadlink RM is recognized but nothing happen when I send code (taked from zip file in e-control app)…just respond ok, ok…no led blinking…

just need to create a device like remote tv, remote samsung cleaner…in order to add some action to some scene…

@stardobas please post zip file and the log output when you try to send a code.

Here’s the zip file that downloads from an Android phone using http://<PHONE_ip_address>:48815 (e-control app). The codes are IR only for a RM mini. One controlled device–a TV, and I stripped out the account specific info. Is there any way to import the json directly from the appcode json file? There is not much in the way of description in the JSON so it’s difficult to tell what is what.

Hi - haven’t tried your plugin yet, but just fyi here’s a file with my codes in it. The first remote is for an IR clock radio (on and off) and the other is for a 433Mhz “Heat & Glo” fireplace remote (on, off, up, down).

Cheers

@ninkasi The json codes are in decimal. Any negative numbers first need to be converted like so:

posDecNumber = 256+(negNumber) eg 256+(-78) = 178dec = 0xb2

Then numbers need to be converted to hex. I end up for your heater codes the following - one code per line.

Edit: also see post further down with code to do this:
http://forum.micasaverde.com/index.php/topic,53871.msg380629.html#msg380629

b2 06 1c 00 0c 0e 0f 1a 1b 0f 0f 1a 0f 1a 0f 1a 0f 1a 0f 1a 0f 1a 0f 1b 1a 0f 1b 0f 1b 00 02 5d 00 00 00 00 00 00 00 00 00 00 00 00 b2 0f 1c 00 0c 0f 0f 1a 1b 0f 0f 1a 0f 1a 0f 1a 0f 1a 0f 1a 0f 1a 0f 1a 0f 1a 1b 0f 1b 00 02 5c 00 00 00 00 00 00 00 00 00 00 00 00 b2 0b 1c 00 0d 0e 0f 1a 1b 0f 0f 1b 0f 1b 0f 1a 10 1a 0f 1b 0f 1a 1b 0f 10 1b 1a 0f 1b 00 02 5d 00 00 00 00 00 00 00 00 00 00 00 00 b2 07 1c 00 0d 0f 10 1a 1b 0f 10 1b 0f 1b 10 1a 10 1a 0f 1b 11 1a 1b 0f 1b 10 0f 1b 1b 00 02 5c 00 00 00 00 00 00 00 00 00 00 00 00

I’m unsure which does what to your heater. Give them a try out to see what happens.

The IR codes are extremely long suggesting they contain many repeats of the base code.

Edit: as per the next post also refer to:
http://forum.micasaverde.com/index.php/topic,52019.msg380440.html#msg380440

[quote=“a-lurker, post:72, topic:198239”]@ninkasi The json codes are in decimal. Any negative numbers first need to be converted like so:

posDecNumber = 256+(negNumber) eg 256+(-78) = 178dec = 0xb2

I’m unsure which does what to you heater. Give them a try out to see what happens.[/quote]

Thanks @a-lurker → I should have mentioned I had already converted them via GitHub - NightRang3r/Broadlink-e-control-db-dump: These two scripts will "parse" the broadlink e-Control Android application database or SharedData and dump the IR / RF codes for selected accessories into a text file which can be later used with broadlink-python to send the codes to the RM PRO hub. The first code is “off”, the second is “on”, the third “up”, the last one “down”. Just thought you might be interested to see what a handful of 433 RF codes looked like :wink:

Cheers

Just in general to extract codes - the e-control codes need to be converted from decimal to hex:

Get the e-control zip file from http://<PHONE_ip_address>:48815 extract and then open the file: SharedData/jsonIrCode and paste into https://jsonlint.com/ to pretty print. For each code, place into the decTab table variable in the code below. Be careful to ensure the start/ends are braces, not brackets. Run code in the AltUI “Lua Code Test”. e-control code is translated to suit the plugin (hopefully).

local function decIR2Hex()
    -- a sample RF code
    local decTab = {-78,  6, 28, 0, 12, 14, 15, 26, 27, 15, 15, 26, 15, 26, 15, 26, 15, 26, 15, 26, 15, 26, 15, 27, 26, 15, 27, 15, 27, 0, 2, 93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

    local hexTab = {}
    
    for _,v in ipairs(decTab) do
        -- handle negative values: eg 433MHz leadin code is 0xb2 ie 178dec, In the e-control json, it is -78dec. So 256+(-78) = 178dec = 0xb2
        if (v < 0) then v = 256 + v end
        table.insert(hexTab, string.format('%02x', v))
    end

    print(table.concat(hexTab,' '))
end

decIR2Hex()

return true

I LOVE YOUUUUUU finally I WINNNNN IT WORKKKKKKKKKKKKKKKKKK LOVING YOUUUUUUUU ;D ;D ;D ;D ;D ;D ;D

My set of codes worked as well. Thank you!

please I have two question…

  1. I would like to buy another 3 rm mini to use in other room… How I can create a different device for its?
  2. I’m able to create a scene for sending code…but is possible to create a remote commander like tv remote or roomba remote or air condition remote (all ir) with all button on it? just for more confortable display…I wan’t control it like a switch (multi switch) and not like a scene…

very thank you for your work

  1. if you get more BroadLink devices; you just plug them in and restart the Luup engine. The plugin will (mostly!) find the new devices and create IR children for each one.

  2. hand crafting a complete virtual remote gets tricky and is a separate issue. A long time ago I made a plugin where you used the PC mouse, to click on an image of the remote. It needs good Lua and IR code skills to alter to suit anything else. Probably not overly useful.

http://forum.micasaverde.com/index.php/topic,13418.0

Others may want to comment on what they have done. In my case I’m mainly interested in using just the IR off/on commands.

Got it working - the auto discovery was not working for me (most likely udp was being blocked between the switch my vera is plugged into and the wifi ap the broadlink was connected to)?. filtering out all the other things I did whilst experimenting, what I did:

#1 Downloaded the files off GitHub
#2 Uploaded them onto the Vera (apps/develop apps/luup files/upload)
#3 Created a device (apps/develop apps/create device) - just need to fill in two fields namely Upnp Device Filename: D_BroadLink_Mk2_1.xml and Upnp Implementation Filename: I_BroadLink_Mk2_1.xml (no need to fill in anything else)
#4 Restart luup (apps/develop apps/Test Luup code) and run the code luup.reload()
#5 You should find in devices (order by room) the new device ?Broadlink Mk2? appear. With luck you should also find some child devices such as ?RM2 Pro Plus 2 - temperature 1? appear. Be patient. It might take a while and/or require restarting luup again. For me though nothing ever appeared so I had to go the next step
#6 Go into Broadlink Mk2 device, advanced, variables and in the variable named ?BroadLinkDevices? I put in:

{ "[b]b4:43:0d:fc:1e:c9[/b]": { "blInternalId": "00000004", "blKey": "20c2e92c20c2e92c5635601c8da8d60b", "blDeviceType": 10119, "blIp": "[b]192.168.0.150[/b]", "blDesc": "RM2 Pro Plus 2" } }

Where ?b4:43:0d:fc:1e:c9? is the mac address of my RM Pro (you can get that from the e-Control app) and ?192.168.0.150? is the IP address. Change to suit your device.
#7 Restart luup again and hopefully the child devices will start to appear and you can then send commands from Vera!

Big thanks @a-lurker. This is great!

[quote=“a-lurker, post:78, topic:198239”]1) if you get more BroadLink devices; you just plug them in and restart the Luup engine. The plugin will (mostly!) find the new devices and create IR children for each one.

  1. hand crafting a complete virtual remote gets tricky and is a separate issue. A long time ago I made a plugin where you used the PC mouse, to click on an image of the remote. It needs good Lua and IR code skills to alter to suit anything else. Probably not overly useful.

http://forum.micasaverde.com/index.php/topic,13418.0

Others may want to comment on what they have done. In my case I’m mainly interested in using just the IR off/on commands.[/quote]

thank you, for me autodiscovery worked very well, only temperature is not showed (report 0?C )but I’m not interested on it… very good work! Now is time to automation :slight_smile: