I have a script that is triggered by a device. This works well.
But only in a certain case, the script detects that it has to rerun after one or two minutes, to check a certain state. This is needed maybe twice a day.
How can I accomplish that? Is it even possible?
(I can of course start the script every minute AND by the device, but that will start the script (24-60 = 1440) - 2 = 1438 unnecessary times a day. A waste of cpu-power, so I do not prefer that.)
Script, only triggered by a device, should sometimes restart itself after one minute. How?
Moderator: leecollings
-
- Posts: 320
- Joined: Thursday 01 November 2018 19:47
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.6
- Location: Portugal
- Contact:
Re: Script, only triggered by a device, should sometimes restart itself after one minute. How?
I use dummy devices for this which I set to turn on after an amount of time, and use them as triggers for the event.
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
- waltervl
- Posts: 5380
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Script, only triggered by a device, should sometimes restart itself after one minute. How?
What is that certain case? Can it be calculated by dzvents?
You can also always rerun the script after 1 or 2 minutes after a device change.
You can also always rerun the script after 1 or 2 minutes after a device change.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Re: Script, only triggered by a device, should sometimes restart itself after one minute. How?
Thanks. That sounds like a viable idea. But how do I turn a dummy device on after an x amount of time from a dzvent script?
Is that something like:
1. Retrieve current time,
2. Add 1 minute.
3. Change a dummy device to start at that time (no idea how to accomplish that).
And then, when the script is started by the dummy device.
4. Remove the previous timer from the dummy device (again, no idea how to do that part).
Can you give me a hint about items no. 3 and 4? Or maybe there is an easier way to do that?
-
- Posts: 529
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: Script, only triggered by a device, should sometimes restart itself after one minute. How?
Ask CoPilot, the Microsoft version of AI which is native in Edge.
Open the page which shows your script, then open CoPilot and ask CoPilot to adapt your script.
Don't forget to realise that AI is able to see the content of the current page of your browser.
Open the page which shows your script, then open CoPilot and ask CoPilot to adapt your script.
Don't forget to realise that AI is able to see the content of the current page of your browser.
Bugs bug me.
- waltervl
- Posts: 5380
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Script, only triggered by a device, should sometimes restart itself after one minute. How?
For now the worst advise you can give as AI does not understand dzVents good enough..... I seen some very bad examples coming from that path unfortunately.
Use a command option: https://wiki.domoticz.com/DzVents:_next ... riggering)How do I turn a dummy device on after an x amount of time from a dzvent script
eg
Code: Select all
device.switchOn().afterMin(2).forSec(10)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Re: Script, only triggered by a device, should sometimes restart itself after one minute. How?
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?
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?You can also always rerun the script after 1 or 2 minutes after a device change.
Re: Script, only triggered by a device, should sometimes restart itself after one minute. How?
Sorry, typing my previous message took too long. Got disturbed a few times.waltervl wrote: ↑Wednesday 20 November 2024 9:27Use a command option: https://wiki.domoticz.com/DzVents:_next ... riggering)How do I turn a dummy device on after an x amount of time from a dzvent script
egCode: Select all
device.switchOn().afterMin(2).forSec(10)
Thanks for this hint! That is actually very simple. This will most likely solve my problem!
Edit: Changed it to device.toggle().afterSec(40).forSec(40), to make my script restart twice, at 40 and 80 seconds after this command ran.
Who is online
Users browsing this forum: No registered users and 0 guests