Skip to content

Instantly share code, notes, and snippets.

@stianeikeland
Created October 20, 2012 14:31
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 stianeikeland/3923421 to your computer and use it in GitHub Desktop.
Save stianeikeland/3923421 to your computer and use it in GitHub Desktop.
Power control on the message bus
power = new Power new MessageBus
# Power coffeemaker off 60 minutes after it was powered on:
power.on 'kitchen-coffeemaker', (event) ->
turnOff = () ->
power.send {
command: "off",
location: "kitchen-coffeemaker" }
setTimeout turnOff, 60*60*1000 if event.command is "on"
# Turn stuff off if the last-man-out button near the exit is pressed:
power.on 'exitdoor-lastmanout', (event) ->
receivers = [
"kitchen-coffeemaker",
"kitchen-kettle",
"bedroom-lights",
"bathroom-lights"]
power.send {
command: "off"
location: receiver
} for receiver in receivers if event.command is "off"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment