Switch Widget
A classic on/off toggle switch. Sends distinct values for the ON and OFF states. Unlike Button's push mode, the Switch always sends on its state change and reflects the current state visually.
Default size: 2 × 2 grid cells
Configuration
| Property | Type | Default | Description |
|---|---|---|---|
onValue | string | 1 | Value sent when switched ON |
offValue | string | 0 | Value sent when switched OFF |
color | hex color | #10B981 | Accent color when ON |
| Device | device | — | The device to write to |
| Pin | V0–V255 | — | The virtual pin to write to |
| Label | string | — | Widget label |
Firmware example
VWIRE_RECEIVE(V2) {
int isOn = param.asInt();
digitalWrite(RELAY_PIN, isOn ? HIGH : LOW);
Vwire.virtualSend(V2, isOn); // echo actual state
}
Restore state on boot
void setup() {
Vwire.begin(SSID, PASSWORD);
Vwire.syncVirtual(V2); // fetches last known state from server
}
Custom on/off values
You can use non-binary values — e.g. send "ON" / "OFF" strings, or use "255" / "0" for a PWM dimmer:
| Setting | onValue | offValue |
|---|---|---|
| Relay | 1 | 0 |
| String command | ON | OFF |
| Full brightness | 255 | 0 |
Difference from Button
| Feature | Switch | Button (toggle) |
|---|---|---|
| Visual state | Pill / slider style | Rectangular button |
| Default ON color | #10B981 (green) | #3B82F6 (blue) |
| Typical use | Persistent state | Action trigger |