Alexa Walabot turn on the lamp you are standing by

Using Walabot radar detect which lamp the user is standing by and turn on that specific lamp. This code optimized for the Raspberry Pi and Phillips Hue lamps.

A derivative of this project: https://www.hackster.io/72740/alexa-turn-on-this-lamp-smart-3d-sensor-for-amazon-echo-b82d7b

Commands Alexa turn on the light Turns on the light you are standing by Alexa turn off the light Turns off the light you are standing by Alexa turn on the lights Turns on all the lights Alexa turn off the lights Turns off all the lights Alexa turn on the light xx % Turns on the light you are standing by the specified brightness Alexa turn on the Walabot Reboots the raspberry pi (useful when the service crashes) Don’t stand in front of the Walabot for 2 minutes while the pi reboots Alexa turn off the Walabot Powers down the Raspberry Pi so it's safe to disconnect the power. Alexa will say the command failed because the pi shuts down before sending the confirmation response.

[{"id":"907bfe4a.2fa938","type":"tab","label":"Flow 17","disabled":false,"info":""},{"id":"5202a4e2.81a9d4","type":"tcp in","z":"907bfe4a.2fa938","name":"","server":"client","host":"localhost","port":"1890","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":150,"y":140,"wires":[["546268d2.f98258"]]},{"id":"546268d2.f98258","type":"function","z":"907bfe4a.2fa938","name":"Convert to json array","func":"raw = msg.payload.toString('UTF-8')\nj = JSON.parse(raw);\nvar msg1 = { payload: raw };\nvar msg2 = { payload: j };\n\n\nif (raw.length > 20)\n{\n    X = msg2.payload.targets[0].x;\n    Y = msg2.payload.targets[0].y;\n    Z = msg2.payload.targets[0].z;\n    global.set(\"X\", X);\n    global.set(\"Y\", Y);\n    global.set(\"Z\", Z);\n    var msg3 = { payload: X };\n    var msg4 = { payload: Y };\n    var msg5 = { payload: Z };   \n}\n\nreturn [  msg1, msg2, msg3, msg4, msg5];  \n\n","outputs":"5","noerr":0,"x":380,"y":140,"wires":[["7487c17d.fa95a"],["81eb1f3c.e66558"],["422aa571.f6632c"],["68ad94b4.c3a1a4"],["984ce324.2bc738"]]},{"id":"7487c17d.fa95a","type":"debug","z":"907bfe4a.2fa938","name":"Raw String","active":false,"console":"false","complete":"payload","x":631,"y":60,"wires":[]},{"id":"984ce324.2bc738","type":"debug","z":"907bfe4a.2fa938","name":"Z","active":true,"console":"false","complete":"payload","x":647,"y":207,"wires":[]},{"id":"68ad94b4.c3a1a4","type":"debug","z":"907bfe4a.2fa938","name":"Y","active":true,"console":"false","complete":"payload","x":647,"y":172,"wires":[]},{"id":"422aa571.f6632c","type":"debug","z":"907bfe4a.2fa938","name":"X","active":false,"console":"false","complete":"payload","x":647,"y":136,"wires":[]},{"id":"81eb1f3c.e66558","type":"debug","z":"907bfe4a.2fa938","name":"JSON Array","active":false,"console":"false","complete":"payload","x":628,"y":99,"wires":[]},{"id":"8aafbe05.7a89e","type":"inject","z":"907bfe4a.2fa938","name":"Print saved XYZ","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"x":166,"y":246,"wires":[["68568d8b.cc1fcc"]]},{"id":"68568d8b.cc1fcc","type":"function","z":"907bfe4a.2fa938","name":"","func":"var X = global.get(\"X\");\nvar Y = global.get(\"Y\");\nvar Z = global.get(\"Z\");\n\nstr = \"X=\" + X + \"  Y=\" + Y + \"  Z=\" + Z\nmsg.payload = str\nreturn msg;  \n\n","outputs":1,"noerr":0,"x":367,"y":246,"wires":[["eaed629f.2db788"]]},{"id":"eaed629f.2db788","type":"debug","z":"907bfe4a.2fa938","name":"","active":false,"console":"false","complete":"false","x":627,"y":246,"wires":[]},{"id":"cb90c58c.4c46a8","type":"comment","z":"907bfe4a.2fa938","name":"Get and save Walabot XYZ","info":"","x":180,"y":60,"wires":[]},{"id":"8404bcab.95fe6","type":"inject","z":"907bfe4a.2fa938","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"x":170,"y":300,"wires":[["836a45f6.5497c8"]]},{"id":"836a45f6.5497c8","type":"exec","z":"907bfe4a.2fa938","command":"/usr/bin/sudo","addpay":false,"append":"python /home/pi/Downloads/smart3DSensorForAlexa/Walabot/walabot.py 1890","useSpawn":"false","timer":"","oldrc":false,"name":"","x":350,"y":300,"wires":[["b978cd6b.7b7e4"],["b978cd6b.7b7e4"],["b978cd6b.7b7e4"]]},{"id":"b978cd6b.7b7e4","type":"debug","z":"907bfe4a.2fa938","name":"","active":true,"console":"false","complete":"false","x":570,"y":300,"wires":[]},{"id":"f652de8a.44be08","type":"debug","z":"907bfe4a.2fa938","name":"","active":true,"console":"false","complete":"true","x":390,"y":580,"wires":[]},{"id":"a4724f86.0df9f8","type":"function","z":"907bfe4a.2fa938","name":"Light A","func":"var X = global.get(\"X\");\nvar Y = global.get(\"Y\");\nvar Z = global.get(\"Z\");\nvar msg2 = { payload: Y };\nvar bri = Math.round(msg.bri * 2.55);\nvar onoff = msg.on;\n\nif (Z < 100)\n{\n    msg.payload={\n    \"on\":[onoff],\n    \"transitiontime\":[10],\n    \"bri\":[bri]}\n    return [  msg, msg2];  \n}","outputs":"2","noerr":0,"x":400,"y":635,"wires":[["d9a17069.fd4f9","3921e407.6da04c"],["6ffe6ef4.292f7"]]},{"id":"f93797a6.94428","type":"function","z":"907bfe4a.2fa938","name":"Light B","func":"var X = global.get(\"X\");\nvar Y = global.get(\"Y\");\nvar Z = global.get(\"Z\");\nvar msg2 = { payload: Y };\nvar bri = Math.round(msg.bri * 2.55);\nvar onoff = msg.on;\n\nif (Z > 100)\n{\n    if (Y < 0)\n    {\n        msg.payload={\n        \"on\":[onoff],\n        \"transitiontime\":[10],\n        \"bri\":[bri]}\n        return [  msg, msg2];  \n    }\n}","outputs":"2","noerr":0,"x":400,"y":680,"wires":[["4e5cfe.961e6b04","bea07326.5bec58"],["6ffe6ef4.292f7"]]},{"id":"d9a17069.fd4f9","type":"debug","z":"907bfe4a.2fa938","name":"","active":true,"console":"false","complete":"true","x":610,"y":600,"wires":[]},{"id":"4e5cfe.961e6b04","type":"debug","z":"907bfe4a.2fa938","name":"","active":true,"console":"false","complete":"true","x":610,"y":740,"wires":[]},{"id":"6ffe6ef4.292f7","type":"debug","z":"907bfe4a.2fa938","name":"Y","active":true,"console":"false","complete":"payload","x":610,"y":680,"wires":[]},{"id":"66ef68e0.d4e1f8","type":"comment","z":"907bfe4a.2fa938","name":"Handle Alexa commands","info":"","x":190,"y":400,"wires":[]},{"id":"1fa8a78a.1fa4e","type":"alexa-local","z":"907bfe4a.2fa938","devicename":"Light","inputtrigger":false,"x":142.50001525878906,"y":626.0000152587891,"wires":[["a4724f86.0df9f8","f93797a6.94428","f652de8a.44be08","93a561a7.d27398"]]},{"id":"a8a17695.d6717","type":"alexa-local","z":"907bfe4a.2fa938","devicename":"Lights","inputtrigger":false,"x":150,"y":760,"wires":[["528ae0a7.c01158"]]},{"id":"3921e407.6da04c","type":"Hue Set","z":"907bfe4a.2fa938","deviceid":"1","serverid":"001788fffe2cdd2c","name":"1","x":610,"y":640,"wires":[[],[]]},{"id":"bea07326.5bec58","type":"Hue Set","z":"907bfe4a.2fa938","deviceid":"2","serverid":"001788fffe2cdd2c","name":"2","x":610,"y":780,"wires":[[],[]]},{"id":"bb9cb955.a89ea8","type":"Hue Set","z":"907bfe4a.2fa938","deviceid":"3","serverid":"001788fffe2cdd2c","name":"3","x":610,"y":820,"wires":[[],[]]},{"id":"528ae0a7.c01158","type":"function","z":"907bfe4a.2fa938","name":"All","func":"var bri = Math.round(msg.bri * 2.55);\nvar onoff = msg.on;\n\nmsg.payload={\n\"on\":[onoff],\n\"transitiontime\":[10],\n\"bri\":[bri]}\nreturn msg;  ","outputs":"2","noerr":0,"x":390,"y":760,"wires":[["3921e407.6da04c","bb9cb955.a89ea8","bea07326.5bec58"],[]]},{"id":"93a561a7.d27398","type":"function","z":"907bfe4a.2fa938","name":"Light C","func":"var X = global.get(\"X\");\nvar Y = global.get(\"Y\");\nvar Z = global.get(\"Z\");\nvar msg2 = { payload: Y };\nvar bri = Math.round(msg.bri * 2.55);\nvar onoff = msg.on;\n\nif (Z > 100)\n{\n    if (Y > 0)\n    {\n        msg.payload={\n        \"on\":[onoff],\n        \"transitiontime\":[10],\n        \"bri\":[bri]}\n        return [  msg, msg2];  \n    }\n}","outputs":"2","noerr":0,"x":400,"y":720,"wires":[["bb9cb955.a89ea8"],[]]},{"id":"4c0bb67a.eb913","type":"inject","z":"907bfe4a.2fa938","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":160,"y":440,"wires":[["8a599fae.f6ec7"]]},{"id":"8a599fae.f6ec7","type":"exec","z":"907bfe4a.2fa938","command":"sudo reboot now","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":480,"y":440,"wires":[["fc52275d.093958"],["fc52275d.093958"],["fc52275d.093958"]]},{"id":"fc52275d.093958","type":"debug","z":"907bfe4a.2fa938","name":"","active":true,"console":"false","complete":"false","x":690,"y":460,"wires":[]},{"id":"97261df6.b9091","type":"alexa-local","z":"907bfe4a.2fa938","devicename":"Walabot","inputtrigger":false,"x":140,"y":480,"wires":[["ad34d016.a1f4a"]]},{"id":"4c96b28d.c2bd3c","type":"exec","z":"907bfe4a.2fa938","command":"sudo shutdown -h now","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":500,"y":500,"wires":[["fc52275d.093958"],["fc52275d.093958"],["fc52275d.093958"]]},{"id":"ad34d016.a1f4a","type":"function","z":"907bfe4a.2fa938","name":"Light A","func":"var bri = Math.round(msg.bri * 2.55);\nvar onoff = msg.on;\n\nif (Z < 100)\n{\n    msg.payload={\n    \"on\":[onoff],\n    \"transitiontime\":[10],\n    \"bri\":[bri]}\n    return [  msg, msg2];  \n}","outputs":"2","noerr":0,"x":280,"y":480,"wires":[["8a599fae.f6ec7","4c96b28d.c2bd3c"],[]]}]
ElectronHacks

Flow Info

created 10 months, 1 week ago

Node Types

Core
  • comment (x2)
  • debug (x12)
  • exec (x3)
  • function (x7)
  • inject (x3)
  • tcp in (x1)
Other

Tags

  • walabot
  • alexa
  • amazon
  • echo
  • raspberry
  • lights
  • automation
  • hue
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option