Temperature & Humidity Sensors
Relevant source files
The following files were used as context for generating this wiki page:
The Temperature & Humidity sensors are fundamental components of the OpenAwair project, providing environmental data used for local-first air quality monitoring. These sensors are integrated into the hardware of both supported devices: the Awair Glow C and the Awair Element. The project abstracts these hardware sensors through TypeScript drivers to facilitate testing, data collection, and integration with external systems like Home Assistant.
Sources: CLAUDE.md:1-15, host/src/shared/telemetry.ts:1-15
Sensor Hardware Architecture
The project utilizes two distinct sensor models depending on the device hardware. Both models communicate via the I²C protocol and are managed by the STM32F412 MCU on the Laird Sterling-EWB module.
- Awair Glow C: Uses the SHTC3 sensor for temperature and humidity.
- Awair Element: Uses the SHT30 sensor for temperature and humidity.
Sources: CLAUDE.md:12-25
Hardware Specifications Summary
| Feature | SHTC3 (Glow C) | SHT30 (Element) |
|---|---|---|
| Interface | I²C | I²C |
| Primary Readings | Temp, Humidity | Temp, Humidity |
| Typical Interval | 5000ms | 5000ms |
| Data Types | Celsius, Relative Humidity | Celsius, Relative Humidity |
Sources: host/src/firmware/sensors/shtc3.ts:5-6, host/src/firmware/sensors/sht30.ts:5-6, CLAUDE.md:65-66
Software Implementation
The software architecture uses a driver-based approach where each sensor implements a common interface. This allows the SensorScheduler and AwairDevice controller to interact with different hardware transparently.
Sensor Driver Interface
Both Shtc3Sensor and Sht30Sensor classes implement the SensorDriver interface, ensuring they provide a standard set of properties and methods:
name: A string identifier for the sensor (e.g., "SHTC3").sampleIntervalMs: The frequency at which the sensor should be polled.read(): An asynchronous method that returns aSensorReadingobject.
Sources: host/src/firmware/sensors/shtc3.ts:4-14, host/src/firmware/sensors/sht30.ts:4-14
Data Models and Telemetry
Sensor data is normalized into a standard SensorReading interface before being processed by the system.
export interface SensorReading {
readonly timestamp: Date;
readonly temperatureC?: TemperatureCelsius;
readonly humidityPercent?: RelativeHumidity;
// ... other sensor fields
}
Sources: host/src/shared/telemetry.ts:8-15
Data Flow and Integration
Temperature and humidity data flows from the hardware sensors through the driver abstraction into a centralized telemetry system for distribution via MQTT or REST API.
Collection Logic Flow
The AwairDevice uses a SensorScheduler to trigger sampling across all registered drivers.
The diagram shows how environmental data is requested by the device controller and propagated to network interfaces.
Sources: host/src/firmware/device.ts:13-22, host/src/firmware/networking/mqtt.ts:11-16, CLAUDE.md:113-117
Home Assistant Discovery
To enable automatic integration, the system generates Home Assistant discovery messages. For temperature sensors, this includes specific metadata such as the deviceClass set to "temperature" and the unitOfMeasurement set to "°C".
| Field | Value for Temperature | Value for Humidity |
|---|---|---|
| Name | Temperature | Humidity |
| Device Class | temperature | humidity |
| State Topic | openawair/{id}/telemetry | openawair/{id}/telemetry |
| Value Template | {{ value_json.sensors.temperatureC }} | {{ value_json.sensors.humidityPercent }} |
Sources: host/src/firmware/networking/mqttDiscovery.ts:13-48, host/test/mqttDiscovery.test.ts:10-25
Conclusion
The Temperature & Humidity sensor module provides a robust abstraction layer for the SHTC3 and SHT30 hardware. By standardizing the polling intervals and data structures via the SensorDriver interface and SensorReading types, OpenAwair ensures consistent environmental monitoring across different device models while enabling seamless integration with home automation platforms.