Scheduling
The Internet of Things (IoT) primarily involves devices connected to the Internet, enabling data exchange such as telemetry and commands. However, many applications require automation where devices can operate independently.
In line with the rest of the ESP RainMaker features, scheduling has been implemented completely on the node side in the form of a "service". The cloud backend just acts as a gateway between the node and the clients (like Phone apps).
The entire complexity of the scheduling feature is hidden beneath a simple C API and also abstracted out by the phone apps.
Use Case
ESP RainMaker’s scheduling feature enables automated control of devices based on predefined times, enhancing convenience and energy efficiency. Users can set schedules for tasks like turning lights on at 6 p.m. and off at 11 p.m. without manual intervention. This allows seamless automation for smart homes and industrial setups, optimizing power usage
Features of Scheduling
- Perform an action at a given absolute time with configuration for:
- One time (Eg. 6:30pm)
- Repeat on specific day(s) of the week (Eg. 6:30pm on Mon, Tue, Sat)
- Repeat on specific date(s) of specified month(s) (Eg. 6:30pm on 20th of Jan, Aug, Dec)
- Repeat every year (Eg. 6:30 pm of 20th Jan every year)
- Perform an action after a specified period of time. (Eg. 3 hours from now)
- Extensible by adding custom info and flags to help apps identify and segregate different types of schedules. (Eg. pre-defined schedules, default on-off schedules, etc.)
- Handling of Day Light Savings (DST) offsets as applicable for the configured timezone. Check Managing Daylight Saving Time (DST) section for more information.
Scheduling comes hand in hand with time service. Therefore, it is mandatory to set up and configure time service. If not schedule will not trigger.
Specifications
The scheduling service consists of a single parameter which is an array of objects. Enabling the feature adds the following service in the node configuration:
JSON Payload (Toggle View)
{
"name": "Schedule",
"params": [{
"bounds": {
"max": 5
},
"data_type": "array",
"name": "Schedules",
"properties": [
"read",
"write"
],
"type": "esp.param.schedules"
}],
"type": "esp.service.schedule"
}
The schedule parameter is an empty array by default. The "max" bound indicates the maximum number of schedules a node can have.
Add a New Schedule
A new schedule can be added by passing a value like this in setparams
. This is usually sent from the client side to the cloud or directly to the node via local control.
JSON Payload (Toggle View)
{
"Schedule": {
"Schedules": [{
"name": "Evening",
"id": "8D36",
"operation": "add",
"triggers": [{
"d": 31,
"m": 1110
}],
"action": {
"Light": {
"power": true
}
}
}]
}
}
Detailed explanation of each JSON Key within the payload
- name (string): A user friendly name for the schedule.
- id (string): A unique ID for the schedule. (This needs to be unique only for the given user not universally unique). This should be generated by the client while adding a schedule, and then used for any further operations. A shorter ID is desirable.
- operation (string): The operation to be performed. Possible values are add, remove, edit, enable and disable.
- triggers (array of objects): The time at which the schedule should trigger. Either "m" or "rsec" should be provided.
- m (uint16): Minutes since midnight. Eg. 6:30pm = 18 * 60 + 30 = 1110. Either "d" or "dd" should be provided.
- d (uint8): Bitmap for days. LSB is Monday. [ N/A | Sunday | Saturday | Friday | Tuesday | Wednesday | Tuesday | Monday ]. Eg. 0b00011111 (31) means all weekdays. A value of zero means trigger just once.
- dd (uint8): Date (1-31).
- mm (uint16, Optional) : Bitmap for months. LSB is January. Eg.0b00000111 (7) means Jan, Feb, Mar.
- yy (uint16, Optional) : Year. Eg. 2023.
- r (bool, Optional):
true
for repeating every year.
- rsec (int32): Relative seconds starting from now. There is no day/date setting for this. Either "m" or "rsec" should be provided.
- m (uint16): Minutes since midnight. Eg. 6:30pm = 18 * 60 + 30 = 1110. Either "d" or "dd" should be provided.
- action (object): The actual action to be performed at the given time. The value of this object will be same as what you pass while setting the params. Eg. For turning on Light, it will be "Light":
{"power": true}
. - info (string, Optional): Additional info or description as per the clients' requirements.
- flags (uint32, Optional): General purpose flags (unsigned integer value) which can be used as per the clients' requirements.
- validity (object, Optional): To provide a start and end time between which the schedule should be applicable.
- start (uint32): Start time (epoch seconds) from which the schedule should be active.
- end (uint32): End time (epoch seconds) after which the schedule should be inactive.
Once the schedule is added successfully, a get on params will report a similar value as shown in JSON payload below:
- This is an acknowledgment response sent from the node to the cloud or to the phone app.
JSON Payload (Toggle View)
{
"Schedule": {
"Schedules": [{
"name": "Evening",
"id": "8D36",
"enabled": true,
"triggers": [{
"d": 31,
"m": 1110
}],
"action": {
"Light": {
"power": true
}
}
}]
}
}
As you can see, the response includes an "enabled" key, which indicates that the schedule is now enabled.
While adding or updating schedules, a single entry is sent in the schedules array. However, when queried, the node will return information of all the schedules in the array.