Skip to content

Instantly share code, notes, and snippets.

@dt
Created December 5, 2014 06:31
Show Gist options
  • Select an option

  • Save dt/4cd39c84eee8889f4674 to your computer and use it in GitHub Desktop.

Select an option

Save dt/4cd39c84eee8889f4674 to your computer and use it in GitHub Desktop.
#coffeebot server
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