mlfunston / node-red-contrib-broadlink-control

Set of node-red nodes to manage the Broadlink home automation device suite
MIT License
44 stars 24 forks source link

Support new RM4 devices #26

Closed deadly667 closed 4 years ago

deadly667 commented 4 years ago

Still something missing.

@deadly667 Create a PR in your fork pointing to this repo.

Also, the changes in the payload bytes 0x24 and 0x25 should be conditioned by device type, otherwise, the older devices won't work.

if (this.type == 0x5f36) { packet[0x24] = this.type & 0xff; packet[0x25] = this.type >> 8; } else { packet[0x24] = 0x2A; packet[0x25] = 0x27; }

Hm, Im not sure about it. This 24 and 25 bytes are for device type. You used 0x272A device type. Idea was to set "type" default value to 0x272A in RMNode.html:

defaults: {
            folder: { value: "", required: true, validate: RED.validators.regex(/^((?:[A-Z]:)?(?:\/.+$))/) },
            mac: { value: "", required: true, validate: RED.validators.regex(/^([0-9A-Fa-f]{12})$/) },
            host: { value: "", required: true, validate: RED.validators.regex(/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/) },
            type: { value: "272a", required: true, validate: RED.validators.regex(/^([0-9A-Fa-f]{4})$/) }
        },

In that case, older devices will work if they dont change type. Also, if they put their correct device type that will also work.

What do you think about this?

luxarts commented 4 years ago

I tought the same. That 272A seems a bit magic but that's how was done in python-broadlink and it works. I would hard code that 272A value and deploy a test version. If it works, then I would delete the hard coded value and test again. If doesn't work at least you will know where the problem is.

BTW, I don't know how this can be tested in Node-RED. I don't know the development cycle with this tool. Maybe @mlfunston can help us so this can be merged soon in his version.

mlfunston commented 4 years ago

The 272A value is a default for unknown device types. Did the edits work for you on your RM unit? Or do we need to do more edits before merging this?

deadly667 commented 4 years ago

Sending is working. Learning still not. Im fixing it now. Hopes it will be done today.

deadly667 commented 4 years ago

Guys here it is. Everything works. I updated also examples and README. @mlfunston can you please check if still everything works with older devices? I dont have any older.

deadly667 commented 4 years ago

Also one note: dont use "type" for variable name. On node-red it breaks a lot of things :D

luxarts commented 4 years ago

Great work! What are the steps to local test it?

This is what I think:

  1. Clone this repo and checkout to this branch in the machine where the Node-RED server is running.
  2. Go to the node_red folder (usually ~/.node-red)
  3. Run npm install <path_to_the_repo_folder> to link the module to Node-RED's node_modules folder.
  4. Run sudo systemctl restart nodered to restart the server`

Is this correct?

Edit:

Followed the above steps (previously uninstalled the original module from the palette manager). The learn still doesn't work, keeps throwing Broadlink Timeout Received - Closing Device Connection. How did you made it work? I'm using the example flow:

[{"id":"53b968ed.0df8b8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"fbd3d83c.133098","type":"inject","z":"53b968ed.0df8b8","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":250,"y":240,"wires":[["4ea25009.ff6fc"]]},{"id":"82694153.fac35","type":"debug","z":"53b968ed.0df8b8","name":"","active":true,"console":"false","complete":"payload","x":670,"y":240,"wires":[]},{"id":"c86c3d63.e4c5a","type":"RM","z":"53b968ed.0df8b8","name":"","device":"d0041af7.f24d68","action":"_msg_","remote":"","button":"","x":530,"y":240,"wires":[["82694153.fac35"]]},{"id":"4ea25009.ff6fc","type":"function","z":"53b968ed.0df8b8","name":"Set IR Data","func":"//Insert learning code here\nvar data = [38,0,140,0,77,21,18,22,38,21,17,22,17,22,38,21,18,21,18,22,37,22,17,22,18,21,18,22,17,0,3,99,77,21,18,22,38,21,17,22,18,21,38,21,18,22,17,22,38,21,18,21,18,22,17,22,17,0,3,99,77,21,18,22,37,22,17,22,18,21,38,21,18,22,17,22,37,22,18,21,18,22,17,22,18,0,3,100,76,22,18,21,38,21,18,22,17,22,37,22,18,21,18,22,37,22,17,22,18,21,18,22,17,0,3,101,76,22,18,21,39,20,18,22,17,22,37,22,18,21,18,22,37,22,17,22,18,21,18,22,17,0,13,5,0,0,0,0,0,0,0,0,0,0,0,0];\n\nmsg.payload={\n    //\"mac\":\"MAC address of your broadlink rm\",\n    //\"host\":\"IP address of your broadlink rm\",\n    \"action\":\"send\",\n    \"data\":data,\n    \"repeat\":2\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":240,"wires":[["c86c3d63.e4c5a"]]},{"id":"befcb270.a63c2","type":"RM","z":"53b968ed.0df8b8","name":"","device":"d0041af7.f24d68","action":"learn","remote":"","button":"","fix":"","RFSweep":"false","x":370,"y":160,"wires":[["66e96ca9.ace5f4"]]},{"id":"631b0727.281fa8","type":"inject","z":"53b968ed.0df8b8","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":250,"y":160,"wires":[["befcb270.a63c2"]]},{"id":"517b9519.e721ac","type":"debug","z":"53b968ed.0df8b8","name":"","active":true,"tosidebar":true,"console":false,"complete":"payload","x":630,"y":160,"wires":[]},{"id":"66e96ca9.ace5f4","type":"json","z":"53b968ed.0df8b8","name":"","pretty":false,"x":490,"y":160,"wires":[["517b9519.e721ac"]]},{"id":"5a57bedc.3061b","type":"comment","z":"53b968ed.0df8b8","name":"Learn","info":"1. Inject\n2. Tap the remote button\n3. Copy learned code from debug tab","x":250,"y":120,"wires":[]},{"id":"250b4e34.45f8c2","type":"comment","z":"53b968ed.0df8b8","name":"Send learned code","info":"1. Insert learned code in the function node\n2. Deploy\n3. Inject","x":290,"y":200,"wires":[]},{"id":"7c01cb87.e0e144","type":"Discover","z":"53b968ed.0df8b8","name":"","x":380,"y":80,"wires":[["7fbabf32.bf9da"]]},{"id":"7fbabf32.bf9da","type":"debug","z":"53b968ed.0df8b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[0]","targetType":"msg","x":540,"y":80,"wires":[]},{"id":"44d58c91.55d894","type":"inject","z":"53b968ed.0df8b8","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":80,"wires":[["7c01cb87.e0e144"]]},{"id":"21894750.b786f8","type":"comment","z":"53b968ed.0df8b8","name":"Get the device properties","info":"","x":310,"y":40,"wires":[]},{"id":"d0041af7.f24d68","type":"rmdevice","z":"","folder":"/home/pi/RM3","mac":"24dfa77a4ff9","host":"192.168.0.101"}]
luxarts commented 4 years ago

Good news, now it works!

The problem is that you need to hard reset the device before.

  1. Press the reset button in the device until the LED starts to blink fast.
  2. Install the Broadlink App in your phone.
  3. Open the app, press "Add device" and it will start to scan for nearby devices. It will ask you the SSID and password of you WiFi network, complete the fields and continue.
  4. When this step finish it will ask to add a remote control or something else, DON'T ADD ANYTHING. Just close the app.
  5. Disconect the device from the power supply and reconect it to completely reset it.
  6. Now the device should work in Node-RED.
luxarts commented 4 years ago

I write this in a separated comment to better tracking.

The RF sweep function doesn't work. If set to No the learn works fine but when set to Yes it throws Broadlink Timeout Received - Closing Device Connection.

Is this feature working in older devices? I don't have one to test.

Anyways, all my IR remote controls (some from local brands and some from known brands like LG or Samsung) are working.

deadly667 commented 4 years ago

@luxarts But your device (5f36 RM3 mini) doesnt have RF. Only RM PRO has RF so this needs to be off (NO) for you.

luxarts commented 4 years ago

You're right, my bad! I confused RF with IR. It's 5am here, sorry. Haha.

Awesome work!

mlfunston commented 4 years ago

Also one note: dont use "type" for variable name. On node-red it breaks a lot of things :D

Ah yes, I was going to suggest using devtype or devicetype like in the python version. I'll check and see how this one works on Friday.

I'd like to get rid of the requirement for the user to select a type longer term but if this quick fix works, we can go with that for now.

deadly667 commented 4 years ago

But how can you know which type of device user are having if they dont select it? Its same like ip address and mac. Yes, for sure you can do something like in discovery node to discover device and its type but then you also know IP address and mac. What if someone has multiple device, which one would you select?

I dont like that idea.