Noob quick question: sendEvent

I made sure to search through some already posted threads and the IDE documentation before asking this because I know it’s an extremely simple and nooby question, just asking for clarification. First response will probably be marked as the solution and we can move on and be happy.

The sendEvent function…I’ve been playing around with the deviceType code for my bulbs trying to understand how it all works. So far I’m pretty comfortable with everything in there…EXCEPT sendEvent. Which, seeing how often it’s used, OBVIOUSLY it’s key to all things SmartThings lol.

Is SendEvent just a method for devices and SmartApps for notifying the ST hub of events for other devices and SmartApps to react to?

Like if I have an off() function in the DeviceType code…but I don’t send the event for it turning off…then if I were to have a SmartApp that does something when that bulb turns off, it won’t work because it didn’t see the event?

Just came across the getting started section of the IDE documentation…I guess I should start there lol. I’m just used to jumping straight into code and learning that way…but not all of this stuff seems to be as self explanatory as some other standard programming languages.

Apologies for posting up nooby questions, just looking for a quick answer I guess.

1 Like

Yes, you have the right idea. Device types send events based on their parse of messages from the device itself. In general, the sequence is device does something (senses, turns on, or …) and sends a message to the hub via z-wave or zigbee. The device type associated with that device parses the message, and sends events out reflecting what happened. These events are used by the device type itself to update its tiles should you look at the device on the mobile app.

1 Like

Thanks!! That helped a lot.

It made A LOT more sense when I found the Subscribe function.

One thing I found is that in the generic zigbee color temp bulb device type for my OSRAM bulbs, it only has a handful of sendEvent function calls in it and it uses all zigbee.whatever commands. But the actual OSRAM bulb device type uses the sendEvent commands all over the place and uses cmds to control the device. Does the zigbee object automatically send out events when it’s functions are used, so the sendEvent function isn’t needed?

If I’m asking questions that are way ahead of me, or I’m way off track, feel free to just tell me to RTFM lol.

ST recently updated the zigbee framework with helper commands to streamline code and make it easier to develop new devicetypes. The generic zigbee color temp code uses this new framework (it does not automatically sendEvents), which also includes a helper for parse, so they can dynamically create events for multiple capabilities from one command. The Osram one was first built before that was available.

Along with that change there was a shift in the placement/use of sendEvent. They now recommend that sendEvent mainly be used in the parse section (i.e. Triggered by messages from the device). This makes sense to keep the app state the same as the physical device. In case of a command that didn’t reach the device, the state wouldn’t get out of sync because it doesn’t change until the device responds.

The old way you usually put sendEvent directly in the command method and assume the device will receive the command and match what you’ve sent it. Then parse was used to update events when refreshed or changed outside of the ST framework (physical switch or direct remote maybe).

New way should better match ST state with physical state, but is dependent on the hardware/firmware of the device to report state changes and could add minor lag to event updates. Old way was in the fire and assume mindset and could result in lots of events if the device did report state changes. You’d send the event in the command, then the device would report back and you’d get the same event. ST ignores duplicates, but it could add load to the servers.

1 Like