davorf / BlackBeanControl

BlackBeanControl - Broadlink RM 3 Mini (aka Black Bean) control script
230 stars 55 forks source link

Trying to reuse BlackBeanControl.ini #10

Closed ChopOMatic closed 7 years ago

ChopOMatic commented 7 years ago

I initially set this up on an RPi3 and got everything rolling. I decided to move it to my Mac instead, for easier execution from my home automation software.

Setup went without a problem into a virtualenv environment. Since I'm using the same RM3 and it's still on the LAN, I copied the BlackBeanControl.ini file over from the Pi since I had already set up everything, including a bunch of commands. Here's what I'm getting:

BlackBean) MacMini:BlackBeanControl Me$ python BlackBeanControl.py -c SignalTreeMainBulbsBlue -d RM3SignalTree
Traceback (most recent call last):
  File "BlackBeanControl.py", line 166, in <module>
    AESEncryption = AES.new(str(RM3Key), AES.MODE_CBC, str(RM3IV))
  File "/Users/Me/MyVenv/BlackBean/lib/python3.5/site-packages/Crypto/Cipher/AES.py", line 95, in new
    return AESCipher(key, *args, **kwargs)
  File "/Users/Me/MyVenv/BlackBean/lib/python3.5/site-packages/Crypto/Cipher/AES.py", line 59, in __init__
    blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
  File "/Users/Me/MyVenv/BlackBean/lib/python3.5/site-packages/Crypto/Cipher/blockalgo.py", line 141, in __init__
    self._cipher = factory.new(key, *args, **kwargs)
ValueError: IV must be 16 bytes long

PyCrypto issue?

davorf commented 7 years ago

Hello!

I don't think it's a PyCrypto issue. Are you using the same broadlink-python package you used on RPi3, or you've downloaded it again in virtualenv? There were some changes recently in the broadlink-python package that could cause this issue. I haven't analyzed it thoroughly, but I'm pretty sure that's the reason you're getting this error. There is a pull request waiting, which will introduce somewhat changed mechanism of code saving and encoding/decoding, and it should solve this issue too (since this new mechanism would not decrypt codes before saving). I hope I'll have some free time tonight or tomorrow to review and accept this pull request. I'll post an info here, after it's done.

Best regards, Davor

ChopOMatic commented 7 years ago

Thanks, Davor. And yes, I did a git clone of the latest broadlink-python build into the virtualenv.

davorf commented 7 years ago

Hello!

I've merged a pull request that should fix the problem you've had. I would appreciate if you could test if it's working now.

Best regards, Davor

ChopOMatic commented 7 years ago

Here's what I'm getting now, Davor:

(Broadlink) MacMini:BlackBeanControl Me$ python BlackBeanControl.py -c SignalTreeMainBulbsGreen -d RM3SignalTree
Traceback (most recent call last):
  File "BlackBeanControl.py", line 192, in <module>
    DecodedCommand = CommandFromSettings.decode('hex')
AttributeError: 'str' object has no attribute 'decode'
walkention commented 7 years ago

ChopOMatic,

The new update requires you to use the -r command to re-key the saved codes from their old format to the new format. For example:

python BlackBeanControl.py -r SignalTreeMainBulbsGreen -d RM3SignalTree

However it looks like you were having an issue with the commands beforehand so the re-key may not work. You should be able to relearn the commands without issue or attempt to the re-key of the codes on the R-Pi and move the updated BlackBeanControl.ini to the Mac.

Aydaen

davorf commented 7 years ago

Hello!

I'm not sure if it's a problem with an old command format, because an error message says there's no attribute decode.

@ChopOMatic: What version of Python you have? It looks like it could be related to Python 2 and Python 3 differences. This script should be used with Python 2.7.

Best regards, Davor

ChopOMatic commented 7 years ago

Davor, I recreated the virtualenv, this time to use Python 2.7 instead of 3.5. Tried the -r option specified by Aydaen and got it to work a time or two but it kept throwing errors. I decided to start over with a fresh .ini file so I just reset the RM3. The only thing I put in the new .ini file were the device configs (using the actual IP and MAC, of course):

[General]
IPAddress = x.x.x.x
Port = 80
MACAddress = xx:xx:xx:xx:xx:xx
Timeout = 10

[RM3SignalTree]
IPAddress = x.x.x.x
Port = 80
MACAddress = b4:43:0d:e4:15:c1
Timeout = 10

When I issue the command, it appears to go into learning mode. If I don't send the signal from the remote to the RM3 during the 10-second window, I get a message saying "command not received."

When I do send the signal from the remote to the RM3 during the 10-second window, I get the code below, and no command is written to the .ini file:

(Broadlink) MacMini:BlackBeanControl ChopOMatic$ python BlackBeanControl.py -c SignalTreeMainBulbsRed -d RM3SignalTree
Traceback (most recent call last):
  File "BlackBeanControl.py", line 203, in <module>
    EncodedCommand = LearnedCommand.encoded('hex')
AttributeError: 'str' object has no attribute 'encoded'
davorf commented 7 years ago

Hello!

I've merged a pull request that fixes misspelled encode attribute. Please try if it works with a latest version.

Best regards, Davor

ChopOMatic commented 7 years ago

PERFECT. Thx, Davor!

davorf commented 7 years ago

Hello!

It's actually @walkention code that made BlackBeanControl compatible with the new version of broadlink-python package. Regarding Re-Key error, I'll try to debug and fix it as soon as I can.

Best regards, Davor

ChopOMatic commented 7 years ago

Thanks, @walkention !

walkention commented 7 years ago

No problem, @ChopOMatic. Sorry to get confused as to what was going on with the issue, but it sounds like it might be solved.

@davorf let me know if you need help debugging the Re-Keying issue.

ChopOMatic commented 7 years ago

While not related to this issue, huge thanks in general to all you guys working on this. I've been using Global Cache WF2IR devices to do exactly this for years. It's wonderful to have a $15 device that is perfectly replicating not all, but most, of the functionality of a $120 device. It's practical to deploy RM3s all over the house; not so much for the GC devices because of cost.

walkention commented 7 years ago

@ChopOMatic I looked at the Global Cache device on Amazon for a while before deciding to just buy the RM3 and try to see if I could cobble something together. I figured for $20 I would at least have something to fiddle with and I wouldn't be out that much. I've been impressed with what people in the community have reverse engineered and I'm glad I grabbed one.

ChopOMatic commented 7 years ago

The one big advantage to the GC devices is the fact that they provide three separate IR outputs that can be routed precisely where you want them. Sometimes that's needed, like when you have a big stack of AV gear. But for general stuff, the RM3 rocks. I have a number of lighted, color-controllable pieces of "art" I've gotten as gifts and such. (From people who know I'm obsessed with color and light, LOL.) With the RM3, I can tie these into my home automation software and have them do really cool things. I'm excited and grateful.

davorf commented 7 years ago

Hello!

Sorry for a late reply, but I haven't had any free time to look into this. I've tried re-key command with lots of previously learned commands, and it works without throwing any exception. I'll close this issue now, but if you find any other problem, feel free to open a new issue.

Best regards, Davor

ChopOMatic commented 7 years ago

No prob!