Skip to main content

Switch Widget

⚡ Control

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

PropertyTypeDefaultDescription
onValuestring1Value sent when switched ON
offValuestring0Value sent when switched OFF
colorhex color#10B981Accent color when ON
DevicedeviceThe device to write to
PinV0V255The virtual pin to write to
LabelstringWidget 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:

SettingonValueoffValue
Relay10
String commandONOFF
Full brightness2550

Difference from Button

FeatureSwitchButton (toggle)
Visual statePill / slider styleRectangular button
Default ON color#10B981 (green)#3B82F6 (blue)
Typical usePersistent stateAction trigger