Lightify plugin/script
Posted: Sun Nov 25, 2018 2:00 pm
Hi,
I am currently trying out some Osram lightify bulbs as got them on special offer.
I've managed to find a python module (https://github.com/tfriedel/python-lightify) and it loads into EG fine and I can control them and query the status of them with EG via python script.
What would be great is a plugin or maybe a start up script (as you did for me for Yeelight @kgschlosser) so I can get events in the log whenever the bulbs status changes.
Discovery is different in Lightify to Yeelight though
Thanks in advance
I am currently trying out some Osram lightify bulbs as got them on special offer.
I've managed to find a python module (https://github.com/tfriedel/python-lightify) and it loads into EG fine and I can control them and query the status of them with EG via python script.
What would be great is a plugin or maybe a start up script (as you did for me for Yeelight @kgschlosser) so I can get events in the log whenever the bulbs status changes.
Discovery is different in Lightify to Yeelight though
kgschlosser wrote: Fri Dec 29, 2017 9:32 pm heh ooops.
Code: Select all
import threading class Yeelight(object): def __init__(self): # this is where you want to add the bulb entries. it has to be laid out # exactly like you see below self.bulbs = { 'LivingRoom.Light': { 'ip': '192.168.1.212', 'current_state': {} }, # example addition # 'SomeNew.Light': { # 'ip': '192.168.1.1', # 'current_state': {} # }, } self._event = None self._thread = None def start(self): if self._thread is None: self._event = threading.Event() self._thread = threading.Thread(target=self.run) self._thread.daemon = True self._thread.start() def stop(self): if self._event is not None: self._event.set() self._thread.join(3.0) def run(self): from yeelight import Bulb for bulb_name, bulb_params in self.bulbs.items(): try: bulb = Bulb(bulb_params['ip']) bulb_params['current_state'] = bulb.get_properties() except: eg.PrintError( 'Yeelight bulb {0} is not connecting on ip {1}.'.format( bulb_name, bulb_params['ip'] ) ) eg.PrintError('Removing bulb from being polled') del self.bulbs[bulb_name] while not self._event.isSet(): for bulb_name, bulb_params in self.bulbs.items(): try: bulb = Bulb(bulb_params['ip']) current_state = bulb.get_properties() for key, value in current_state.items(): if ( key not in bulb_params['current_state'] or value != bulb_params['current_state'][key] ): eg.TriggerEvent( prefix='Yeelight', suffix='{0}.{1}.{2}'.format( bulb_name, key, value ), payload=value ) bulb_params['current_state'][key] = value except: eg.PrintError( 'Yeelight bulb {0} is not connecting on ip {1}.'.format( bulb_name, bulb_params['ip'] ) ) eg.PrintError('Removing bulb from being polled') del self.bulbs[bulb_name] self._event.wait(0.15) self._event = None self._thread = None def send(self, name, **params): # i do not know how to change states or whatever else # if you provide me this information i can add it here pass def get(self, name, params=None): if params is None: from copy import deepcopy return deepcopy(self.bulbs[name]['current_state']) if isinstance(params, (list, tuple)): res = {} bulb = self.bulbs[name] for key in params: if key in bulb['current_state']: res[key] = bulb['current_state'][key] else: res[key] = None return res else: if param in self.bulbs[name]['current_state']: return self.bulbs[name]['current_state'][param] eg.globals.yeelight = Yeelight() eg.globals.yeelight.start() # if for some reason you want to stop the polling you need to call # eg.globals.yeelight.stop() # when you get me the information on how to send commands to the bulbs # it would get used by calling send # eg.globals.yeelight.send('LivingRoom.Light', command1=None, command2=None) # the thread is set up as a daemon thread so it will close all nice nice when # EG exits. # you can use the below mechanism to grab current status data # to get all statuses returned in a dict # eg.globals.yeelight.get('LivingRoom.Light') # to get a single status # eg.globals.yeelight.get('LivingRoom.Light', 'power') # to grab more then one status returned as a dict # eg.globals.yeelight.get('LivingRoom.Light', ['power', 'bright']) # if at any time there is no value for the status provided a # None will be returned for that status
Thanks in advance