Single Switch
Allows users to toggle a slider to send commands to devices or update attributes/time series data. Configurable settings let users define how to retrieve the initial state and specify actions for the on/off toggle.
Who it’s for
Anyone who needs a labelled on-off control in a single dashboard row — a lighting circuit, a valve, an enable flag — where a row of switches down a panel reads better than a grid of round buttons.
What it does
The Single Switch toggles equipment on and off from a slider control in a 3.5×1 strip, showing the current state as the slider’s position. State is fetched by a configured action, and the on and off transitions each send their own action, so the switch reflects the device rather than the last press.
- Built for a stacked panel — one grid row per switch, with a label and an icon on the same line.
- State is read back, not assumed — the initial state action fetches from an attribute, a telemetry key, an RPC call or an alarm status.
- On and off are separate actions, for devices where the two transitions are different calls.
- On, off and disabled each have their own switch and tumbler colors, so the three states are visually distinct.
- The on and off labels are editable, so a switch can read Open and Closed rather than the generic pair.
- A disabled condition greys the control out, distinguishing “off” from “cannot be operated”.
- The Single Switch is one control for one thing: a value rather than a state belongs on a slider or a stepper.
How to set up
Data keys
The Single Switch takes no data keys — state and commands come from its configured actions.
| Attribute | Scope | Operation | Description |
|---|---|---|---|
| Configured key | Any for read, Shared / Server for write | Read + Write | With Initial state set to Get attribute the switch reads this key; with the on and off actions set to Set attribute it writes it. |
| Method | Direction | Parameters | Sent when |
|---|---|---|---|
| Turn ‘On’ method | One-way or two-way, as configured | Constant or from a convert function | When the slider is moved to on |
| Turn ‘Off’ method | One-way or two-way, as configured | Constant or from a convert function | When the slider is moved to off |
Behavior
| Setting | Default | Effect |
|---|---|---|
| Initial state | Unset | How the current state is fetched |
| Turn ‘On’ | Unset | The action triggered when the slider is switched on |
| Turn ‘Off’ | Unset | The action triggered when the slider is switched off |
| Disabled state | Unset | An action deciding when the control is greyed out |
Configure the initial state action so the switch reflects the equipment. Without it the slider shows the last commanded position, which stops matching reality as soon as anything else operates the device.
How to customize
- To read the real state — set Initial state to the action matching how the device reports, with a parse function if the value is not a boolean.
- To command the device — set Turn ‘On’ and Turn ‘Off’ to their own actions.
- To word the positions — set the On label and Off label to the operator’s terms, such as Open and Closed.
- To make the states unmistakable — set the Switch color and Tumbler color separately for on, off and disabled.
- To name the control — turn on Label and set its text, and add an Icon if the panel uses them.
- To keep the row proportional — leave Auto scale on, or turn it off to pin exact sizes.
- To block operation under a condition — configure the Disabled state action.
Tips
- Give every switch in a stacked panel the same layout and label width. A column of switches is operated by muscle memory as much as by reading, and rows that shift horizontally invite the wrong one being pressed.
- Word the labels as positions, not as commands. Open and Closed describe what the valve is, whereas Open and Close mix a state with an instruction and leave the operator unsure which one the switch is currently showing.
Share Your Widget with the Community
Built a custom widget? Export it as a JSON from ThingsBoard and publish it to the IoT Hub through a simple 4-step wizard (Upload, Listing, Readme, Review & Submit). Share it with thousands of ThingsBoard developers worldwide and get featured in the catalog.