Over the last days I’ve added support for the
UPnP Lighting Controls V 1.0 to
Coherence.
Although there aren’t yet much application areas for this specification outside of maybe some futuristic showrooms and research laboratories - and here at my place with my little UPnP <-> EIB bridge - but that specification addresses one of the biggest obstacles when it comes to home-automation.
The need to know/to program the unique id of a new device you bring into your household and to establish the connection between a switch and that device, is in all serious automation systems diametrically opposed to the wish of the ordinary customer who just wants to buy a new lamp, plug it in and have it working.
Newer systems like digitalstrom or ZigBee take that (partially) into account, but here too UPnP has the potential to model a unified layer above the system and vendor specific peculiarities.
And having that in Coherence is a nice demonstration of the simplicity implementing a device with it anyway.
class SimpleLight(Backend):
""" this is a backend for a simple light
that only can be switched on or off
therefore we need to inform Coherence
about the state, and a method to change it
everything else is done by Coherence
"""
implements = ['BinaryLight']
logCategory = 'simple_light'
def __init__(self, server, **kwargs):
self.name = kwargs.get('name','SimpleLight')
self.server = server
self.state = 0 # we start switched off
louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
def upnp_init(self):
if self.server:
self.server.switch_power_server.set_variable(0, 'Target', self.state)
self.server.switch_power_server.set_variable(0, 'Status', self.state)
def upnp_SetTarget(self,**kwargs):
self.info('upnp_SetTarget %r', kwargs)
self.state = int(kwargs['NewTargetValue'])
if self.server:
self.server.switch_power_server.set_variable(0, 'Target', self.state)
self.server.switch_power_server.set_variable(0, 'Status', self.state)
print "we have been switched to state", self.state
return {}
Yep, that’s all. :-)
From the three UPnP actions the SwitchPower service defines,
only one is actually needed to implement, the other two actions can be handled by Coherence autonomously.