Temperature Card
Display a temperature reading with a configurable unit using dash::TemperatureCard.
The temperature card displays a numeric temperature reading with a unit, such as the output of a thermistor or a digital temperature sensor.

Constructor
dash::TemperatureCard<T, Precision> card(dashboard, name, unit);Prop
Type
Template parameters:
Prop
Type
dash::TemperatureCard temperature(dashboard, "Temperature"); // float, 2 decimals, °C
dash::TemperatureCard<float, 1> outdoor(dashboard, "Outdoor", "°F");
dash::TemperatureCard<int> core(dashboard, "Core");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 temperature 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, for example "°C" or "°F". 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::TemperatureCard<float> temperature(dashboard, "Temperature", "°C");
void setup() {
// ... connect to Wi-Fi
server.begin();
}
void loop() {
float reading = 23.5f; // replace with a sensor reading
temperature.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. - Changing the unit does not convert the value; set a value in the new unit as well.
