Scenario:
- The "Thermometer" thing has a "temperatureChanged" event with a float value
- The "Airconditioner" thing has "start" and "stop" methods which control the on/off state of an air conditioner
- A "startStopAirconditioner" trigger is to be created which activates from the "temperatureChanged" event
- The trigger logic contains code to start/stop Airconditioner if the temperature value goes above/below 30
Prerequisites:
- A "Thermometer" thing with a float property "Temperature" was created in the Create, Read And Write Property example
- A "temperatureChanged" event with a float value was added to the "Thermometer" thing in the Create Event And Trigger example
- 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
1. Create "startStopAirconditioner" trigger
- Open "Triggers" in the "Thing: Thermometer" tab
- Click "New" to open "Create Script Trigger" dialog
- Set name to "startStopAirconditioner"
- Set "temperatureChanged" as the event used for the trigger
- Save trigger by clicking "Save"
This new trigger will now be activated whenever a "temperatureChanged" event occurs
2. Code "startStopAirconditioner" logic
- Open "Triggers" again in the "Thing: Thermometer" tab
- Select "startStopAirconditioner"
- Click "Edit Script" button to open "Edit Script Trigger" dialog
-
Insert the following script in the text area:
-
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
- Click "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 "Airconditioner" is started/stopped)
4. 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: