Not understanding "sendEvent"

In the driver I'm learning from (ported ST dimmer switch) there is a function I can't quite grasp.

I understand the "def installed()" is called when a device is discovered and installed.

I believe the sendEvent( name: ...........) is trying to create an event (that will run in the executive program) to generate a periodic action that will ping the installed device.

I don't understand:

  1. How the driver can use "sendEvent" instead of "createEvent" unless "sendEvent" defaults to "create" if there sent event does not exist.

  2. The function of the last line "response(commands)"

Any help will be appreciated.


def installed() {
// Device-Watch simply pings if no device events received for 32 min(checkInterval)
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"])
def commands = refresh()
if (zwaveInfo?.mfr?.equals("001A")) {
commands << "delay 100"
//for Eaton dimmers parameter 7 is ramp time. We set it to 1s for devices to work correctly with local execution
commands << zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 7, size: 1).format()
} // deleted: else if (isHoneywellDimmer())

I might not get this completly correct as I despise createEvent.
CreateEvent is a wrapper for sendEvent.
Think of createEvent as a helper function which returns a sendevent method, vs sendEvent which is more of a procedure since it doesn't return anything.
I prefer sendEvent since it offers explicit control of all the event parameters.
I think create event does as well but I don't like it, too auto magic for me.

1 Like

It was my understanding that you were supposed to use createEvent() in the parse() routine of a driver. SendEvent() was to be used outside of the parse() routine.