LedStrip
The LedStrip API provides JavaScript methods for controlling addressable LED strips and matrices from scripts. It enables dynamic color control, effect switching, brightness adjustment, and creation of custom script effects. This API complements the RPC-based LedStrip component documentation.
Overview
The LedStrip API enables scripts to:
- Get current LED strip status and configuration
- Control brightness, colors, and effects in real-time
- Switch between effects and modify effect parameters
- Reset effect parameters to defaults
- List available effects and color palettes
- Create custom script effects with JavaScript
- Access audio analyzer features for sound-reactive effects
Quick Example
// Get LED strip status
let status = Shelly.getComponentStatus("ledstrip:0");
if (status) {
console.log("LED is", status.on ? "on" : "off");
console.log("Brightness:", status.brightness, "%");
console.log("Color:", status.rgb);
console.log("Effect:", status.effect);
}
// Set color and brightness
Shelly.call("LedStrip.Set", {
id: 0,
on: true,
brightness: 100,
rgb: [255, 0, 0] // Red
}, function(result, error_code) {
if (error_code === 0) {
console.log("Color changed successfully");
}
});
// Switch to an effect
Shelly.call("LedStrip.Set", {
id: 0,
effect: "rainbow",
speed: 60,
intensity: 80
});
// Switch to next effect
Shelly.call("LedStrip.NextEffect", { id: 0 });
// Reset effect parameters to defaults
Shelly.call("LedStrip.ResetEffect", { id: 0 });
API Reference
Shelly.getComponentStatus("ledstrip:id")
Get the current status of the LED strip component.
Parameters:
- None
Returns:
- Component status object with properties:
id,on,brightness,rgb,r,g,b,bg_rgb,bg_r,bg_g,bg_b,effect,speed,intensity,palette,reverse
Example:
let status = Shelly.getComponentStatus("ledstrip:0");
if (status && status.on) {
console.log("Strip is on, brightness:", status.brightness);
}
Shelly.call("LedStrip.Set", params, callback)
Set LED strip state, colors, brightness, and effects.
Parameters:
id(number): LED strip component IDon(boolean, optional): Turn on/offbrightness(number, optional): Brightness 0-100%rgb(array, optional): RGB color as array [r, g, b] with values 0-255r,g,b(number, optional): Individual RGB channels 0-255bg_rgb,bg_r,bg_g,bg_b(array/number, optional): Background coloreffect(string, optional): Effect key to activatespeed(number, optional): Effect speed 0-100intensity(number, optional): Effect intensity 0-100palette(string, optional): Palette name (e.g., "fire")reverse(boolean, optional): Reverse effect directiontransition_duration(number, optional): Color transition time in secondsaudio_gain(number, optional): Audio analyzer gain 0-100 (if supported)audio_norm(boolean, optional): Audio analyzer auto-gain (if supported)tag(string or null, optional): State change origin tag (max 20 chars)
Example:
Shelly.call("LedStrip.Set", {
id: 0,
on: true,
brightness: 75,
rgb: [0, 255, 0], // Green
transition_duration: 0.5
}, function(result, error) {
if (!error) {
console.log("LED updated");
}
});
Shelly.call("LedStrip.ResetEffect", params, callback)
Reset effect parameters (speed, intensity, palette, reverse, colors) to their default values for the current effect.
Parameters:
id(number): LED strip component ID
Example:
Shelly.call("LedStrip.ResetEffect", { id: 0 }, function(result, error) {
if (!error) {
console.log("Effect parameters reset");
}
});
Shelly.call("LedStrip.ListAllEffects", params, callback)
Get list of available effects.
Parameters:
id(number): LED strip component IDoffset(number, optional): Pagination offset
Returns:
- Array of effect objects with properties:
key,name,description,controls
Example:
Shelly.call("LedStrip.ListAllEffects", { id: 0 }, function(result) {
if (result && result.effects) {
result.effects.forEach(function(effect) {
console.log(effect.key, "-", effect.name);
});
}
});
Shelly.call("LedStrip.ListAllPalettes", params, callback)
Get list of available color palettes.
Parameters:
id(number): LED strip component IDoffset(number, optional): Pagination offsetrgb(array, optional): Preview color for generative palettes as [r, g, b]
Returns:
- Array of palette objects with properties:
key,name,colors,is_auto
Example:
Shelly.call("LedStrip.ListAllPalettes", { id: 0 }, function(result) {
if (result && result.palettes) {
result.palettes.forEach(function(pal) {
console.log(pal.key, "-", pal.name);
});
}
});
Shelly.call("LedStrip.NextEffect", params, callback)
Switch to the next effect in the effects list.
Parameters:
id(number): LED strip component ID
Example:
Shelly.call("LedStrip.NextEffect", { id: 0 });
Shelly.call("LedStrip.AddEffect", params, callback)
Add an effect to the effects list.
Parameters:
id(number): LED strip component IDeffect_key(string): Effect key (built-in or "script:N")
Example:
Shelly.call("LedStrip.AddEffect", { id: 0, effect_key: "rainbow" });
Shelly.call("LedStrip.RemoveEffect", params, callback)
Remove an effect from the effects list.
Parameters:
id(number): LED strip component IDeffect_key(string): Effect key to remove
Example:
Shelly.call("LedStrip.RemoveEffect", { id: 0, effect_key: "rainbow" });
Shelly.call("LedStrip.ListAllProtocols", params, callback)
Not available on all devices. Only available when LED protocol is configurable (not fixed by hardware).
Get list of available LED protocols.
Parameters:
id(number): LED strip component ID
Returns:
- Array of protocol objects with properties:
id,key,name
Example:
Shelly.call("LedStrip.ListAllProtocols", { id: 0 }, function(result) {
if (result && result.protocols) {
result.protocols.forEach(function(proto) {
console.log(proto.key, "-", proto.name);
});
}
});
Shelly.call("LedStrip.TestColors", params, callback)
Not available on all devices. Only available when color order is configurable (not fixed by hardware).
Run LED color test (cycles red, green, blue, white at 25% brightness).
Parameters:
id(number): LED strip component ID
Example:
Shelly.call("LedStrip.TestColors", { id: 0 });
Script Effects
Custom effects can be created using JavaScript and registered as LED strip effects. Script effects appear in the effects list and can be selected via LedStrip.Set or LedStrip.NextEffect.
Effect Script Structure
Script effects are regular scripts created with type led_strip_effect, see Script.Create. The script receives the LED strip component object and must implement the effect logic.
Script effects can include metadata to provide UI information:
// @meta {"description":"My custom effect","controls":["rgb","speed"]}
// Effect implementation here
Supported metadata fields:
description(string): Human-readable effect descriptioncontrols(array): Available control parameters:"rgb","bg_rgb","palette","intensity","speed","reverse"
Event Listener Pattern
Scripts can listen for LED strip status changes via internal events:
Shelly.addEventHandler(function(event) {
if (event.component === "ledstrip:0") {
// kChange: on/off state changed
if (event.info.event === "change") {
console.log("LED strip on/off changed");
let status = Shelly.getComponentStatus("ledstrip:0");
console.log("LED is now", status.on ? "on" : "off");
}
// kValueChange: brightness, color, effect, or parameters changed
if (event.info.event === "value_change") {
console.log("LED strip value changed");
let status = Shelly.getComponentStatus("ledstrip:0");
console.log("Current color:", status.rgb);
console.log("Brightness:", status.brightness);
}
}
});
These are internal notification events for scripts and LNM, not webhook events. They fire unconditionally on every state change, enabling reliable script automation.
Audio Analyzer Integration
Devices with integrated audio analyzers (Shelly Nolu Bars, Trigon, Mosaic, Hexo and Floor) can use audio-reactive effects that respond to sound input.
Audio Analyzer Control
When an LED strip component has an audio analyzer, two additional parameters are available in LedStrip.Set:
audio_gain(number, 0-100): Manual gain adjustment (0=muted, 50=unity, 100=max)audio_norm(boolean): Enable/disable auto-gain normalization (compressor)
Example:
Shelly.call("LedStrip.Set", {
id: 0,
effect: "audio_reactive_effect", // Requires audio analyzer
audio_gain: 75,
audio_norm: true
}, function(result, error) {
if (error && error.code === -104) {
console.log("Device does not have audio analyzer");
}
});
Audio-Reactive Effect Metadata
Audio-reactive effects can include controls in their metadata:
// @meta {"description":"Sound-reactive rainbow","controls":["rgb","speed","intensity"]}
// Effect implementation here
Gain Mapping
The audio_gain parameter uses a logarithmic scale:
- 0% = muted (0× multiplier)
- 50% = unity gain (1× multiplier)
- 100% = maximum (≈6.67× multiplier)
The mapping preserves audio quality and is optimized for typical audio input levels.
Color Representation
Colors can be specified in multiple formats:
Array Format:
// Pass as array [r, g, b] with values 0-255
Shelly.call("LedStrip.Set", {
id: 0,
rgb: [255, 0, 255] // Magenta
});
// Set background color
Shelly.call("LedStrip.Set", {
id: 0,
bg_rgb: [0, 0, 0] // Black background
});
Individual Channels:
// Pass RGB channels separately
Shelly.call("LedStrip.Set", {
id: 0,
r: 255,
g: 0,
b: 255
});
Configuration Management
Scripts can read current LED strip configuration:
Shelly.call("LedStrip.GetConfig", { id: 0 }, function(result) {
if (result) {
console.log("LED count:", result.config.num_leds * result.config.num_modules);
console.log("Effects:", result.config.effects);
}
});
Best Practices
- Check availability: Always verify the component exists before calling methods
- Handle errors: Check error codes in callbacks for audio analyzer availability
- Avoid rapid updates: Batch multiple property changes in a single
Setcall - Use transitions: Set
transition_durationfor smooth color changes - Event-driven: Use
addEventHandlerto react to LED strip changes rather than polling - Audio safety: Validate
audio_gainbefore setting on devices with audio analyzers
Example: Complete Light Show
// Comprehensive LED strip control example
function startLightShow() {
let strip = Shelly.getComponentStatus("ledstrip:0");
if (!strip) {
console.log("No LED strip found");
return;
}
// Get available effects
Shelly.call("LedStrip.ListAllEffects", { id: 0 }, function(result) {
if (!result || !result.effects) return;
// Set initial state
Shelly.call("LedStrip.Set", {
id: 0,
on: true,
brightness: 100,
rgb: [255, 0, 0],
transition_duration: 1.0
});
// Switch to first available effect after 3 seconds
setTimeout(function() {
if (result.effects.length > 0) {
Shelly.call("LedStrip.Set", {
id: 0,
effect: result.effects[0].key,
speed: 60,
intensity: 80
});
}
}, 3000);
// Listen for changes
Shelly.addEventHandler(function(event) {
if (event.component === "ledstrip:0" && event.info.event === "change") {
console.log("LED state changed");
}
});
});
}
startLightShow();