Orvibo S20 WiFi Mains Sockets

On/off control of the Orvibo S20 Smart Sockets. More info here.

[{"id":"32a2fac0.cd5d06","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"5c877283.a3788c","type":"udp out","z":"3c0defcd.c3f21","name":"","addr":"255.255.255.255","iface":"","port":"10000","ipv":"udp4","outport":"","base64":false,"multicast":"broad","x":718,"y":831,"wires":[]},{"id":"9ec80023.6138","type":"delay","z":"3c0defcd.c3f21","name":"","pauseType":"delay","timeout":"300","timeoutUnits":"milliseconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":502,"y":858,"wires":[["5c877283.a3788c"]]},{"id":"3d8d399.fc272c6","type":"function","z":"3c0defcd.c3f21","name":"Orvibo S20 WiFi Sockets","func":"// Read my blog post about this here: https://nathan.chantrell.net/20160101/orvibo-s20-wifi-mains-socket-with-node-red\n\n// Get mac address from topic and place in array\nmsg.topic = msg.topic.replace('orvibo/','');\nvar mac = [];\nfor (var i = 0; i < msg.topic.length;) {\n    mac.push(\"0x\" + msg.topic.charAt(i) + msg.topic.charAt(i+1));\n    i = i+2;\n}\nvar padding = [0x20,0x20,0x20,0x20,0x20,0x20];\nvar uid = mac.concat(padding);\nvar uidLE = mac.reverse().concat(padding);\n\n// Build subscribe packet\nvar command = [0x68,0x64,0x00,0x1e,0x63,0x6c];\nvar subscribe = command.concat(uid).concat(uidLE);\n\n// Build command packet\ncommand = [0x68,0x64,0x00,0x17,0x64,0x63];\nif (msg.payload == \"on\") {\n    var data = [0x00,0x00,0x00,0x00,0x01];\n} else if (msg.payload == \"off\") {\n    var data = [0x00,0x00,0x00,0x00,0x00];\n}\nvar packet = command.concat(uid).concat(data);\n\nmsg = { payload: new Buffer(subscribe) };\nvar msg2 = { payload: new Buffer(packet) };\n\nreturn [msg, msg2];\n","outputs":"2","noerr":0,"x":299,"y":839,"wires":[["5c877283.a3788c"],["9ec80023.6138"]]},{"id":"881a23a6.77e5e","type":"mqtt in","z":"3c0defcd.c3f21","name":"","topic":"orvibo/#","broker":"32a2fac0.cd5d06","x":109,"y":839,"wires":[["3d8d399.fc272c6"]]}]

Flow Info

Created 9 years, 9 months ago
Updated 8 years, 2 months ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • delay (x1)
  • function (x1)
  • mqtt in (x1)
  • mqtt-broker (x1)
  • udp out (x1)

Tags

  • orvibo
  • s20
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option