Triggers on state of my custom device do not fire

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Fri Jun 03, 2011 11:28 am
donhoffman offline
Posts: 51
Joined: May 26, 2011
Location: Portland, OR and Livingston, MT

Triggers on state of my custom device do not fire

As a way to get started with plugins I wrote a plugin for a homebrew keypad controller that connects to computer via RS232. The controller has ports for two keypads and uses an old Basic Stamp to scan the keypads for digits entered and send the digit string to the PC in a well known format on entry of #. I built the thing in the late-'90s and it is currently connected to an old Stargate HA controller.

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))

Posted on
Fri Jun 03, 2011 11:52 am
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Triggers on state of my custom device do not fire

If you select the device in the device table in the Home Window, do you see the "lastKeypadCode" state listed in the "States" box in the control area below the device list? Do you see the state value change?

I don't know what self.devMap is, but if you don't see the state change above then you should make sure that what's stored in there is an actual device reference.

You shouldn't need to do anything else aside from calling updateStateOnServer().

Also note - if you created the devices before you defined "lastKeypadCode" as a state, or if you renamed the state, then you'll need to recreate the device - states are added to the Indigo DB at device creation time and don't change at runtime.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jun 03, 2011 12:10 pm
donhoffman offline
Posts: 51
Joined: May 26, 2011
Location: Portland, OR and Livingston, MT

Re: Triggers on state of my custom device do not fire

jay wrote:
If you select the device in the device table in the Home Window, do you see the "lastKeypadCode" state listed in the "States" box in the control area below the device list? Do you see the state value change?


Yes. Everything is as expected. I see the the state variable in the box near the bottom of the window and the new value changes instantly after the expected string from the controller has arrived.

I don't know what self.devMap is, but if you don't see the state change above then you should make sure that what's stored in there is an actual device reference.
You shouldn't need to do anything else aside from calling updateStateOnServer().


That was saved from the device start so I had a device reference in the background thread. Since the device does update as mentioned above, I assume the dev reference is correct. Here is where it is set:
Code: Select all
    def deviceStartComm(self, dev):
        self.debugLog(u"<<-- entering deviceStartComm: %s (%s - %s)" % (dev.name, dev.id, dev.deviceTypeId))
        self.debugLog(u"keypad port: %s" % (dev.pluginProps["keypadPort"]) )
        self.devMap[dev.pluginProps["keypadPort"]] = dev
        dev.updateStateOnServer(key="lastKeypadCode", value=0)
        self.debugLog(u"exiting deviceStartComm -->>")



Also note - if you created the devices before you defined "lastKeypadCode" as a state, or if you renamed the state, then you'll need to recreate the device - states are added to the Indigo DB at device creation time and don't change at runtime.


Yes, I deleted the devices and recreated them each time I made such code changes and just now did it once more for grins just to be sure, without making any code changes.

BTW, this is running on Beta 5. Also, I can email you a zip of the whole plugin if that is useful.

Posted on
Fri Jun 03, 2011 2:47 pm
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Triggers on state of my custom device do not fire

You can zip up the plugin and send it to indigo DASH support AT perceptiveautomation DOT com. I'll take a look at it when I get the chance, though may not be able to replicate it given I don't have hardware.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jun 03, 2011 3:39 pm
donhoffman offline
Posts: 51
Joined: May 26, 2011
Location: Portland, OR and Livingston, MT

Re: Triggers on state of my custom device do not fire

Will do so tonight. You can test it just by typing something like "keypad door1=1234" in to the serial port via a terminal program connected to the serial port from another computer. I have also faked input by just generating a string every 30 seconds in the runConcurrentThread().

One other strange thing. In the trigger, it says:

Code: Select all
Trigger: "Keypad 1" onOffState becomes equal to 1234"


The use of the term "onOffState" seems strange there. Is that what it is supposed to say?

Thanks for looking in to this.

Posted on
Fri Jun 03, 2011 4:43 pm
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Triggers on state of my custom device do not fire

We appear to have a little buglet - when you first select your keypad device, if you don't select a state (the only one in your plugin, "Last Keypad Code"), the dialog for some reason believes the state is onOffState - which of course you don't support. The workaround until we can get the fix in is to just click on the state popup - even though there's only one entry, it's enough to get the Cocoa bindings to update the underlying field and you should be good to go… ;)

Instead of onOffState, it should show lastKeypadCode. Thanks for the bug report!

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jun 03, 2011 5:25 pm
donhoffman offline
Posts: 51
Joined: May 26, 2011
Location: Portland, OR and Livingston, MT

Re: Triggers on state of my custom device do not fire

That fixed it. Thanks.

Now I need to fix my own bug where the same code entered in succession does not trigger after the first time. Plus the two you pointed out via email. :roll:

Must say, other than this minor issue, it is almost trivially easy to do a plugin. Might want to make available a simpler example than EasyDAQ for serial programming. My own plugin is less than a few dozen lines of real code (minus logging + some more robust error checking and input validation per your input). The other plugins I can probably knock off in less than a day each now that I have the pattern.

Thanks again.

Posted on
Fri Jun 03, 2011 8:47 pm
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Triggers on state of my custom device do not fire

No problem - we spent a bunch of time and iterations over the last year really trying to make sure we got it as right as we could. Not that there aren't improvements that can be made - but I think we're moving in the right direction and have a very solid base to work from.

Yeah, a simpler serial example would be great - maybe once you have this one polished up it can serve as that example.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 22, 2011 4:00 pm
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Triggers on state of my custom device do not fire

The next beta will fix the state bug mentioned above. Try it out and let us know if we missed something.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest