Skip to content

Instantly share code, notes, and snippets.

@tedstriker
Last active April 28, 2017 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedstriker/803d78e2ddfc5d5c7d2e135f975f9a60 to your computer and use it in GitHub Desktop.
Save tedstriker/803d78e2ddfc5d5c7d2e135f975f9a60 to your computer and use it in GitHub Desktop.
xiaomi sensors to mqtt

V 0.1: Initial version

Listen to sensor reports of a xiaomi home gateway. This is an early version and it will be improved over time.

What's working is:

  • reliably report motion state
  • reliably report door/window state

Whats missing yet:

  • turn motion sensor off, if there's no update within 65 seconds (minimum open state interval is 120 seconds and could be reduced to 6265 seconds)
  • retain values for door and motion sensors
  • not all switch reports are handled properly (unhandled no_close)
  • not all cube reports are handled properly (unhandled rotation)
[{"id":"7f85a82e.909a48","type":"mqtt out","z":"be3a4531.4610c8","name":"","topic":"","qos":"","retain":"","x":670,"y":500,"wires":[]},{"id":"99abc2c4.2dbda","type":"debug","z":"be3a4531.4610c8","name":"","active":false,"console":"false","complete":"false","x":690,"y":460,"wires":[]},{"id":"d3529a36.34cd8","type":"function","z":"be3a4531.4610c8","name":"","func":"var newMsg = {};\nif (msg.payload.cmd == 'report') {\n var data = JSON.parse(msg.payload.data);\n if (data.no_motion) {\n newMsg.payload = \"no_motion\";\n } else if (data.status ){\n newMsg.payload = data.status;\n } else {\n newMsg.payload = msg.payload.data;\n }\n newMsg.topic = 'xiaomi/' + msg.payload.model + '/' + msg.payload.sid + '/status';\n return [msg, newMsg];\n} \n\nreturn null;","outputs":"2","noerr":0,"x":520,"y":480,"wires":[["99abc2c4.2dbda"],["7f85a82e.909a48"]]},{"id":"df3c8f11.dc1e7","type":"json","z":"be3a4531.4610c8","name":"","x":380,"y":480,"wires":[["d3529a36.34cd8"]]},{"id":"62b13610.673b5","type":"udp in","z":"be3a4531.4610c8","name":"","iface":"","port":"9898","ipv":"udp4","multicast":"true","group":"224.0.0.50","datatype":"utf8","x":170,"y":480,"wires":[["df3c8f11.dc1e7"]]},{"id":"d21e5455.31c39","type":"comment","z":"be3a4531.4610c8","name":"Listen for Xiaomi sensors","info":"every msg type != cmd:report gets filtered out.","x":190,"y":420,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment