Created
October 20, 2012 14:31
-
-
Save stianeikeland/3923421 to your computer and use it in GitHub Desktop.
Power control on the message bus
This file contains 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
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