Building a Timer Script in DZvents
Moderator: leecollings
-
masselb
- Posts: 27
- Joined: Friday 06 September 2019 11:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Building a Timer Script in DZvents
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!
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!
- waltervl
- Posts: 7002
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2026.3
- Location: NL
- Contact:
Re: Building a Timer Script in DZvents
What should it do after you press start? Toggle the selected device after countdown?
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
-
masselb
- Posts: 27
- Joined: Friday 06 September 2019 11:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Building a Timer Script in DZvents
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..
- waltervl
- Posts: 7002
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2026.3
- Location: NL
- Contact:
Re: Building a Timer Script in DZvents
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.
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
}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
-
masselb
- Posts: 27
- Joined: Friday 06 September 2019 11:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Building a Timer Script in DZvents
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!
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!
-
masselb
- Posts: 27
- Joined: Friday 06 September 2019 11:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Building a Timer Script in DZvents
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
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
- waltervl
- Posts: 7002
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2026.3
- Location: NL
- Contact:
Re: Building a Timer Script in DZvents
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.
Yes you can make a second script with different devices, no problem with that.
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
-
masselb
- Posts: 27
- Joined: Friday 06 September 2019 11:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Building a Timer Script in DZvents
Good day Walter (or another script wizzard),
I still have this script running seamlessly, but when i was busy building a new dashboard i thought of a small extension of this Timer script. Would it be possible to set a "warning" device for the same periode the chosen device is active? This way, I can see when the Timer is finished on my dashboard and wheter the Timer can be set off again. I reckon an Virtual device will do the trick?
Thanks! Bert
I still have this script running seamlessly, but when i was busy building a new dashboard i thought of a small extension of this Timer script. Would it be possible to set a "warning" device for the same periode the chosen device is active? This way, I can see when the Timer is finished on my dashboard and wheter the Timer can be set off again. I reckon an Virtual device will do the trick?
Thanks! Bert
- waltervl
- Posts: 7002
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2026.3
- Location: NL
- Contact:
Re: Building a Timer Script in DZvents
It is easier to set the Device selector device to Off together with the selected device.
If the Selector device has a value then the timer is active. If the selector device is Off then there is no timer active.
add line
If the Selector device has a value then the timer is active. If the selector device is Off then there is no timer active.
add line
Code: Select all
domoticz.devices('Your Device Selector').switchOff().afterMin(tonumber(SelectedTimer))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
-
masselb
- Posts: 27
- Joined: Friday 06 September 2019 11:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Building a Timer Script in DZvents
Ah! Ok see what you mean; I make the push on button a normal switch and the script sets it back when the timer ends.. Correct?
Make sense... even for me
Make sense... even for me
- waltervl
- Posts: 7002
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2026.3
- Location: NL
- Contact:
Re: Building a Timer Script in DZvents
Ah, no I was looking at the device selector device. So you set a device and a time. Then push the button. As long as the device selector has a value (eg device X) the timer is active. After the time has finished the script changes the device selector from Device X to Off (no value).
This is only possible if you have only 1 timer active.
This is only possible if you have only 1 timer active.
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
-
masselb
- Posts: 27
- Joined: Friday 06 September 2019 11:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Building a Timer Script in DZvents
Ah ok, see what you mean.. I have two timers in place, with the same device/time selector which runs perfectly. So would it be possible then to switch a Virtual device on with the script for the same period of time that selected device is active? When the time ends, it switches the virtual device to off and the script is ready for a new run. Something like that?
- waltervl
- Posts: 7002
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2026.3
- Location: NL
- Contact:
Re: Building a Timer Script in DZvents
Yes, that would be possible. Create multiple timer active (virtual) devices (one per device you want to monitor) and adapt the script.
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