SendEvents not Firing or Working - Help!

First time developer to ST, but not to the world of developing. What am I doing wrong here (link below)?

Working on a custom device handler. the switch on() and off() fire and control the pump, but I can’t get any state change that I want on any tile.

The intended design is using turningOn and TurningOff as indicators that I pressed the button, and allowing the polling mechanism of the http request to verify device RPM before setting the switch state to truly on or off.

I had this working at one point, but now messed up. something changed or happened after I had uninstalled/reinstalled the handler.

It’s a work in progress with a lot of commented out items and log.debug/ for troubleshooting.

Most currently troubleshooting Line 223 because it won’t fire to set the details to the ValueTile. I want to update the valuetile with the text output from the json. I took out the RPM logic around those lines to change the on/off for the primary switch as it wasn’t working either. Diagnosis confirms json does exist and variables set correctly.

Further diagnosis and copy/paste of a simple sendEvent to force the switch on/off doesn’t work either. I’ve even placed in the on() and off() routines and still won’t change state from the turning(on/off).

I’m baffled. So in summary, no switch change states, and no value tile data at all.

OK. Firstly have you come across which is the capabilities reference for use with the Classic app? In it you will see the attributes available for each capability and their permitted values. This is important because the attributes are the ‘state’ of the device.

With the code as it is as I write your only attribute is ‘switch’ from the Switch capability so you have the options of sendEvent(name: "switch", value: "on") or sendEvent(name: "switch", value: "off").

Just to clarify, “name” is the name of an attribute of your device that is either standard with the capabilities you have defined, or defined as a custom attribute (see below).

When it comes to your standardTile and valueTile definitions, the second argument is also the attribute/state that you are working with so again all you have is "device.switch" available to you.

Again, just to clarify, the “tiles” section defines the UI for the mobile app. You can think of it like providing the code for a web page with the mobile app being the browser. That’s why you can put any syntactically correct stuff in there without anything complaining.

For your valueTile, what you probably want to do is add a custom attribute. For example after your capability definitions you could add the line attribute "pump", "string" and then you would be able to have "device.pump" as the second argument to your valueTile and set the attribute/state with sendEvent(name: "pump", value: "your text") .

I’m not really sure where you are going with the ‘refresh1’ tile. The refresh capability doesn’t have any attribute/state so you won’t get any joy with "device.refresh" or the various sendEvent commands. If you want to make your code work you could try adding attribute "refresh", "enum", ["active", "idle"] and using sendEvent(name: "refresh", value: "active") or sendEvent(name: "refresh", value: "idle").

I think I’ve got that right.

1 Like

Thanks. still having problems. oddly, the first time I read your comments, and implemented the changes, it worked. Then I removed the device, and readded it, and now I’m back to the same issues as described before - it’s as if state changes are not being recognized and value text not being updated. At that point, I went ahead and made additional changes to remove refresh stuff and unnecessary commented features and to document intended behavior in parse() for switch on/off (which I had before but just not in git repo).

I’ve uploaded my changes to the repository.

any suggestions? Could this be some sort of ST bug?

Update - I haven’t changed the code at all today after this post, and miraculously the on/off switches and value text are working now. I think there’s a ST bug here. I’ll continue to monitor.