Anniversary Sale · up to 80% off all librariesEnds Nov 9Shop now
SOFTTDocs
Cards
You are reading the documentation for ESP-DASH v4.x.x, which is no longer the latest release. View the v5.x.x documentation.

Week Selector Card

Let users select days of the week as a comma-separated list on the ESP-DASH Pro v4 dashboard.

ESP-DASH Pro feature. This functionality is available only in the commercial edition of ESP-DASH.

The week selector card lets the user select days of the week. Its value is a comma-separated (,) string of the selected days, such as mon,wed,fri. Use it for schedules and recurring timers.

Week selector card

Constructor

Card week(&dashboard, WEEK_SELECTOR_CARD, "Select Days");

Prop

Type

Callback

The callback fires whenever the user selects or deselects a day. days is a comma-separated list of the selected days, using the values mon, tue, wed, thu, fri, sat and sun.

Call update() with the received value and then dashboard.sendUpdates() inside the callback. Otherwise the dashboard does not register the input and the card remains in its waiting state.

week.attachCallback([&](const char* days) {
  Serial.println("Selected days: " + String(days));
  week.update(days);
  dashboard.sendUpdates();
});

Methods

update()

Sets the selected days from a comma-separated list. The order of days does not matter: tue,mon,thu selects Monday, Tuesday and Thursday.

week.update(const char* value);
week.update(const String &value);

Call dashboard.sendUpdates() afterwards to push the change to connected clients.

Example

main.cpp
#include <Arduino.h>
#if defined(ESP8266)
  #include <ESP8266WiFi.h>
  #include <ESPAsyncTCP.h>
#elif defined(ESP32)
  #include <WiFi.h>
  #include <AsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
#include <ESPDash.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

AsyncWebServer server(80);
ESPDash dashboard(&server);

Card week(&dashboard, WEEK_SELECTOR_CARD, "Select Days");

void setup() {
  Serial.begin(115200);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("WiFi connection failed");
    return;
  }
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  week.update("mon,tue,wed,thu,fri");

  week.attachCallback([&](const char* days) {
    Serial.println("Selected days: " + String(days));
    week.update(days);
    dashboard.sendUpdates();
  });

  server.begin();
}

void loop() {
  // ...
}

On this page