Datastreams
Read and write the datastreams assigned to the widget. Every datastream is addressed by its 0-based index — its position in the widget's Datastreams settings — or by a selector.
The value object
getValue, getValues and onValueUpdated all deliver the same ValueObject. Every field is always present, even ones that don't apply to the stream's type — those default to null, '' or [] instead of being left out. Use type to decide which ones are meaningful.
index
number
0-based datastream index (its position in the widget settings)
id
number | null
Server-side datastream ID; use it with the { id } selector
value
string | null
Current value as a string. null before the first value arrives
lastUpdated
number | null
Unix timestamp (ms) of the last update, or null
type
string
"INT", "DOUBLE", "STRING", "ENUM", "LOCATION", … — compare case-insensitively
label
string
Datastream name as configured on the template
displayName
string
Display alias; '' when not set
pinType
string
Pin type, e.g. "VIRTUAL", or ''
color
string
Accent color from the widget settings, or ''
min, max
number | null
Range bounds; null for non-numeric streams
unit
string
Measurement unit name, or ''
unitSystem
string | null
'METRIC', 'IMPERIAL' or null when the unit has no system
suffix
string
Unit suffix for display, or ''
decimalFormat
string
Decimal format pattern such as "#.##", or ''
mappings
string[]
Enum option labels; [] for non-enum streams
enumFallbackValue
string | null
Label for an enum index outside mappings; null when not configured
For "ENUM" streams, resolve the label with mappings[parseInt(value, 10)], falling back to enumFallbackValue, then to the raw value.
Datastream selectors
Besides a 0-based index, getValue and sendValue accept a selector object with exactly one property:
{ id: 42 }
The server-side datastream ID (the id field of a ValueObject)
{ name: 'Temperature' }
The datastream name (label), not its display alias. Up to 255 characters
{ pin: 'V5' }
A datastream on that virtual pin. V0, V1, … case-insensitive. Datastreams on digital or analog pins are addressed by id or name
Selectors search only the widget's assigned datastreams.
The resolved value object carries
index, so you can reuse it for history and map requests, which take indexes only.Web: a selector resolves only after the dashboard has delivered the widget's datastreams. Resolve selectors after the first value update, or address datastreams by index until then.
invalid_selector
The selector doesn't carry exactly one of id, name, pin, or a value has the wrong type
datastream_not_found
No assigned datastream matches (on web, also before the datastreams have loaded)
ambiguous_datastream_selector
Several assigned datastreams match. details.indexes lists them — select by index instead
Get a datastream value
Returns the current value of one datastream.
Parameters
Resolves with a ValueObject.
Rejects with
invalid_request
target is missing, or the index is not configured on the widget
invalid_selector, datastream_not_found, ambiguous_datastream_selector
The selector can't be resolved — see Datastream selectors
device_unavailable
Called outside a Blynk host
bridge_destroyed
Called after destroy()
Example
Get all datastream values
Returns the current values of every datastream assigned to the widget.
Parameters: none.
Resolves with an array of ValueObjects, positioned by index. Always key rendering off v.index, not off the position you iterate.
Rejects with device_unavailable, bridge_destroyed.
Web: the array is built from the values the dashboard has already pushed into the iframe. Before the first push it is
[], and a stream that hasn't reported yet leaves a hole. So an empty array means "no datastreams configured or nothing has arrived yet" — render a neutral state and letonValueUpdatedfill the UI in.forEachandfor…ofhandle holes safely; indexed access can returnundefined. Mobile returns the full list from the app.
Example
Send a datastream value
Writes a value to a datastream (and on to the device).
Parameters
value
string | number
yes
Value to write
Returns nothing. sendValue is synchronous and fire-and-forget — there is no delivery confirmation. Reflect the new state optimistically and let onValueUpdated confirm it.
Errors
An index that isn't configured on the widget is reported through
sendError(so youronErrorsees it), and the value is dropped.A selector that can't be resolved is reported through
sendErrorand thrown synchronously as aBlynkBridgeError. Wrap selector-based writes intry/catch.Outside a Blynk host, or after
destroy(), the call does nothing.
Example
Value updates pushed by the host arrive in onValueUpdated.
Was this helpful?

