bin/lights

66 lines
1.1 KiB
Ruby
Executable file

#!/usr/bin/env ruby
require 'huemote'
LIGHT_NAMES = ['Office 1', 'Office 2']
TEMPS = {
'bright' => {
brightness: 100,
temp: 4200,
},
'cloudy' => {
brightness: 90,
temp: 3500,
},
'sunrise' => {
brightness: 70,
temp: 2600,
},
'morning' => {
brightness: 90,
temp: 2200,
},
'noon' => {
brightness: 100,
temp: 4200,
},
'sunset' => {
brightness: 90,
temp: 2600,
},
'night' => {
brightness: 70,
temp: 2200,
},
}
TEMPS['sunny'] = TEMPS['bright']
TEMPS['overcast'] = TEMPS['cloudy']
setting = ARGV.first
Huemote.set_ip '192.168.0.2'
lights = LIGHT_NAMES.map { |name| Huemote::Light.find(name) }
case setting
when 'off'
lights.each(&:off!)
when 'on'
lights.each(&:on!)
else
lights.each(&:on!)
attrs = TEMPS[setting] || {
brightness: (ARGV[1] || 80).to_i,
temp: setting.to_i,
}
if attrs
lights.each do |l|
if attrs[:brightness]
l.brightness(attrs[:brightness])
end
if attrs[:temp]
l.kelvin(attrs[:temp])
end
end
else
puts "Unknown setting: #{setting}"
end
end