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

Broadlink MP1 Validation #11

Closed TomyCesaille closed 4 years ago

TomyCesaille commented 5 years ago

Hello, Broadlink MP1 (4 Outlet Power Strip) device seems to be working. Just saying as README declare it was not tested.

Get, Set actions

Get & Get actions are both working.

Small issue: One Set might be missed when changing 2+ sockets state 'at the same time' (like in screenshot below). However, there are no issues when setting 2+ sockets state using one single Set block.

'Set from msg.payload' action

I could not make Set from msg.payload to work. I tried to inject those 2 json payloads with no success.

{"state":{"s1":true}}
{"s1":true}
lotek4u commented 5 years ago

Regarding your small issue of missing some "set" commands, this happens with many node-red flows I have. I usually introduce a delay node with about 100 msecs on (for instance) the line going to s2. It's not ideal, but it gets around the issue which I think is a node-red issue and not really related to the nodes in question.

mlfunston commented 5 years ago

Hi @TomyCesaille - Thanks for the info, I'll mark it as working in the Readme.

For the set via msg.payload function, it needs to be in the following format as I understand it.

{
    "action": "setState",
    "state": false,
    "s1": true,
    "s2": true,
    "s3": false,
    "s4": false
}

As for the other issue, it's either the issue mentioned by @lotekjunky or possibly that the Broadlink unit can't respond to two subsequent requests that quickly. Does it work if you do them serially? Or by setting each outlet using the message format above?

TomyCesaille commented 5 years ago

Hi @mlfunston, I tried your payload and it makes nodered crash. Format might be good then, but this is leading to an exception.

24 Feb 19:20:18 - [red] Uncaught Exception:
24 Feb 19:20:18 - SyntaxError: Unexpected token u in JSON at position 0
    at Object.parse (native)
    at MP1._device.on (/data/node_modules/node-red-contrib-broadlink-control/nodes/MP1Node.js:58:84)
    at emitNone (events.js:86:13)
    at MP1.emit (events.js:185:7)
    at Socket.Device.cs.on (/data/node_modules/node-red-contrib-broadlink-control/nodes/Device.js:50:22)
    at emitTwo (events.js:106:13)
    at Socket.emit (events.js:191:7)
    at UDP.onMessage (dgram.js:548:8)

This is fine when assigning multiple SET in 1 flow serially.

mlfunston commented 4 years ago

I tried doing some tests separately on the code and it seems to work ok, but you need to include all 4 s parameters. If you want to change s1 and s3 for example, send the following:

{ "action": "setState", "state": false, "s1": true, "s2": false, "s3": true, "s4": false }

Only the switches marked with true will be changed to the state defined - false (off) in the case above.

Let me know if that works.

mlfunston commented 4 years ago

Updated in v1.0.8