Beispiel #1
0
def main():

    syslog.openlog(sys.argv[0])

    # Change location to nearest city.
    location = 'San Diego'

    # Get the local sunset/sunrise times
    a = Astral()
    a.solar_depression = 'civil'
    city = a[location]
    timezone = city.timezone
    sun = city.sun(date=datetime.datetime.now(), local=True)

    if debug:
        print 'Information for {}/{}\n'.format(location, city.region)
        print 'Timezone: {}'.format(timezone)

        print 'Latitude: {:.02f}; Longitude: {:.02f}\n'.format(
            city.latitude, city.longitude)

        print('Dawn:    {}'.format(sun['dawn']))
        print('Sunrise: {}'.format(sun['sunrise']))
        print('Noon:    {}'.format(sun['noon']))
        print('Sunset:  {}'.format(sun['sunset']))
        print('Dusk:    {}'.format(sun['dusk']))

    # Find the bulbs on the LAN
    scanner = BulbScanner()
    scanner.scan(timeout=4)

    # Specific ID/MAC of the bulbs to set
    porch_info = scanner.getBulbInfoByID('ACCF235FFFEE')
    livingroom_info = scanner.getBulbInfoByID('ACCF235FFFAA')

    if porch_info:
        bulb = WifiLedBulb(porch_info['ipaddr'])
        bulb.refreshState()

        timers = bulb.getTimers()

        # Set the porch bulb to turn on at dusk using timer idx 0
        syslog.syslog(
            syslog.LOG_ALERT,
            "Setting porch light to turn on at {}:{:02d}".format(
                sun['dusk'].hour, sun['dusk'].minute))
        dusk_timer = LedTimer()
        dusk_timer.setActive(True)
        dusk_timer.setRepeatMask(LedTimer.Everyday)
        dusk_timer.setModeWarmWhite(35)
        dusk_timer.setTime(sun['dusk'].hour, sun['dusk'].minute)
        timers[0] = dusk_timer

        # Set the porch bulb to turn off at dawn using timer idx 1
        syslog.syslog(
            syslog.LOG_ALERT,
            "Setting porch light to turn off at {}:{:02d}".format(
                sun['dawn'].hour, sun['dawn'].minute))
        dawn_timer = LedTimer()
        dawn_timer.setActive(True)
        dawn_timer.setRepeatMask(LedTimer.Everyday)
        dawn_timer.setModeTurnOff()
        dawn_timer.setTime(sun['dawn'].hour, sun['dawn'].minute)
        timers[1] = dawn_timer

        bulb.sendTimers(timers)

    else:
        print "Can't find porch bulb"

    if livingroom_info:
        bulb = WifiLedBulb(livingroom_info['ipaddr'])
        bulb.refreshState()

        timers = bulb.getTimers()

        # Set the living room bulb to turn on at sunset using timer idx 0
        syslog.syslog(
            syslog.LOG_ALERT,
            "Setting LR light to turn on at {}:{:02d}".format(
                sun['sunset'].hour, sun['sunset'].minute))
        sunset_timer = LedTimer()
        sunset_timer.setActive(True)
        sunset_timer.setRepeatMask(LedTimer.Everyday)
        sunset_timer.setModeWarmWhite(50)
        sunset_timer.setTime(sun['sunset'].hour, sun['sunset'].minute)
        timers[0] = sunset_timer

        # Set the living room bulb to turn off at a fixed time
        off_timer = LedTimer()
        off_timer.setActive(True)
        off_timer.setRepeatMask(LedTimer.Everyday)
        off_timer.setModeTurnOff()
        off_timer.setTime(23, 30)
        timers[1] = off_timer

        bulb.sendTimers(timers)
    else:
        print "Can't find living room bulb"
def main():

	syslog.openlog(sys.argv[0])
	
	# Change location to nearest city.
	location = 'San Diego'  
	
	# Get the local sunset/sunrise times
	a = Astral()
	a.solar_depression = 'civil'
	city = a[location]
	timezone = city.timezone
	sun = city.sun(date=datetime.datetime.now(), local=True)

	if debug:
		print 'Information for {}/{}\n'.format(location, city.region)
		print 'Timezone: {}'.format(timezone)
		
		print 'Latitude: {:.02f}; Longitude: {:.02f}\n'.format(city.latitude, city.longitude)
		   
		print('Dawn:    {}'.format(sun['dawn']))
		print('Sunrise: {}'.format(sun['sunrise']))
		print('Noon:    {}'.format(sun['noon']))
		print('Sunset:  {}'.format(sun['sunset']))
		print('Dusk:    {}'.format(sun['dusk']))
		
	# Find the bulbs on the LAN
	scanner = BulbScanner()
	scanner.scan(timeout=4)

	# Specific ID/MAC of the bulbs to set 
	porch_info = scanner.getBulbInfoByID('ACCF235FFFEE')
	livingroom_info = scanner.getBulbInfoByID('ACCF235FFFAA')
	
	if porch_info:
		bulb = WifiLedBulb(porch_info['ipaddr'])
		bulb.refreshState()
		
		timers = bulb.getTimers()

		# Set the porch bulb to turn on at dusk using timer idx 0
		syslog.syslog(syslog.LOG_ALERT, 
			"Setting porch light to turn on at {}:{:02d}".format(sun['dusk'].hour, sun['dusk'].minute))
		dusk_timer = LedTimer()
		dusk_timer.setActive(True)
		dusk_timer.setRepeatMask(LedTimer.Everyday)
		dusk_timer.setModeWarmWhite(35)
		dusk_timer.setTime(sun['dusk'].hour, sun['dusk'].minute)
		timers[0] = dusk_timer
		
		# Set the porch bulb to turn off at dawn using timer idx 1
		syslog.syslog(syslog.LOG_ALERT, 
			"Setting porch light to turn off at {}:{:02d}".format(sun['dawn'].hour, sun['dawn'].minute))
		dawn_timer = LedTimer()
		dawn_timer.setActive(True)
		dawn_timer.setRepeatMask(LedTimer.Everyday)
		dawn_timer.setModeTurnOff()
		dawn_timer.setTime(sun['dawn'].hour, sun['dawn'].minute)
		timers[1] = dawn_timer
		
		bulb.sendTimers(timers)

	else:
		print "Can't find porch bulb"
			
	if livingroom_info:
		bulb = WifiLedBulb(livingroom_info['ipaddr'])
		bulb.refreshState()
		
		timers = bulb.getTimers()

		# Set the living room bulb to turn on at sunset using timer idx 0
		syslog.syslog(syslog.LOG_ALERT, 
			"Setting LR light to turn on at {}:{:02d}".format(sun['sunset'].hour, sun['sunset'].minute))
		sunset_timer = LedTimer()
		sunset_timer.setActive(True)
		sunset_timer.setRepeatMask(LedTimer.Everyday)
		sunset_timer.setModeWarmWhite(50)
		sunset_timer.setTime(sun['sunset'].hour, sun['sunset'].minute)
		timers[0] = sunset_timer

		# Set the living room bulb to turn off at a fixed time
		off_timer = LedTimer()
		off_timer.setActive(True)
		off_timer.setRepeatMask(LedTimer.Everyday)
		off_timer.setModeTurnOff()
		off_timer.setTime(23,30)
		timers[1] = off_timer
		
		bulb.sendTimers(timers)
	else:
		print "Can't find living room bulb"