Page 1 of 1

Building a Timer Script in DZvents

Posted: Monday 03 March 2025 12:15
by masselb
Hello @all,

I have tried to build a timer script by putting 2 selectors: 1) select your device and 2) select a time (15,30,60,120 mins)
Then a "start" button which starts the timer, and I put a blockly in place to manage the timing. It is working, but not very seamlessly..

As I am no Wizzard with scripting I reckon this should be done by a DZvents script, question is how? The principal is simple; set the two selectors and press start.. well at least in my mind it's not complex, but how to put this in a Script....

Wenn there is anyone who could give me a direction I woul dbe very Greatfull!

Re: Building a Timer Script in DZvents

Posted: Monday 03 March 2025 13:41
by waltervl
What should it do after you press start? Toggle the selected device after countdown?

Re: Building a Timer Script in DZvents

Posted: Monday 03 March 2025 14:13
by masselb
Hey Walter, yes it should activate the device and deactivate it after the selected time frame.. The problem I have with Blockly is that the number of combinations possible (Let's say 10 devices and 5 possible time frames) makes the matter really "heavy" and extensive. I was thinking (but I'm not more than an noob in scripting) that with a DZvents-script the matter would be way more "thin" and smarter..

Re: Building a Timer Script in DZvents

Posted: Monday 03 March 2025 15:05
by waltervl
Something like this (not tested!!!!)
It assumes you have 3 devices:
1. 'Your Device Selector' with the list of devices and levelName should be exact device name
2. 'Your Timer Selector' with a list of timer options and levelname should be the timers in minutes
3 'Your Start Device' eg a Push On button switch.
Modify the names of in the script according your own devices.

Code: Select all

    return {
        on = {
            devices = {
            'Your Start Device' -- this device triggers the timer script
            }
        },
        execute = function(domoticz, switch)
			-- Device that has the list of devices. 
			-- levelName should be exact device name.
			local SelectedDevice = domoticz.devices('Your Device Selector').levelName 
			-- Device that has the list of timers eg 15,30,60,120 
			-- levelName should be the time in minutes.
			local SelectedTimer = domoticz.devices('Your Timer Selector').levelName 
			domoticz.devices(SelectedDevice).switchOn() -- Switch the selected device on
			domoticz.devices(SelectedDevice).switchOff().afterMin(tonumber(SelectedTimer)) -- Switch the device off after selected minutes
        end
    }

Re: Building a Timer Script in DZvents

Posted: Thursday 06 March 2025 16:56
by masselb
Hey Walter,
Thanks a million, I will test this would be really cool when this solves my Timer Wish (and Blockly headache:) )

I will report back you you!

Re: Building a Timer Script in DZvents

Posted: Friday 07 March 2025 9:47
by masselb
Good Morning Walter,

Looks like this works! Thanks! The "start button" is in this case a normal switch, I will test it with a pressing-button because I have to set the switch back manually. Should work i guess. Maybe a simple question; Can I make a copy of the script with a second "start" to be able to run a second timer?

Thanks, Bert

Re: Building a Timer Script in DZvents

Posted: Friday 07 March 2025 17:45
by waltervl
With the Edit button on the switch device widget you can change the type to PushOn.

Yes you can make a second script with different devices, no problem with that.