Created
December 5, 2014 06:31
-
-
Save dt/4cd39c84eee8889f4674 to your computer and use it in GitHub Desktop.
#coffeebot server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| brew_light <- 55000; | |
| brewing <- false; | |
| slack_url <- "https://hooks.slack.com/services/BLAHBLAHBLAH"; | |
| function slack(msg) { | |
| local body = "{\"text\": \""+msg+"\", \"username\": \"Coffeebot\", \"icon_emoji\": \":coffee:\"}"; | |
| local request = http.post(slack_url, {}, body); | |
| local resp = request.sendsync(); | |
| server.log("Slack says ("+resp.statuscode + "): " + resp.body) | |
| } | |
| function check(lvl) { | |
| server.log("level: " + lvl); | |
| if (lvl < brew_light) { //brewing! | |
| if (!brewing) | |
| slack("Coffee is brewing..."); | |
| brewing = true; | |
| } else { | |
| if (brewing) | |
| slack("Coffee is ready!"); | |
| brewing = false; | |
| } | |
| } | |
| device.on("lvl", check); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment