Hot to get Input(100) values into a script

Hinweis zur Nutzung von Skripten (für Nutzer)

Die Verwendung von Skripten erfolgt ausdrücklich auf eigene Gefahr. Weder Shelly noch die jeweiligen Autoren oder Entwickler der Skripte übernehmen irgendeine Form der Haftung für mögliche Schäden, Fehlfunktionen, Datenverluste oder anderweitige Beeinträchtigungen, die durch die Nutzung dieser Skripte entstehen könnten. Bitte stellen Sie vor dem Einsatz sicher, dass Sie den Quellcode verstehen und sich der möglichen Auswirkungen bewusst sind. Die Skripte werden ohne Gewähr bereitgestellt und unterliegen keiner regelmäßigen Wartung oder offiziellen Unterstützung.


Hinweis für Entwickler

Wenn Sie eigene Skripte bereitstellen, achten Sie bitte darauf, eine klare Beschreibung, eventuelle Einschränkungen und Sicherheitsaspekte zu dokumentieren. Beachten Sie zudem, dass Nutzer Ihre Skripte grundsätzlich auf eigenes Risiko verwenden. Eine Haftung für Schäden ist ausgeschlossen, sofern diese nicht vorsätzlich oder grob fahrlässig verursacht wurden oder gesetzlich anderweitig geregelt ist.

VPN/Proxy erkannt

Es scheint, dass Sie einen VPN- oder Proxy-Dienst verwenden. Bitte beachten Sie, dass die Nutzung eines solchen Dienstes die Funktionalität dieser Webseite einschränken kann.

  • 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


    Any help gratefully received.

    Thanks,

    Andrew.

  • Hello Andrew,

    welcome to the forum.

    "Shelly.call" is the function you need: https://shelly-api-docs.shelly.cloud/gen2/0.14/Scri…ures#shellycall

    You can try this script to get the value from the analog input (eventually you have to change the "id" value):

    Greetings

    Nordlicht_2023

    Jede Maschine ist eine Nebelmaschine. Man muss sie nur falsch genug bedienen 😁

  • Thank you Nordlicht_2023,

    Got the output to react to the light setting at 20%. I am now struggling with the timer function. I also had to change "function" to "function callback"

  • You're welcome.

    I think the function from shelly.call can't call from outside and is for the processing through shelly.call only.

    Try to call a timer and a new function around shelly.call. So can the timer call the "lightcheck" function every 2 seconds:

    Greetings

    Nordlicht_2023

    Jede Maschine ist eine Nebelmaschine. Man muss sie nur falsch genug bedienen 😁

  • @Nordlicht_2023 Thats wrong.

    You can always get your input values with print(Shelly.getComponentStatus('input',100));, No 'Shelly.call' is necessary for this.

    @AJSG1969 Welcome,

    What you are looking for are events, and normally your input 100 should also create events, so you can just use an event handler, and then filter for your input 100 events.

    Put this line of code into a script and it will show you all the events within your Script Consol: Shelly.addEventHandler(function(data){print(data);});

    I can provide you with a code example that demonstrates how to use this event. However, I would need the structure of your 'input:100' events, so please share a screenshot of some input:100 events with me.

    8 Mal editiert, zuletzt von _[Deleted]_ (13. Dezember 2023 um 21:38)

  • Dieses Thema enthält 12 weitere Beiträge, die nur für registrierte Benutzer sichtbar sind.