Please ignore, I used the APP to create a scene and then condition to send me a notification. Happy to help if anyone needs to know how to do this.
Beiträge von AJSG1969
-
-
With the kind help of people on this forum I have a great script running on my Plus2PM. I have tested it and am really happy.
Next I need to be notified when the script has been triggered.
I understand that there is no way to send an email, I do however have several "always-on" devices, from Raspberry PI, Linux box to a PC.
From experience could somebody suggest the most reliable way to get a notification?
This is the code into which I need to build the "notification".
Thank you.
Code
Alles anzeigenlet component_name_id = 'input:100'; let component_item = 'percent'; let threshold = 20.0; // component value <= threshold let pause_time = 0; let pause_threshold = 0; function switchontimer() { print("Switch OFF für 30 secs") Shelly.call("Switch.Set","{ id:0, on:false }",null,null); Timer.set(30000,false,switchofftimer); } function switchofftimer() { pause_time = 0; } print("Start and waiting.") let eventhandle = Shelly.addEventHandler( function(data) { if (data["component"] == component_name_id) { if (pause_time != 1 && pause_threshold != 1 && data["info"][component_item] <= threshold) { print("Switch ON für 10 secs - " + data["info"][component_item]) Shelly.call("Switch.Set","{ id:0, on:true }",null,null); pause_time = 1; pause_threshold = 1; Timer.set(10000,false,switchontimer); } else { if (pause_time != 1) { if (pause_threshold != 1) { print("-- value changed: " + data["info"][component_item] + " - no action needed"); } } else { print("-- value changed: " + data["info"][component_item] + " - switching paused"); } if (pause_threshold == 1) { if (data["info"][component_item] > threshold) { print("Ready and waiting.") pause_threshold = 0; } else { if (pause_time != 1) { print("-- value changed: " + data["info"][component_item] + " - waiting value to be < threshold"); } } } } } } );
-
I'm using a Plus2PM setup with a script to reset an MCB, its slightly more complex as mine uses a light sensor to determine if a device has crashed. However either way what you need is a 16A contactor, wire the contactor to the Shelly and treat it as a big relay.
Then use the input side to determine when the pump should run. You could use a water sensor for example or similar. The input side is quite smart so you can use thresholds rather than just binary levels.
-
Please try the following script. It switches on when threshold <= 20 % for 10 seconds, then off for 30 seconds und gets ready only if the threshold is > 20 % again.
The many print messages are only for debugging.
This is amazing Nordlicht_2023, works perfectly tomorrow I am going to read up on those links for WhatsApp integration. I cannot find anything for email for some reason.
Thanks again and have a splendid evening.
Andrew. -
AJSG1969 Do you need a switch action every time the value changed to < 20 % ?
I expect that value to drop to below 20% no more than once a day. Whilst the process is critical the timing isn't so in theory if the action occurs a few minutes after the LED starts flashing and causes the percentage to fall then its ok. However at that stage I would need some kind of notification which can generate an iOS pop up of sorts.
Imagine I need to automatically reboot a PC, which crashes about once a day, when it crashes an LED starts blinking. However that same LED also blinks when the PC boots up.Thank you very much.
-
What your are looking for is two Timer inside a Event Loop, that filters for Input 100 events.
I'm going to have a read but the voltage and hence the percentage is almost constantly changing by small amounts.
Much obliged. -
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.
Think going back to basics is clearer than me posting code:
Check for light < 20% if true
Switch on for 10 seconds
then Switch off a further 30 seconds
then loop
The id:100 input is a simple photoresistor. With a variable percentage value between 0 and 100%. I do not think it fits into the "event" bracket.
Thank you. -
Hmm, this is an issue because I need to:
Check for light < 20% if true
Switch on for 10 seconds
then Switch off a further 30 seconds
then loop
The issue is that the script needs to stop for 30 seconds and not process further readings. The device reboot causes its LEDs to flash which would send the script into a reboot loop!
In Actions the issue is that you cannot set "Repeat When" > "Set Flip value after property"
Code
Alles anzeigenfunction lightcheck () { Shelly.call("Input.GetStatus",{ id:100}, function (result, err_code, err_message, user_data) { if (err_code === 0) { console.log("LightValue:", result['percent']); if (result['percent'] < 20.0) { print("light") Shelly.call("Switch.Set","{ id:0, on:true }",null,null); } else { print("dark") Shelly.call("Switch.Set","{ id:0, on:false}",null,null); } } else { console.log("Error:", err_message); } } ); }; let timer_handle = Timer.set(10000,true,lightcheck,null); function callback(userdata) { Shelly.call("Switch.Set","{ id:0, on:false}",null,null); } let timer_handle = Timer.set(30000,true,callback,null);
-
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"
Code
Alles anzeigenShelly.call("Input.GetStatus",{ id:100}, function callback(result, err_code, err_message, user_data) { if (err_code === 0) { console.log("LightValue:", result['percent']); if (result['percent'] < 20.0) { print("light") Shelly.call("Switch.Set","{ id:0, on:true }",null,null); let timer_handle = Timer.set(2000,true,callback,null); Shelly.call("Switch.Set","{ id:0, on:false}",null,null); } else { print("dark") Shelly.call("Switch.Set","{ id:0, on:false}",null,null); let timer_handle = Timer.set(1000,true,callback,null); } } else { console.log("Error:", err_message); } } );
-
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
Code
Alles anzeigenfunction 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);
Any help gratefully received.
Thanks,
Andrew.