Humidity Card
Display a relative humidity reading with a configurable unit using dash::HumidityCard.
The humidity card displays a numeric humidity reading, by default as a percentage, such as the output of a DHT22 or BME280 sensor.

Constructor
dash::HumidityCard<T, Precision> card(dashboard, name, unit);Prop
Type
Template parameters:
Prop
Type
dash::HumidityCard humidity(dashboard, "Humidity"); // float, 2 decimals, %
dash::HumidityCard<float, 1> greenhouse(dashboard, "Greenhouse");
dash::HumidityCard<int> room(dashboard, "Room");An overload without the dashboard argument creates the card without attaching it to a dashboard; attach it later with dashboard.add(card).
Methods
setValue()
bool setValue(const T& value);Sets the humidity value. Returns true if the value changed and an update is pending.
value()
const T& value() const;Returns the current value. Call it only when hasValue() returns true.
hasValue()
bool hasValue() const;Returns true if a value has been set.
removeValue()
bool removeValue();Clears the value. The dashboard then shows 0. Returns true if a value was removed.
setUnit()
bool setUnit(const char* unit);Sets the unit displayed next to the value. Returns true if the unit changed.
unit()
const char* unit() const;Returns the current unit.
Example
#include <Arduino.h>
#include <WiFi.h> // ESP32; use the networking headers for your board
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ESPDash.h>
AsyncWebServer server(80);
ESPDash dashboard(server);
dash::HumidityCard<float> humidity(dashboard, "Humidity", "%");
void setup() {
// ... connect to Wi-Fi
server.begin();
}
void loop() {
float reading = 55.2f; // replace with a sensor reading
humidity.setValue(reading);
dashboard.sendUpdates();
delay(3000);
}Notes
- The card stores the
unitpointer and does not copy the string. Pass a string literal or a buffer that outlives the card.
