Switch
A two-way control for an on/off entity. It shows the current state and changes it when you flip it.
Live preview · sample data
Settings
| Field | What it does |
|---|---|
| Entity | The on/off value to control |
| Switch label | Wording shown beside the switch |
| Color | The colour when on |
| Admin only | Hide it from everyone who isn’t an admin of the device — see Sharing a device |
How it works
A switch reads and writes. The position reflects what your device last reported, so if something else changes the value — a physical button, the device itself — the switch follows.
Flipping it sends the new value down to your device, where entityChanged receives it:
.entityChanged = [](JsonDoc doc) {
// a switch or slider was changed on a dashboard
},Report the value back in sendStatus so the switch reflects reality:
.sendStatus = [](JsonDoc doc) {
doc["ledOn"] = digitalRead(LED_PIN);
},If you don’t, the switch will spring back to the old position the next time your device reports, which usually looks like the switch “not working”.
Switch or button?
Use a switch for something with a lasting state you can read back — a relay, an LED, a mode. Use a Button for an action that happens and is over, like a reboot.