Created
September 11, 2016 16:41
-
-
Save dzamlo/16bc43e20f299e2206659ff0c3b2306b to your computer and use it in GitHub Desktop.
Quick and dirty way to use a cheap bluetooth selfie remote on a linux server (like a raspberry pi) to control lifx lights
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
ACTION=="add", SUBSYSTEM=="input", ATTRS{name}=="AB Shutter3 ", TAG+="systemd", PROGRAM="/bin/systemd-escape -p --template=lifx-remote@.service $env{DEVNAME}", ENV{SYSTEMD_WANTS}+="%c" |
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
The full paths of the file are: | |
/etc/udev/rules.d/99-lifx-keyboard.rules | |
/etc/systemd/system/lifx-remote@.service | |
/usr/local/bin/lifx-remote.py | |
Install the python dependancies lister in requirements.txt using pip. | |
If you have multiple remote, you could filter them in the udev rule. | |
It should work with multiple bulb, but I haven't tested that. |
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
#! /usr/bin/python2 | |
import evdev | |
import lifx | |
import time | |
COLOR_NORMAL = lifx.color.HSBK(hue=0.0, saturation=0.0, brightness=1.0, kelvin=3500) | |
COLOR_NIGHT = lifx.color.HSBK(hue=0.0, saturation=0.0, brightness=0.1099870298313878, kelvin=2750) | |
def button(lights, color): | |
devices = lights.get_devices() | |
if len(devices) > 0: | |
if not devices[0].power or devices[0].color != color: | |
for device in devices: | |
device.color = color | |
time.sleep(0.1) | |
device.power = True | |
else: | |
for device in devices: | |
device.power = False | |
def big_button(lights): | |
print "big button pressed" | |
button(lights, COLOR_NORMAL) | |
def small_button(lights): | |
print "small button pressed" | |
button(lights, COLOR_NIGHT) | |
def main(argv): | |
device = evdev.InputDevice(argv[1]) | |
device.grab() | |
lights = lifx.Client() | |
enter_pressed = False | |
for event in device.read_loop(): | |
if event.type == evdev.ecodes.EV_KEY: | |
event = evdev.categorize(event) | |
key_up = event.keystate == evdev.KeyEvent.key_up | |
vol_up = event.keycode == 'KEY_VOLUMEUP' | |
enter = event.keycode == 'KEY_ENTER' | |
if key_up and enter: | |
enter_pressed = True | |
elif key_up and vol_up: | |
lights.discover() | |
if enter_pressed: | |
small_button(lights) | |
else: | |
big_button(lights) | |
enter_pressed = False | |
def usage(): | |
print("usage: lifx-remote.py /dev/input/event?") | |
if __name__ == '__main__': | |
import sys | |
if len(sys.argv) > 1: | |
main(sys.argv) | |
else: | |
usage() |
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
[Unit] | |
Description=lifx remote on %I | |
[Service] | |
ExecStart=/usr/local/bin/lifx-remote.py /%I | |
Type=simple |
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
evdev | |
lifx-sdk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment