Timer Service

The timer service allows a workflow to request a countdown timer.  When the timer reaches zero, the timer service will send a callback event which can be used to trigger a workflow. 

You can reset a specific timer service to restart the countdown timer and you can have multiple timer services per device at any moment.

This service is especially useful to trigger when a device goes offline as it is refreshed as long as the device is transmitting data. 

 

Activate Timer Service

Before you can use the timer service, you'll need to request a timer service access token from Medium One at support@mediumone.com.

 

 

Add Alarm

Summary

  • Endpoint: https://timer.mediumone.com/add_alarm
  • Method: POST
  • Credit cost: 1

Body

All parameters are required.

  • token: str|unicode Medium One timer service access token (provided by Medium One)
  • callback_stream: str|unicode stream for callback event; make sure the stream exists
  • callback_tag: str|unicode tag for callback event
  • callback_msg: str|unicode value associated with callback tag
  • callback_device_id: str|unicode API basic user associated with callback event; make sure the user exists.
  • rule_name: str|unicode timer rule name; needs to be unique per device, unless you are resetting the timer
  • time: int seconds to wait before sending event

Response

A successful response contains the expiration time of the timer in seconds since the epoch

 

Example


import HTTP
import json callback_device_id = "test_device"
time = 60 # 60 seconds
url = "https://timer.mediumone.com/add_alarm"
header = {"Accept":"application/json","Content-Type":"application/json"}
body = {"token": "1234567", "callback_stream": "m1_timer_test","callback_tag": "m1_test", "callback_msg": "This works!" ,"callback_device_id": "test_device", "rule_name": "test_rule","time": time}
response = HTTP.post(url, json.dumps(body), None, None, 5000, header, 'utf-8', True)