So writing plugin was easy and it mostly works except for the most important part. The triggers I set that are intended to match the device state change never fire. So, for example, if the user enters 1234 on keypad, the state variable "lastKeypadCode" gets set to 1234. I create a trigger for that device that matches on the value becoming 1234. I see the changes in the state variable on the server UI for that device and the expected log messages, but I never see the trigger action (I just toggle an Insteon light for now). The trigger runs fine when manually set off via the button in the Indigo UI.
In the version below, I modeled the state value as an integer, but also tried it as a string. Neither worked.
Is this a bug, feature, or is there some other operation I need to do in addition to updateStateOnServer to get the triggers to fire?
Here is my Devices.xml:
- Code: Select all
<?xml version="1.0"?>
<Devices>
<Device type="custom" id="keypadRS232">
<Name>Custom RS232 Keypad Controller</Name>
<ConfigUI>
<Field type="menu" id="keypadPort">
<Label>Keypad Location:</Label>
<List>
<Option value="keypad1">Keypad Port 1</Option>
<Option value="keypad2">Keypad Port 2</Option>
</List>
</Field>
</ConfigUI>
<States>
<State id="lastKeypadCode">
<ValueType>Integer</ValueType>
<TriggerLabel>Last Keypad Code</TriggerLabel>
<TriggerLabelPrefix>Last code entered was</TriggerLabelPrefix>
<ControlPageLabel>Last Keypad Code</ControlPageLabel>
<ControlPageLabelPrefix>Last code entered was</ControlPageLabelPrefix>
</State>
</States>
</Device>
</Devices>
Here is the relevant code section:
- Code: Select all
def _processLine(self, line):
line.strip()
self.debugLog(u"Received line: %s" % (line))
if line.startswith("keypad door1="):
code = int(line[13:])
self.debugLog("Door 1 code entered: %d" % (code))
if "keypad1" in self.devMap:
self.devMap["keypad1"].updateStateOnServer(key="lastKeypadCode", value=code)
else:
self.errorLog(u"Can't find device for keypad 1")
elif line.startswith("keypad door2="):
code = int(line[13:])
self.debugLog("Door 2 code entered: %d" % (code))
if "keypad2" in self.devMap:
self.devMap["keypad2"].updateStateOnServer(key="lastKeypadCode", value=code)
else:
self.errorLog(u"Can't find device for keypad 2")
else:
self.errorLog(u"Unknown input string: %s" % (line))