Switch
A Switch turns something on or off: a relay, a pump, a light. Tap it once to switch on, tap again to switch off. It stays where you leave it.
1 / 01 Telemetry Point8 knob iconsTry it
Tap the switch on the dashboard. Watch the value travel to the NuttyFi board and the relay LED change. Then change the settings below — they are the same ones you'll find in the widget's settings window.
How to add and set up
- Open the dashboard in edit modeOpen the device and turn on editing.
- Add a SwitchPress + on the right edge of the canvas and pick Switch. Drag it into place.
- Open its settingsClick the gear icon on the widget. The window title shows the widget's name.
- Link a Telemetry PointUnder Linked Telemetry Points, pick the point your code reads, for example
TP0. - Name and style itSet the Widget Name, Switch Orientation, Icon, labels and Widget Color. Save, then press DONE.
Settings
| Setting | What it does |
|---|---|
| Widget Name | The title shown on the widget. |
| Label Color | Colour of the title. |
| Linked Telemetry Points | The Telemetry Point (TP0, TP1…) the widget uses. Your device code uses the same point. |
| Switch Orientation | Horizontal or Vertical. The tile keeps the same size; the switch turns upright. |
| Icon | Symbol on the knob: Auto (power), Power, Bulb, Fan, Pump / Water, Lock, Bell or Play / Pause. |
| ON / OFF label | Text shown under the switch for each state. Defaults: ON and OFF. |
| ON / OFF text colour | Colour of that text in each state. |
| Widget Color | Colour of the switch (and its glow) when it is on, and of the tile's border. |
| Hide widget Name | Hides the title. |
| Hide Telemetry Point | Hides the TP badge in the corner. |
| Hide Widget Border | Removes the outline around the tile. |
What it sends
Each tap writes one value to the linked Telemetry Point. Your device code checks that point and switches the pin.
Receive commands on your device
Your board picks the value up with SME_LISTEN, using the same point you linked on the dashboard. The examples use TP0.
SME_LISTEN(TP0)
{
int on = data.toInt(); // 1 = on, 0 = off
digitalWrite(PUMP_PIN, on);
}
// Many relay boards switch on when the pin goes LOW
SME_LISTEN(TP0)
{
int on = data.toInt();
digitalWrite(RELAY_PIN, on ? LOW : HIGH); // active-low relay
}
// Report the new state back so an LED widget on TP1 confirms it
SME_LISTEN(TP0)
{
int on = data.toInt();
digitalWrite(PUMP_PIN, on);
SME.publish(TP1, on); // LED on TP1 shows the result
}
#define DASHBOARD_ID "PROJ-XXXXXXXX"
#define DEVICE_TOKEN "SME-XXXX-XXXX-XXXX"
#define FIRMWARE_VERSION "1.0.0"
#define WIFI_SSID "your_wifi"
#define WIFI_PASS "your_pass"
#include <SMEIoT.h>
#define PUMP_PIN 5
// Switch on TP0: 1 = on, 0 = off
SME_LISTEN(TP0)
{
int on = data.toInt();
digitalWrite(PUMP_PIN, on);
}
void setup()
{
Serial.begin(115200);
pinMode(PUMP_PIN, OUTPUT);
SME.begin(DASHBOARD_ID, DEVICE_TOKEN, FIRMWARE_VERSION,
WIFI_SSID, WIFI_PASS);
}
void loop()
{
SME.run(); // keeps the link alive
}SME_LISTEN(TP0) runs every time the dashboard writes TP0. data holds the value it sent, as text: use data.toInt() for whole numbers or data.toFloat() for decimals.
These are snippets. Your sketch also needs #include <SMEIoT.h>, SME.begin(...) in setup() and SME.run() in loop(). The full sketch tab shows a complete example; see the SDK quick start for more.
Docs