Skip to content

Instantly share code, notes, and snippets.

@NateBarnes
Created March 25, 2014 03:01
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 NateBarnes/9754494 to your computer and use it in GitHub Desktop.
Save NateBarnes/9754494 to your computer and use it in GitHub Desktop.
require 'bundler'
Bundler.require
require 'socket'
def c
@c ||= LIFX::Client.lan
end
def lightcontrol(command)
print command
case command
when "kitchen_on"
c.lights.with_tag('kitchen').turn_on
when "kitchen_off"
c.lights.with_tag('kitchen').turn_off
end
sleep 1
end
LIFX::Config.logger = Yell.new(STDERR, :level => :error)
a = TCPServer.new('', 3333) # '' means to bind to "all interfaces", same as nil or '0.0.0.0'
c.discover
5.times do
c.lights.refresh
c.flush
sleep 1
puts "Lights found: #{c.lights.count}"
end
sleep 1
loop {
connection = a.accept
data = connection.recv(1024)
puts "received:" + data
case data
when "kitchen_on"
c.lights.with_tag('kitchen').turn_on
when "kitchen_off"
c.lights.with_tag('kitchen').turn_off
when "downstairs_off"
c.lights.with_tag('downstairsall').turn_off
when "downstairs_on"
c.lights.with_tag('downstairsall').turn_on
when "lamp_on"
c.lights.with_label('LRLamp').turn_on
when "lamp_off"
c.lights.with_label('LRLamp').turn_off
sleep 1
end
connection.close
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment