|
/** |
|
* Shelly Power Plug LED Color Controller |
|
* Author: Theo van der Sluijs |
|
* Contact: theo@vandersluijs.nl |
|
* License: MIT |
|
* |
|
* This script is designed to control the LED color of a Shelly power plug |
|
* based on its switch state and button press. It changes the LED color to green when the plug is on |
|
* and to red when the plug is off. The script can be customized for different RGB |
|
* color values and brightness levels. |
|
*/ |
|
|
|
// Main event handler for the Shelly device |
|
Shelly.addEventHandler(function (event) { |
|
// Check if the event source is a switch and if the id of the input is 0 |
|
if (event.name === "switch" && event.id === 0) { |
|
print(event.info.state); // Print the state of the switch |
|
|
|
// If the switch is on (state 1) |
|
if (event.info.state == 1) { |
|
print("Switch ", event.id, " is on"); |
|
// Set LED color to green with full brightness |
|
shellyPlugSChangeLEDColor(0, 100, 0, 100); |
|
} |
|
// If the switch is off (state 0) |
|
else if (event.info.state == 0) { |
|
print("Switch ", event.id, " is off"); |
|
// Set LED color to red with full brightness |
|
shellyPlugSChangeLEDColor(100, 0, 0, 100); |
|
} |
|
else { |
|
print('nothing'); // No relevant state change |
|
} |
|
} |
|
}); |
|
|
|
// Function to change the LED color of the Shelly Plug S |
|
function shellyPlugSChangeLEDColor(red, green, blue, brightness) { |
|
let config = { |
|
"config": { |
|
"leds": { |
|
"colors": { |
|
"switch:0": { |
|
"on": { |
|
"rgb": [red, green, blue], // RGB color for 'on' state |
|
"brightness": brightness // Brightness for 'on' state |
|
}, |
|
"off": { |
|
"rgb": [red, green, blue], // RGB color for 'off' state |
|
"brightness": brightness // Brightness for 'off' state |
|
} |
|
} |
|
} |
|
} |
|
} |
|
}; |
|
Shelly.call("PLUGS_UI.SetConfig", config); // Apply the configuration to the plug |
|
} |
|
|
|
/** |
|
* RGB Color Suggestions: |
|
* - Cool White: (100, 100, 100) |
|
* - Warm Yellow: (100, 85, 35) |
|
* - Soft Blue: (0, 0, 100) |
|
* - Vibrant Purple: (75, 0, 100) |
|
* - Bright Orange: (100, 65, 0) |
|
* Note: These are just suggestions. Feel free to experiment with different combinations. |
|
*/ |