Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2016 16:41
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dzamlo/16bc43e20f299e2206659ff0c3b2306b to your computer and use it in GitHub Desktop.
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
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"
The full paths of the file are:
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.
#! /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
device.power = True
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])
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:
if enter_pressed:
enter_pressed = False
def usage():
print("usage: /dev/input/event?")
if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
Description=lifx remote on %I
ExecStart=/usr/local/bin/ /%I
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment