ThingWorx Model Definition and Composer > Things > Thing Events
  
Thing Events
Events are interesting or critical property states that the Thing publishes to subscribers. They are initiators to kick off some functionality in a subscription, which is basically a triggered service. Within a service definition, if you double click the event, the script necessary to fire the event will be stubbed out in the service for you. Triggers are well-defined changes of state (for example, Motor is overheating) of an asset or system (a Thing) and often require an action to correct or respond to the change (for example, Display warning light to show that the tractor is overheating). Complex predictions from analytical algorithms can fire events and allow the application developer to react to those events with business logic.
Business logic and actions in a ThingWorx application are driven by events. An event can be as simple as a new data value from a machine to more complex events from many data points and their dependencies. For example, ThingWorx Analytics real-time scoring predicts a failure and fires an event to the IoT run-time engine so you can take action. Events can be fired through API requests from a user in an application, or a device can fire its own events based on local data analysis or diagnostic routines.
There should be a subscriber to the event in the model. The subscriber is sent a data packet and the subscription is initiated. If no one is subscribed to the event (no one is listening), nothing happens.
In ThingWorx, there are standard events and related data packets (as defined by Data Shapes). The most common type of event is a data change related to a Thing property. When you define a property, there are many configuration aspects. For example, using DataChangeEvent, you can set an event to fire when there is new data for a property, only if the data has changed, only if the data evaluates true or false, or only if the new value changed beyond a defined threshold. All data change events send a data packet with the same predefined Data Shape.
You can create custom events in your model. For example, you may have a machine that runs diagnostic checks. When the diagnostic check determines that the machine needs to be calibrated, you can create a custom calibration alert for that class of equipment (usually at the Thing Shape or Thing Template level). In the definition, you can create a Data Shape that contains the data from the machine needed to take action. You can configure the machine agent to fire that event through the ThingWorx API when the condition is detected. In the subscription, you can implement business logic to respond to the event. You can also fire events through the standard ThingWorx REST API, so that Mashups and custom applications can trigger events through ThingWorx Analytics.
ThingWorx Analytics can examine data and figure out anomalous behaviors, or it can be trained by historical data. It can use real-time data from ThingWorx to predict outcomes. A basic example is predictive analytics. You can train the analytics engine for a class of equipment based on historical data, including failure information. You can send run-time data from individual Things to the analytics engine. If it detects a pattern that led to a past failure, it can fire an event to that Thing and allow you to take action through a subscription. That action could be to create a service ticket or send a notification to the service department. Alerts or subscriptions to custom events allow you to link specific action and business logic to near real-time events.