# Thermostat mode

## **Description and API usage**

### **What is Thermostat mode?**

**Every MClimate device of type relay (Bobbie, Smart plug, Shelly 1, Shelly 1pm, Shelly em, etc) can act as a thermostat. If it is configured as such, it can use sensor data from another device that have temperature sensors (Bobbie, Melissa, Vicki, Mom, HT sensor, Shelly 1/1 pm, AQI Sensor and notifier, etc.) and use the sensor as reference to control the heating load e.g. space heater, water heater, etc.**

### **How does it work?**

**Every 10 minutes an algorithm checks all created thermostat records and their settings. If the temperature that is measured by the associated sensor is under the target (-delta),, the relay is switched on. If the sensor temperature has reached the target, the relay is switched off.**

### **How to use it via MClimate’s API?**

**Performing queries to MClimate API is done by making HTTP requests with&#x20;*****Headers*****: Content-Type: application/json, Authorization: Bearer {access\_token}**

## Endpoints

### Create Thermostat Mode

*Request URL:*

```
POST /thermostat_mode
```

*Headers:*

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

*Body*:

```
{
  "serial_number" : "QI***********8",
  "sensor_id" : 1****6, // - ID of the sensor device
       - can be the same as relay device if device have sensors
  "target_temperature" : 55, // hysteresis, temperature delta to switch the relay
       on (e.g. target_temperature is 25, delta is 1; the relay will be switched
       on once the sensor_temperature is 24 or lower.
  "delta" : 3, // 0-the mode is off / 1-the mode is on (optional)
  "active" : 1, 
  "state": 1, // Relay last state
  "default_state": "do_nothing", // what do you want to happen with the relay
      in case the sensor is offline - on / off / do_nothing  (optional)
  "push":1 // push notification when state is changed, 1-on/0-off
}
```

*Response:*

```
{
    "thermostat_mode": {
        "sensor_id": 1****0,
        "target_temperature": 50,
        "delta": 3,
        "active": 1,
        "default_state": "do_nothing",
        "push": 1,
        "controller_id": 1****,
        "user_id": 1***3,
        "id": 2**
    },
    "_links": {
        "self": {
            "href": "/v1/thermostat_mode"
        }
    }
}
```

### Fetch Thermostat Mode

*Request URL:*

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

*Headers:*

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

*Response:*

```
{
    "thermostat_mode": {
        "id": 2**,
        "controller_id": 1***0,
        "user_id": 1****3,
        "sensor_id": 1****0,
        "target_temperature": 50,
        "delta": 3, //hysteresis-possible temperature before the relay is switched on
        "state": null,
        "default_state": "do_nothing",
        "push": 1,
        "active": 1 // 0-the mode is off / 1-the mode is on
    },
    "_links": {
        "self": {
            "href": "/v1/thermostat_mode/W**********W"
        }
    }
}
```

### Update Thermostat Mode

*Request URL:*

```
PATCH /thermostat_mode/{Controller Serial Number}
```

*Headers:*

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

*Body*:

```
{
  "target_temperature" : 24,
}
```

*Response:*

```
{
    "thermostat_mode": {
        "id": 2**,
        "controller_id": 1***0,
        "user_id": 1****3,
        "sensor_id": 1***0,
        "target_temperature": 24,
        "delta": 3,
        "state": null,
        "default_state": "do_nothing",
        "push": 1,
        "active": 1
    },
    "_links": {
        "self": {
            "href": "/v1/thermostat_mode/W**********AW"
        }
    }
}
```

### **Postman collection:**

**You can get the full postman collection from** [**here.**](https://www.getpostman.com/collections/243d041f5a652f418a26)


---

# 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/thermostat-mode.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.
