Skip to content

Instantly share code, notes, and snippets.

@stigtsp
Created November 30, 2016 07:44
Show Gist options
  • Save stigtsp/fd7160850df4f26a13fd693f6d009af4 to your computer and use it in GitHub Desktop.
Save stigtsp/fd7160850df4f26a13fd693f6d009af4 to your computer and use it in GitHub Desktop.
Is anyone at Dim Sum labs? This Bitbar scripts will tell you if the lights are on, and what rgb value the light has.
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import paho.mqtt.client as mqtt
import json
import struct
def on_connect(client, userdata, flags, rc):
client.subscribe("dsl/enviro")
def on_message(client, userdata, msg):
s = json.loads(str(msg.payload))
col = struct.pack('BBB',*s['rgb']).encode('hex')
lights="💤"
if s['helios']>0: lights ="💡"
print "DSL"+lights+" | color: #" + col
exit()
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("iot.eclipse.org", 1883, 60)
client.loop_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment