waltervl wrote: ↑Tuesday 19 November 2024 21:46
What is that certain case? Can it be calculated by dzvents?
First, thanks a lot for your reply. Very appreciated.
Yes. It can be calculated by dzvents.
The case is:
I have a smart plug which measures and switches the power supply to my computer peripherals (monitor, speakers, usb-dock etc).
I want it to switch off when the power is below a certain threshold. Sounds very simple.
Version 1:
I created a simple script which turns the switch off in case the switch is on and the power was below the threshold. Trigger is a change in power consumption.
Problems:
1. The power was not updated quick enough, so it turned the switch off immediately after it switched on.
2. The power was cut too fast for me to change the USB-dock plug from my private laptop to my work-laptop.
Conclusion: delay needed.
Version 2:
I changed the switchoff command to switch.switchOff().afterSec(100) and added a switch.cancelQueuedCommands() in case the power got above the threshold within the 100 seconds.
Problem:
1. In standby my laptop still consumes very short peaks of power from the USB-port, probably to keep the battery charged. These peaks keep triggering the switch.cancelQueuedCommands(), so the equipment never turns off.
Conclusion: A short peak may not trigger the switch.cancelQueuedCommands().
Version 3:
Added a counter which counts these power peaks and which is reset when the power is below the threshold. Only when the counter is >1 the switch.cancelQueuedCommands() is sent. This works very well for my private laptop. Switch does exactly what I want.
Problem:
1. My work laptop is power hungry and has its own power supply (not measured by smart plug). So when it is connected, the measured power is very constant and the power consumption is rarely updated, so the script is rarely triggered, and my counter never reaches >1, so the switch.cancelQueuedCommands() is never sent and my equipment switches unintentionally off.
So I need a Version 4:
Which somehow restarts the script one or a few times after the switch.switchOff().afterSec(100) command was given to check if the switch.cancelQueuedCommands() should be sent.
But the big question is: How do I restart the script after maybe 1 minute?
You can also always rerun the script after 1 or 2 minutes after a device change.
That would be a good solution, but how can I run a script not only
at the device change, but also 1 or 2 minutes
after such a change?