Skip to end of metadata
Go to start of metadata

Scenario:

  1. We have a "Thermometer" thing with a float property "Temperature" 
  2. A "temperatureChanged" event will be created here which refers to a float value
  3. A "highTemperatureEmail" trigger is also created to activate from this "temperatureChanged" event
  4. The trigger logic will be executed whenever a "temperatureChanged" event occurs
  5. The trigger logic contains code to send an email if the temperature is higher than 30

Prerequisites:

  1. A "Thermometer" thing with a float property "Temperature" was created in the Create, Read And Write Property scenario
  2. An event can be activated either by UI, API, script property, method logic, another trigger, or schedule
  3. A reference value must be entered whenever an event is activated based on the given data type of the event
  4. A float temperature value is set in the "temperatureChanged" event when its activated
  5. 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


  1. In the "Thing: Thermometer" tab, open "Events"
  2. Click "New" to open "Create Event" dialog
  3. Set name to "temperatureChanged"
  4. Select "float" as the data type for this event
  5. Save event

2. Create "highTemperatureEmail" trigger


  1. Open "Triggers" in the "Thing: Thermometer" tab
  2. Click "New" to open "Create Script Trigger" dialog
  3. Set name to "highTemperatureEmail"
  4. Select "temperatureChanged" as the event used for the trigger
  5. 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


  1. Open "Triggers" again in the "Thing: Thermometer" tab
  2. Select "highTemperatureEmail"
  3. Click "Edit Script" button to open "Edit Script Trigger" dialog

  4. Insert the following script in the text area (email name may be edited):

  5. 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


  1. Open "Events" in the "Thing: Thermometer" tab
  2. Select "temperatureChanged"
  3. Click "Push Event" to open dialog
  4. Set event details (the float "value" may be edited)
  5. Click "Push" to activate the event and its trigger
  6. 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


  1. 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
  2. Obtain required parameters:
    • To obtain the Thing Id, see instructions here.
    • Obtain "temperatureChanged" event Id. See instructions here.
    • To create an API Key, see instructions here.

      4. Use API Explorer to perform REST calls using UI
      5. Use cURL to perform REST calls using command line:

 

 

  • No labels