# Schedules

### Create Schedule

*Scope: Basic*

*Request URL:*

```
POST /schedules
```

*Headers:*

```
Content-Type: application/json
Authorization: Bearer {access_token}
```

*Body*:

```
{
    "controller_id": "G********H3",// serial number of the device
	"days" : "0000010",// days of week you want the schedule to be active
    "active": 1,
    "from_time": 650, //time formula:(H)*60+(min)/10:50 =>10*60= 600 + 60 = 650
    "to_time": 700, //time formula:(H)*60+(min)/11:40 =>11*60= 660 + 40 = 700
    "device_hours": 14, // device hours at the moment of creatio
    "action": "command", //thermostat mode or command
    "target": 24, // target temperature or state// integer//
                     for smart plug or bobbie 0- off, 1 - on
    "push":1 // 1/0 for push notification
    "default_state": "do_nothing"// not working for vicki /"on","off","do_nothing" 
      // when schedule ends, what state you want to set the device, its for melissa bobbie smartplug
}
```

*Response:*

```
{
    "schedules": {
        "controller_id": 1******,
        "days": "0000010",
        "active": 1,
        "from_time": "2021-05-29 10:50:00",
        "to_time": "2021-05-29 11:40:00",
        "action": "command",
        "target": 24,
        "push": 1,
        "user_time_offset": null,
        "id": 21
    },
    "_links": {
        "self": {
            "href": "/v1/schedules"
        }
    }
}
```

### Fetch Controller's Schedule

*Scope: Trusted*

*Request URL:*

```
GET /schedules/{Controller Serial Number}
```

*Headers:*

```
Content-Type: application/json
Authorization: Bearer {access_token}
```

*Response:*

```
{
    "_embedded": {
        "schedules": [
            {
               ...
            },
            {
                ...
            },
            {
                "controller_id": 1****,
                "from_time": "2021-05-29 10:50:00",
                "to_time": "2021-05-29 11:40:00",
                "days": "0000010",
                "target": 24,
                "main_target": null,
                "default_state": "do_nothing",
                "action": "command",
                "priority": 0,
                "active": 1,
                "push": 1,
                "user_time_offset": null,
                "id": 21,
                "_links": {
                    "self": {
                        "href": "/v1/schedules/21"
                    }
                }
            }
        ]
    },
    "total": 5,
    "_links": {
        "self": {
            "href": "/v1/schedules/GC********3"
        }
    }
}
```

### Fetch Schedule

*Scope: Trusted*

*Request URL:*

```
GET /schedules/{schedule id}    
```

*Headers:*

```
Content-Type: application/json
Authorization: Bearer {access_token}
```

*Response:*

```
{
    "schedules": {
        "id": 3,
        "controller_id": 2,
        "from_time": "2021-07-02 09:20:00",
        "to_time": "2021-07-02 16:40:00",
        "days": "1111111",
        "target": 27,
        "main_target": null,
        "default_state": "do_nothing",
        "action": "thermostat_mode",
        "priority": 0,
        "active": 1,
        "push": 1,
        "user_time_offset": null
    },
    "_links": {
        "self": {
            "href": "/v1/schedules/3"
        }
    }
}
```

### Update Schedule

*Scope: Trusted*

*Request URL:*

```
PATCH /schedules/{schedules id}
```

*Headers:*

```
Content-Type: application/json
Authorization: Bearer {access_token}
```

*Body*:

```
{
  "from_time" : 1300,
  "to_time" : 1400,
  "days": "0000011"
}
```

*Response:*

```
{
    "schedules": {
        "id": 10,
        "controller_id": 1,
        "from_time": "2021-07-03 21:40:00",
        "to_time": "2021-07-03 23:20:00",
        "days": "0000011",
        "target": 24,
        "main_target": null,
        "default_state": "do_nothing",
        "action": "command",
        "priority": 0,
        "active": 1,
        "push": 1,
        "user_time_offset": null
    },
    "_links": {
        "self": {
            "href": "/v1/schedules/10"
        }
    }
}
```

### Delete Schedule

*Scope: Trusted*

*Request URL:*

```
Delete /schedules/{schedules id}
```

*Headers:*

```
Content-Type: application/json
Authorization: Bearer {access_token}
```

*Response:*

```
{
    "schedules": {
        "id": 57
    },
    "_links": {
        "self": {
            "href": "/v1/schedules/57"
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mclimate.eu/mclimate-api-documentation/functions/schedules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
