# Smart Home Sensor Guide

`action.devices.types.SENSOR` - A single sensor can serve multiple functions, such as monitoring both temperature and humidity. Sensors may report either or both quantitative---for example, carbon monoxide and smoke level measured at parts per million---and qualitative measurements (such as whether air quality is healthy or unhealthy).

This type indicates that the device gets the Sensor icon and some related
synonyms and aliases.

## Device capabilities

Refer to the corresponding trait documentation for
implementation details, such as attributes and states that your service should support, and how to
build EXECUTE and QUERY responses.

### Recommended traits

These traits are recommended, if applicable to your device.
However, you are free to mix and match from all available traits to best match your existing
product functionality.

- [`action.devices.traits.SensorState`](https://developers.home.google.com/cloud-to-cloud/traits/sensorstate)
- [`action.devices.traits.EnergyStorage`](https://developers.home.google.com/cloud-to-cloud/traits/energystorage)

Sensors may also use other traits covering data they can report, such as:

- [HumiditySetting](https://developers.home.google.com/cloud-to-cloud/traits/humiditysetting)
- [OpenClose](https://developers.home.google.com/cloud-to-cloud/traits/openclose)
- [TemperatureControl](https://developers.home.google.com/cloud-to-cloud/traits/temperaturecontrol) - Use for non-climate temperatures (water, surface temp, device interiors).
- [TemperatureSetting](https://developers.home.google.com/cloud-to-cloud/traits/temperaturesetting) - Use for climate temperatures (ambient air).

> [!NOTE]
> **Note:** Sensors that report data covered by another trait should use that trait with the `queryOnly*` attribute for that trait set to `true`. For example, window sensors should use the [OpenClose](https://developers.home.google.com/cloud-to-cloud/traits/openclose) trait with the `queryOnlyOpenClose` attribute set to `true`.

## Example device: Simple sensor

This section contains example intent payloads representing a common "Sensor"
based on the device type and traits above. If you add or remove traits in your implementation,
modify your responses accordingly to reflect those changes.

### Sample SYNC response

Request

```
{
  "requestId": "6894439706274654512",
  "inputs": [
    {
      "intent": "action.devices.SYNC"
    }
  ]
}
```
Response

```
{
  "requestId": "6894439706274654512",
  "payload": {
    "agentUserId": "user123",
    "devices": [
      {
        "id": "123",
        "type": "action.devices.types.SENSOR",
        "traits": [
          "action.devices.traits.EnergyStorage",
          "action.devices.traits.OccupancySensing",
          "action.devices.traits.SensorState"
        ],
        "name": {
          "name": "Simple sensor"
        },
        "willReportState": true,
        "attributes": {
          "sensorStatesSupported": [
            {
              "name": "AirQuality",
              "descriptiveCapabilities": {
                "availableStates": [
                  "healthy",
                  "moderate",
                  "unhealthy",
                  "very unhealthy"
                ]
              }
            }
          ],
          "queryOnlyEnergyStorage": true,
          "occupancySensorConfiguration": [
            {
              "occupancySensorType": "PIR",
              "occupiedToUnoccupiedDelaySec": 10,
              "unoccupiedToOccupiedDelaySec": 10,
              "unoccupiedToOccupiedEventThreshold": 2
            }
          ]
        },
        "deviceInfo": {
          "manufacturer": "smart-home-inc",
          "model": "hs1234",
          "hwVersion": "3.2",
          "swVersion": "11.4"
        }
      }
    ]
  }
}
```

### Sample QUERY response

Request

```
{
  "requestId": "6894439706274654514",
  "inputs": [
    {
      "intent": "action.devices.QUERY",
      "payload": {
        "devices": [
          {
            "id": "123"
          }
        ]
      }
    }
  ]
}
```
Response

```
{
  "requestId": "6894439706274654514",
  "payload": {
    "devices": {
      "123": {
        "status": "SUCCESS",
        "online": true,
        "currentSensorStateData": [
          {
            "name": "AirQuality",
            "currentSensorState": "healthy"
          }
        ],
        "descriptiveCapacityRemaining": "HIGH",
        "capacityRemaining": [
          {
            "unit": "PERCENTAGE",
            "rawValue": 90
          }
        ],
        "occupancy": "OCCUPIED"
      }
    }
  }
}
```

## Device ERRORS

See the full list of [errors and exceptions](https://developers.home.google.com/cloud-to-cloud/intents/errors-exceptions).