Humidity Card
The Humidity Card displays humidity data, typically with a percentage symbol as its unit.
Initializer
To create a humidity card in ESP-DASH v5, use the dash::HumidityCard<T, Precision> class. The template parameters allow you to control the value type and decimal precision:
T: Value type (e.g., float, int)Precision: Number of decimal places for floating point values (default: 2)
Example 1: Float value, default precision (2 decimals)
dash::HumidityCard<float> hum(dashboard, "Humidity");Example 2: Float value, custom precision (3 decimals)
dash::HumidityCard<float, 3> hum3(dashboard, "Humidity", "%");Example 3: Integer value
dash::HumidityCard<int> humInt(dashboard, "Humidity", "%");Methods
setValue(T value)
Set the humidity value. The type of value must match the template type you chose for T (e.g., int, float).
humidity.setValue(value); // value is of type T- Signature:
void setValue(T value) - Parameters:
T value— The value to display (type matches template parameterT).
- Returns:
void
value()
Get the current humidity value. The return type matches your template type for T (e.g., int, float).
T v = humidity.value();- Signature:
T value() - Parameters: None
- Returns:
T— The current value displayed by the card (type matches template parameterT).
Note:
Tcan be one of:intorfloatdepending on how you instantiate the card.
setUnit(const char* unit)
Set the unit or symbol for the humidity card (e.g., ”%”).
humidity.setUnit("%");- Signature:
void setUnit(const char* unit) - Parameters:
const char* unit— The unit or symbol to display.
- Returns:
void
unit()
Get the current unit or symbol for the humidity card.
const char* unit = humidity.unit();- Signature:
const char* unit() - Parameters: None
- Returns:
const char*— The current unit or symbol for the card.
Reference
Below is a reference code showing how to integrate this widget in a real project, including initialization and value updates usage.
// Create a humidity card (float, 2 decimals by default)
dash::HumidityCard<float> humCard(dashboard, "Humidity", "%");
void setup() {
// ...
humCard.setValue(55.2f);
humCard.setUnit("%");
}
void loop() {
// ...
}Last updated on