The web thing API packages are designed to be primarily used for writing out, since you should know more about when exactly these state transitions happen. So you’d do it there.
If you’re talking about doing something that involves multiple devices, you should check out rules in the gateway, where you can define a condition and actions.
Thanks for replying. I’ve got this so far, all I want is to see the debug output ‘get’ / ‘set’ to be displayed but this isn’t happening. I’m new to this sorry, where am I going wrong?
Many thanks.
class LightThing(Thing):
def __init__(self):
Thing.__init__(self,
'Light Thing',
['OnOffSwitch', 'Light'],
'A web connected light thing')
self.state = False
self.add_property(
Property(self,
'on',
Value(self.get_state(), self.set_state()),
metadata={
'@type': 'OnOffProperty',
'title': 'On/Off',
'type': 'boolean',
'description': 'Whether the lamp is turned on'
}))
def get_state(self):
logging.debug("get")
return True
def set_state(self):
logging.debug("set")
I tested that today by chance. Or better I stumbled over it.
You have to add a parameter like this:set_state(self, value)
value will be the state of your property.
An OnOffProperty has 'type':'boolean' so value will be True or False depending on the state of the gateway UI button.
you can add this to the Multiplething Example in line 101: