Page 1 of 1
Very basic off/on with timer
Posted: Friday 28 August 2020 20:02
by tontze
Hi !
Im a blockly user, but blockly does not support seconds, so im out of luck there :/
Im looking for a very basic script, turning switch off->on defined number of times with defined interval. Is this done how ?
Thank you in advance

Re: Very basic off/on with timer
Posted: Friday 28 August 2020 20:07
by snellejellep
does the timer function of a switch not fill your needs?
Re: Very basic off/on with timer
Posted: Friday 28 August 2020 20:43
by tontze
snellejellep wrote: ↑Friday 28 August 2020 20:07
does the timer function of a switch not fill your needs?
Nope, i need seconds

Otherwise i would have been doing it with blockly ..
Re: Very basic off/on with timer
Posted: Friday 28 August 2020 20:59
by waaren
tontze wrote: ↑Friday 28 August 2020 20:43
snellejellep wrote: ↑Friday 28 August 2020 20:07
does the timer function of a switch not fill your needs?
Nope, i need seconds

Otherwise i would have been doing it with blockly ..
What should trigger the actions ?
Re: Very basic off/on with timer
Posted: Friday 28 August 2020 21:00
by snellejellep
you can do it in dzvents with for example <switchname>.switchOff().afterSec(5) which switches it off after 5 seconds
Re: Very basic off/on with timer
Posted: Friday 28 August 2020 21:59
by tontze
waaren wrote: ↑Friday 28 August 2020 20:59
tontze wrote: ↑Friday 28 August 2020 20:43
snellejellep wrote: ↑Friday 28 August 2020 20:07
does the timer function of a switch not fill your needs?
Nope, i need seconds

Otherwise i would have been doing it with blockly ..
What should trigger the actions ?
certain time of day, like 20:00, switch is on, then it switches off and on 6 times in 1 sec interval, and stays on.
Re: Very basic off/on with timer
Posted: Friday 28 August 2020 22:00
by tontze
snellejellep wrote: ↑Friday 28 August 2020 21:00
you can do it in dzvents with for example <switchname>.switchOff().afterSec(5) which switches it off after 5 seconds
Il look in to it, thnx
Re: Very basic off/on with timer
Posted: Friday 28 August 2020 22:16
by snellejellep
tontze wrote: ↑Friday 28 August 2020 22:00
snellejellep wrote: ↑Friday 28 August 2020 21:00
you can do it in dzvents with for example <switchname>.switchOff().afterSec(5) which switches it off after 5 seconds
Il look in to it, thnx
this should do the trick, turning it on and off 6 times and then leaving it on at 20:00
i assumed it would be a lamp so called it that but you can fill in the name of the switch you want to use in place of yourlampnameoridx
Code: Select all
return {
on ={
timer={
'at 20:00' -- the time at which this script should trigger
}
},
execute = function(dz, device)
local lamp = dz.devices("yourlampnameoridx")
lamp.switchOn()
lamp.switchOff().afterSec(1)
lamp.switchOn().afterSec(2)
lamp.switchOff().afterSec(3)
lamp.switchOn().afterSec(4)
lamp.switchOff().afterSec(5)
lamp.switchOn().afterSec(6)
lamp.switchOff().afterSec(7)
lamp.switchOn().afterSec(8)
lamp.switchOff().afterSec(9)
lamp.switchOff().afterSec(10)
lamp.switchOn().afterSec(11)
end
}
Re: Very basic off/on with timer
Posted: Friday 28 August 2020 23:28
by waaren
tontze wrote: ↑Friday 28 August 2020 21:59
certain time of day, like 20:00, switch is on, then it switches off and on 6 times in 1 sec interval, and stays on.
dzVents version
Code: Select all
return
{
on =
{
timer =
{
'at 20:00',
},
},
execute = function(dz)
light = dz.devices('Flicker')
for i = 0, 12, 2 do
light.switchOff().afterSec(i)
light.switchOn().afterSec(i + 1)
end
end
}
Classic Lua version (save with trigger type timer)
Code: Select all
local executionTime = '20:00'
local light = 'Flicker' -- Name of your light
commandArray = {}
if os.date('%H:%M') == executionTime then
for i = 0, 12, 2 do
commandArray[#commandArray + 1] = { [light] = 'Off AFTER ' .. i }
commandArray[#commandArray + 1] = { [light] = 'On AFTER ' .. (i + 1) }
end
end
return commandArray
Blockly (save with trigger type timer)

- flickr.png (60.52 KiB) Viewed 900 times