Skip to content

Temperature and Humidity Sensors

José Antonio Jiménez Campos edited this page May 11, 2020 · 47 revisions

The HomeKit temperature and humidity sensors have a number of common options and are grouped here.

Type Device Type
22 Temperature Sensor
23 Humidity Sensor
24 Temperature & Humidity Sensor

The following configuration is available for garage doors:

Section Key Description
Actions "0", "1" etc. The actions performed by the accessory
Inching Time "i" Time period before returning accessory to previous state
Wildcard Actions "y[n]" Perform an action when an accessory reaches a target value
Sensor GPIO "g" GPIO line sensor is attached to
Sensor Type "n" Type of sensor attached to accessory
Sensor Polling Time "j" Frequency sensor is read
Humidity Offset "h" Correction offset to apply
Temperature Offset "z" Correction offset to apply
Initial State "s" State a switch accessory enters on boot

Example

{
  "c": { "l": 13 },
  "a": [{
    "t": 1,
    "0": { "r": [{ "g": 12, "v": 0  }] },
    "1": { "r": [{ "g": 12, "v": 1 }] },
    "b": [{ "g": 0 }],
    "s": 5
  }, {
    "t": 24,
    "g": 14,
    "n": 4,
    "j": 30,
    "z": -0.8
  }]
}

This is an example of a Sonoff TH10 unit with a temperature & humidity sensor connected to GPIO 14 and an LED connected to GPIO 13 ("l": 13). The device also has a switch output ("t": 1) connected to GPIO 12 with actions "0" & "1". The switch has a button connected to GPIO 0 ("b": [{ "g": 0 }]).

A second accessory, the temperature & humidity sensor accessory ("t": 24) is attached to GPIO 14 ("g": 14) and is a Si7021 sensor ("n": 4). The polling time has been set to 30 seconds ("j": 30) and to improve the accuracy of the reading an offset of -0.8ºC is applied ("z": -0.8). No offset is being applied to the humidity sensor.

NOTE: The following options are not needed in this example as they are the default options but are included to make the example more readable: "t": 1, "v": 0 & "j": 30

Actions

Action State Description
"5" Sensor Error Action to perform when there is a sensor error

Temperature and humidity sensors only have one action.

Sensor GPIO

Sensor GPIO is defined by the "g" key contained within the accessory object.

Key Value Description
"g" GPIO # GPIO line the temperature and/or humidity sensor is connected to

Home Accessory Architect only supports one-wire temperature and humidity sensors. This is a mandatory option that specifies the GPIO the sensor is connected to.

Sensor Type

Sensor type is defined by the "n" key contained within the accessory object.

A variety of one-wire sensors are available and supported by HAA.

Key Type Device Type Support Description
"n" 1 22, 23 & 24 DHT11 Temperature and humidity sensor
2 22, 23 & 24 DHT22 Type 1 (default) Temperature & humidity sensor
3 22 DS18B20 Temperature sensor
4 22, 23 & 24 Si7021 and DHT22 Type 2 Temperature and humidity sensor
5 22 ADC NTC Thermistor
6 22 ADC Custom thermistor
7 22 ADC Inverted custom thermistor

Sensor types 1 & 3 can only be used with Device type 22 (Temperature Sensor), but sensor types 2 & 4 can be used with any Device type as they contain both a temperature sensor and a humidity sensor.

The DHT22 sensor seems to be available in two forms; a new type branded as a Sonoff product and older types branded as ASAIR and other names. The older types should be configured as DHT22 Type 1 "n": 2 and the newer Sonoff branded type should be configured as a DHT22 Type 2 "n": 4.

The Sonoff Si7021 sensor chip is an I2C device. The Sonoff branded sensor has a Si7021 sensor and an 8-bit MCU combined. The MCU translates the I2C commands into a 1-bit interface suitable for one-wire communication.

NOT SUPPORTED

The Si7021 sensor contains an integrated resistive heating element that can be used to drive off condensation. The data sheet recommends enabling the heater when the humidity readings are >80% as above this the sensor readings can become unreliable. This feature is not currently supported.

Bear this in mind if you are intending to use this sensor outdoors.

Sensor Type Datasheets

Sensor Polling Time

Sensor polling time is defined by the "j" key contained within the accessory object.

Key Value Description
"j" 30 Sensor is polled every 30 seconds (default)
0.1 to 65535 Float specifying the number of seconds between polls

A temperature and/or humidity sensor is polled on a regular basis to read the latest values. These values are then posted to HomeKit. If this option is not specified then the sensor will be polled once every 30 seconds.

Temperature Offset

Temperature offset is defined by the "z" key contained within the accessory object.

NOTE: This option is NOT available for device type 23

Key Value Description
"z" 0.0 No offset is applied (default)
-∞ < 0.0 > +∞ Offset is added to temperature value read

The accuracy of the available one-wire sensors varies and may sometimes read consistently higher or lower than the actual temperature. The temperature offset option enables calibration of the sensor by specifying a positive or negative offset to apply to the reading.

The option uses is a floating point value, accurate to 1 decimal place e.g. 1.1

Humidity Offset

Humidity offset is defined by the "h" key contained within the accessory object.

NOTE: This option is NOT available for device type 22

Key Value Description
"h" 0.0 No offset is applied (default)
-∞ < 0.0 > +∞ Offset is added to humidity value read

The accuracy of the available one-wire sensors varies and may sometimes read consistently higher or lower than the actual humidity. The humidity offset option enables calibration of the sensor by specifying a positive or negative offset to apply to the reading.

The option uses is a floating point value, accurate to 1 decimal place e.g. 1.1

Wildcard Actions

Wildcard Actions "y[n]" are supported by this accessory. The supported list is:

Key Action
"y0" Trigger action when accessory reaches a specific temperature
"y1" Trigger action when accessory reaches a specific humidity

Refer to Wildcard Actions for more detail.

Initial State

The Initial State key is not supported by this accessory.

Clone this wiki locally