Skip to content

Instantly share code, notes, and snippets.

@techlemur
Last active July 24, 2018 18:29
Show Gist options
  • Save techlemur/2f085b47189475733d6de3a3f0dedbee to your computer and use it in GitHub Desktop.
Save techlemur/2f085b47189475733d6de3a3f0dedbee to your computer and use it in GitHub Desktop.
Basic flow to have Alexa locally control a raspberry pi running node red.
[{"id":"f1de55df.5e2f88","type":"subflow","name":"Execute Shell Script","info":"","in":[{"x":100,"y":200,"wires":[{"id":"285cddd0.d7e24a"}]}],"out":[{"x":960,"y":280,"wires":[{"id":"62b058c.3afd0a8","port":0}]},{"x":960,"y":340,"wires":[{"id":"62b058c.3afd0a8","port":1}]},{"x":960,"y":400,"wires":[{"id":"62b058c.3afd0a8","port":2}]}]},{"id":"76a063c9.c6b974","type":"file","z":"f1de55df.5e2f88","name":"Write script file","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"false","x":860,"y":140,"wires":[]},{"id":"d0bfe6c1.044a5","type":"exec","z":"f1de55df.5e2f88","command":"mktemp","addpay":false,"append":"","useSpawn":"","timer":"","name":"","x":420,"y":200,"wires":[["fe9bd6b2.929e7"],[],[]]},{"id":"b4a9ec57.96bc4","type":"file","z":"f1de55df.5e2f88","name":"Delete script file","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"delete","x":1020,"y":480,"wires":[]},{"id":"62b058c.3afd0a8","type":"exec","z":"f1de55df.5e2f88","command":" sh ","addpay":true,"append":"","useSpawn":"","timer":"","name":"Execute the shell script","x":690,"y":340,"wires":[["b4a9ec57.96bc4"],[],[]]},{"id":"fbb9e1ff.5101d8","type":"exec","z":"f1de55df.5e2f88","command":"chmod +x ","addpay":true,"append":"","useSpawn":"","timer":"","name":"","x":1040,"y":200,"wires":[["2e95caad.66f9fe"],[],[]]},{"id":"285cddd0.d7e24a","type":"change","z":"f1de55df.5e2f88","name":"","rules":[{"t":"set","p":"command","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":200,"wires":[["d0bfe6c1.044a5"]]},{"id":"30114b40.606d84","type":"change","z":"f1de55df.5e2f88","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"filename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":200,"wires":[["fbb9e1ff.5101d8"]]},{"id":"fe9bd6b2.929e7","type":"function","z":"f1de55df.5e2f88","name":"","func":"msg.filename = msg.payload.trim();\nmsg.payload = msg.command;\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":180,"wires":[["76a063c9.c6b974","30114b40.606d84"]]},{"id":"2e95caad.66f9fe","type":"change","z":"f1de55df.5e2f88","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"filename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":340,"wires":[["62b058c.3afd0a8"]]},{"id":"6f02b2cb.adf59c","type":"comment","z":"f1de55df.5e2f88","name":"Execute shell script","info":"Execute the shell script in msg.payload.","x":130,"y":40,"wires":[]},{"id":"231541c2.2ef7ae","type":"template","z":"3c6601f6.a56b66","name":"Shell Script - Shutdown","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"#! /bin/sh\n\nsudo shutdown -P -t now","x":780,"y":280,"wires":[["961fcace.c4b6d"]]},{"id":"def7c165.e09c08","type":"inject","z":"3c6601f6.a56b66","name":"shutdown","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":520,"y":300,"wires":[["231541c2.2ef7ae"]]},{"id":"961fcace.c4b6d","type":"subflow:f1de55df.5e2f88","z":"3c6601f6.a56b66","name":"","x":1220,"y":160,"wires":[["33c5a854.e89b08"],["33c5a854.e89b08"],["33c5a854.e89b08"]]},{"id":"62f49a89.b6ec94","type":"switch","z":"3c6601f6.a56b66","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":260,"wires":[["95f34023.1a1908"],["231541c2.2ef7ae"]]},{"id":"33c5a854.e89b08","type":"debug","z":"3c6601f6.a56b66","name":"Log the result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1440,"y":160,"wires":[]},{"id":"95f34023.1a1908","type":"template","z":"3c6601f6.a56b66","name":"Shell Script - Reboot","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"#! /bin/sh\n\nsudo reboot","x":780,"y":240,"wires":[["961fcace.c4b6d"]]},{"id":"47a7262a.169a38","type":"template","z":"3c6601f6.a56b66","name":"Shell Script - stop nodered and bluetooth 20","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"#! /bin/sh\n\nsudo /etc/init.d/bluetooth stop\n\n\nsudo systemctl stop nodered.service","x":780,"y":200,"wires":[["961fcace.c4b6d"]]},{"id":"20b6f99b.707126","type":"template","z":"3c6601f6.a56b66","name":"Shell Script - stop nodered 50","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"#! /bin/sh\n\nsudo systemctl stop nodered.service","x":780,"y":160,"wires":[["961fcace.c4b6d"]]},{"id":"7f12e428.a290bc","type":"template","z":"3c6601f6.a56b66","name":"Shell Script - start/restart nodered, apache, haBridge, and mosquitto","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"#! /bin/sh\n\nsudo /etc/init.d/bluetooth restart\nsudo systemctl restart nodered.service\nsudo systemctl restart apache2.service\nsudo systemctl restart habridge.service\nsudo systemctl restart mosquitto.service ","x":780,"y":40,"wires":[["961fcace.c4b6d"]]},{"id":"912947e5.74d118","type":"template","z":"3c6601f6.a56b66","name":"Shell Script - start/restart bluetooth 90","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"#! /bin/sh\n\nsudo /etc/init.d/bluetooth restart","x":780,"y":80,"wires":[["961fcace.c4b6d"]]},{"id":"1add10fa.19c44f","type":"switch","z":"3c6601f6.a56b66","name":"on/off command?","property":"on_off_command","propertyType":"msg","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":160,"wires":[["c75afe69.9f6a2"],["62f49a89.b6ec94"]]},{"id":"5e454a7f.2b4b9c","type":"inject","z":"3c6601f6.a56b66","name":"reboot","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":510,"y":220,"wires":[["95f34023.1a1908"]]},{"id":"c75afe69.9f6a2","type":"switch","z":"3c6601f6.a56b66","name":"brightness","property":"bri","propertyType":"msg","rules":[{"t":"eq","v":"100","vt":"num"},{"t":"eq","v":"95","vt":"num"},{"t":"eq","v":"90","vt":"num"},{"t":"eq","v":"60","vt":"num"},{"t":"eq","v":"50","vt":"num"},{"t":"eq","v":"20","vt":"num"}],"checkall":"true","repair":false,"outputs":6,"x":530,"y":100,"wires":[["7f12e428.a290bc"],[],["912947e5.74d118"],["3e61cfdb.0a305"],["20b6f99b.707126"],["47a7262a.169a38"]]},{"id":"6d2a9db9.27415c","type":"alexa-local","z":"3c6601f6.a56b66","devicename":"raspberry pie","inputtrigger":false,"x":100,"y":160,"wires":[["1add10fa.19c44f"]]},{"id":"3e61cfdb.0a305","type":"template","z":"3c6601f6.a56b66","name":"Shell Script - start/restart nodered 50","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"#! /bin/sh\n\nsudo systemctl restart nodered.service","x":780,"y":120,"wires":[[]]},{"id":"357b06f7.b56c5a","type":"comment","z":"3c6601f6.a56b66","name":"README","info":"https://gist.github.com/techlemur/2f085b47189475733d6de3a3f0dedbee\n\nI've only tried this with the echo dot gen2 but\nit should work on gen1 dots as well.\n\nRequires node-red-contrib-alexa-local.\n\nThe user node red is running as must also\nhave sudo access without asking for a password.\n\nAfter installing just say \"Alexa, discover devices\".\nShe should find a new “light” named raspberry pi.\nAfter Alexa discovers the light you can control\nYour pi by telling Alexa to...\n\n“turn {on|off} raspberry pi”\nor\n“set raspberry pi to {number 1-100}”.\n\nSadly there's no other commands that will work\nwith the virtual light so you have to memorize\nwhat you set the percentages to.\n\nKudos to uphy for the “Execute Shell Script” subflow.\nhttps://gist.github.com/uphy/7aab9758be41888e20b94d14e9c50976\n\n~Techlemur\n\n\n\n","x":80,"y":120,"wires":[]},{"id":"7cc467d0.17043","type":"comment","z":"3c6601f6.a56b66","name":"Kudos to uphy for this subflow","info":"https://gist.github.com/uphy/7aab9758be41888e20b94d14e9c50976","x":1210,"y":120,"wires":[]},{"id":"38c4ca5c.af95ae","type":"comment","z":"3c6601f6.a56b66","name":"REQUIRES node-red-contrib-alexa-local","info":"You must install node-red-contrib-alexa-local\nbefore this will work.","x":90,"y":80,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment