Update: I found a solution (or workaround) for using a Shelly 1PM Mini Gen4 in detached mode with smart bulbs in Smartthings! Here’s what I did:
-
Create a virtual button in SmartThings Advanced and copy it’s device ID.
-
Create a token at account.smartthings.com/tokens
Select all permissions under “Devices”. -
Access the Shelly 1PM Mini Gen4 page in your browser (192.168.1.xxx) and create a script:
let ST_TOKEN = “Paste_Your_Token_Here”;
let DEVICE_ID = “Paste_Your_Virtual_Button_DeviceID_Here”;
let flip_flop = false;
print(“Listening for the switch…”);
Shelly.addEventHandler(function(event) {
if (event.component === “input:0” && typeof event.info.state !== “undefined”) {
print(“▶ CLICK DETECTED! Sending order to Smartthings…”);
flip_flop = !flip_flop;
let command_to_send = flip_flop ? “on” : “off”;
let payload = JSON.stringify({
“commands”:[{
“component”: “main”,
“capability”: “switch”,
“command”: command_to_send
}]
});
Shelly.call(
“HTTP.Request”,
{
method: “POST”,
url: “https://api.smartthings.com/v1/devices/” + DEVICE_ID + “/commands”,
headers: {
“Authorization”: "Bearer " + ST_TOKEN,
“Content-Type”: “application/json”
},
body: payload
},
function(result, error_code, error_msg) {
if (error_code === 0 && result !== null) {
if (result.code === 200) {
print("✅ SUCCESS! " + command_to_send);
} else {
print("❌ Smartthings ERROR: Code " + result.code + " → " + result.body);
}
} else {
print("❌ NETWORK ERROR: " + error_msg);
}
}
);
}
});
-
Click on Save and Start, and then on Run on startup.
-
Create the Routine in the SmartThings App, Ex.:
IF: Device Status Virtual Button is On/Off (or other conditions/pre-conditions)
THEN: Control Smart Bulbs → Toggle On/Off or set brightness/color temp
-
And that’s it! ENJOY
Thank you all for your help (especially @TapioX and @mocelet for your quick replies).