Skip to end of metadata
Go to start of metadata

Scenario

  1. The "Thermometer" thing has a "temperatureChanged" event with a float value
  2. The "Airconditioner" thing has "start" and "stop" methods which control the on/off state of an air conditioner
  3. A "startStopAirconditioner" trigger is to be created which activates from the "temperatureChanged" event 
  4. The trigger logic contains code to start/stop Airconditioner if the temperature value goes above/below 30

Prerequisites

  1. A "Thermometer" thing with a float property "Temperature" was created in the Create, Read And Write Property example
  2. A "temperatureChanged" event with a float value was added to the "Thermometer" thing in the Create Event And Trigger example
  3. An "Airconditioner" thing with "start" and "stop" methods was created in Create and Execute Method example

Steps

 For a complete description of all the settings used for the dialog boxes in this tutorial, see Thing Event Settings and Thing Trigger Settings

1. Create "startStopAirconditioner" trigger


  1. Open "Triggers" in the "Thing: Thermometer" tab
  2. Click "New" to open "Create Script Trigger" dialog
  3. Set name to "startStopAirconditioner"
  4. Set "temperatureChanged" as the event used for the trigger
  5. Save trigger by clicking "Save"

This new trigger will now be activated whenever a "temperatureChanged" event occurs

2. Code "startStopAirconditioner" logic


  1. Open "Triggers" again in the "Thing: Thermometer" tab
  2. Select "startStopAirconditioner"
  3. Click "Edit Script" button to open "Edit Script Trigger" dialog
  4. Insert the following script in the text area:

  5. Save the trigger script by clicking "Save"

The trigger logic will activate the "start" or "stop" methods for "Airconditioner" depending on whether the temperature value is greater or less than 30

The "start" or "stop" methods of "Airconditioner" will only start/stop "Airconditioner" if it is not already started/stopped

To check out more coding options for events and triggers, see

3. Fire "temperatureChanged" event using UI


  1. Click "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 "Airconditioner" is started/stopped)

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