Hello all, I am trying to run a script to restart a device every time its LED starts flashing. However, when restarting the device flashes the LED as well so the script needs to sleep.
I need the Script to react if LDR (photoresistor) is lower than 20% "Input (100)", set Output State to ON, and Flip Value after 10 seconds. However, it then needs to Sleep for 30 seconds. I cannot do the Sleep side in the Actions interface. I need to use a script.
I have a 2PM with a Plus Addon.
Input (100) is Analog and reports light value as a Percentage (range 0 to 100%)
I have tried using getComponentStatus("input:100") and I do get the right value:
Light Level { "id": 100, "percent": 44.5 }
So I can definitely pull that in. But how? The code below just looks for a Button Down event. This is part of a script written by a GIT contributor called nygma2004.
I have really tried but cannot find documentation on referencing that input being less than 20% to trigger the event
function eventcallback(userdata) {
print("Event called: ", JSON.stringify(userdata));
// check if this a button press event
if (userdata.info.event==="btn_down") {
print("button down event");
state = !state;
if (state) {
timercallback(null);
} else {
Timer.clear(timer_handle);
}
}
}
Shelly.addEventHandler(eventcallback, userdata);
Alles anzeigen
Any help gratefully received.
Thanks,
Andrew.