Sensor Readings
Pre-requisite: The LiveView should be already started before making any interactions.
Cameras with environmental sensors push their readings over the same data channel that carries the stream commands. Both readings are StateFlow<Float?> and both are null until the camera reports for the first time.
Temperature
viewModelScope.launch {
client.temperatureInfo.collectLatest { temperature ->
temperature?.let { render(it) }
}
}
The camera reports a raw number, not a unit. Which unit to display it in is a space setting — Space.settings?.temperatureUnit holds TemperatureUnit.value, either "C" or "F", defaulting to "F".
Humidity
viewModelScope.launch {
client.humidityInfo.collectLatest { humidity ->
humidity?.let { render(it) }
}
}
A humidity reading of 0 means the camera had nothing to report; it is discarded rather than emitted, so the flow keeps the last good value. Temperature has no such guard — 0 is a real temperature and is passed through.
How readings arrive
Nothing needs to be started. Once the WebRTC data channel opens, the client checks which sensors the camera advertises and begins polling each supported one over the data channel every 10 seconds — the same interval used for Signal Strength. The loops stop on their own when the data channel closes, so closing the client is enough to end them.
Availability
Check the sensor before showing a reading at all:
if (device.hasTemperatureSensor()) {
// show the temperature
}
if (device.hasHumiditySensor()) {
// show the humidity
}
Both helpers read the camera’s clusters, so they return false on flat-settings cameras (device.supportsCluster() is false) regardless of the hardware. On a camera without the sensor the flow stays null for the life of the stream — treat null as “no reading available”, not as a reading of zero.
Related
- Signal Strength — the third reading the camera pushes over the stream.
- Nursery Monitoring — temperature and humidity alert thresholds, and the events raised when a reading crosses one.