Scenario:
- We have a "Thermometer" thing with a float property "Temperature"
- A "temperatureChanged" event will be created here which refers to a float value
- A "highTemperatureEmail" trigger is also created to activate from this "temperatureChanged" event
- The trigger logic will be executed whenever a "temperatureChanged" event occurs
- The trigger logic contains code to send an email if the temperature is higher than 30
Prerequisites:
- A "Thermometer" thing with a float property "Temperature" was created in the Create, Read And Write Property scenario
- An event can be activated either by UI, API, script property, method logic, another trigger, or schedule
- A reference value must be entered whenever an event is activated based on the given data type of the event
- A float temperature value is set in the "temperatureChanged" event when its activated
- Anytime an event is activated, a timestamp is included to keep track of the timing for possible use on charts or data logs
Steps:
For a complete description of all the settings used for events and event triggers in this tutorial, see Thing Event Settings and Thing Trigger Settings.
1. Create "temperatureChanged" event
- In the "Thing: Thermometer" tab, open "Events"
- Click "New" to open "Create Event" dialog
- Set name to "temperatureChanged"
- Select "float" as the data type for this event
- Save event
2. Create "highTemperatureEmail" trigger
- Open "Triggers" in the "Thing: Thermometer" tab
- Click "New" to open "Create Script Trigger" dialog
- Set name to "highTemperatureEmail"
- Select "temperatureChanged" as the event used for the trigger
- Save trigger by clicking "Save"
Note: Activating the selected event causes the trigger action (sending email, etc.) The trigger does not activate the event.
3. Code"highTemperatureEmail" logic
- Open "Triggers" again in the "Thing: Thermometer" tab
- Select "highTemperatureEmail"
-
Click "Edit Script" button to open "Edit Script Trigger" dialog
-
Insert the following script in the text area (email name may be edited):
- Save the trigger script by clicking "Save"
The trigger logic will send an email if a "temperatureChanged" event occurs and the temperature value is greater than 30
To check out more coding options for events and triggers, see:
4. Fire "temperatureChanged" event using UI
- Open "Events" in the "Thing: Thermometer" tab
- Select "temperatureChanged"
- Click "Push Event" to open dialog
- Set event details (the float "value" may be edited)
- Click "Push" to activate the event and its trigger
- Check if an email was sent (an email is sent only if the temperature value is greater than 30)
5. Fire "temperatureChanged" event using REST API
- Check out the GadgetkeeperAPI - Datapoints page for details on how to fire an event (create datapoint) on GadgetKeeper API using cURL or a REST API tool
- Obtain required parameters:
4. Use API Explorer to perform REST calls using UI
5. Use cURL to perform REST calls using command line: