Page 1 of 1
Using TIME in dzvents
Posted: Friday 19 August 2022 17:59
by solarboy
I am just getting started with dzvents but still struggling with using time in my scripts.
Could someone point out to me where I am going wrong, I find the dzvents wiki quite hard to understand.
Code: Select all
return {
on = {
timer = { 'every 1 minutes'},
},
execute = function(domoticz,Item)
local Time = require('Time')
local now = Time()
if now == '16:54'
then domoticz.log('PASSED TEST', domoticz.LOG_ERROR)
print(now)
else
domoticz.log('FAILTEST', domoticz.LOG_ERROR)
print(now)
end
end
}
Re: Using TIME in dzvents
Posted: Friday 19 August 2022 18:10
by solarboy
Basically I am trying to recreate what in Blockly would be
I have tried quite a few variations and still no luck.
Re: Using TIME in dzvents
Posted: Friday 19 August 2022 18:33
by solarboy
For example this
Code: Select all
return {
on = {
timer = { 'every 1 minutes'},
},
execute = function(domoticz,Item)
if domoticz.time() == '17:27'
then domoticz.log('PASSED TEST2', domoticz.LOG_FORCE)
end
end
}
Obviously I am missing something.
Re: Using TIME in dzvents
Posted: Friday 19 August 2022 20:08
by waltervl
Use
To start something at 17:27
For testing be sure you set a time > 2 minutes after current time. Else Domoticz will probably not be triggered as timers are stored every minute.
Re: Using TIME in dzvents
Posted: Friday 19 August 2022 20:10
by waltervl
Tip: to switch something simple on/off use the standard timer function, see wiki
https://www.domoticz.com/wiki/Managing_ ... ice_Timers
Re: Using TIME in dzvents
Posted: Friday 19 August 2022 20:32
by solarboy
Thanks for the response

. I am using virtual switches as timer devices for now,and calling them as devices...
if dz.device('My virtual switch').state == 'On'
then...
I just thought there might be another way.
So I guess with your first suggestion, I would add
as my trigger, and then capture the triggered that as an item which triggered the script in the execute/function part.
Sometimes I would like to have various timers in one script that can be individually referenced in the function.
Seems quite a complex way of working with time in a function.
Re: Using TIME in dzvents
Posted: Friday 19 August 2022 20:37
by solarboy
For example. I often would like a script such as.
Code: Select all
If switch1 == 'On' and time == '17:57'
then switch 2.switchOn()
elseif switch1 == 'On' and time == '23:00'
then switch3.switchOn()
end
Re: Using TIME in dzvents
Posted: Saturday 20 August 2022 0:49
by waltervl
You can use the matchesRule(rule) function for this eg.
If switch1 == 'On' and domoticz.time.matchesRule(' at 17:27') then
Re: Using TIME in dzvents
Posted: Saturday 20 August 2022 2:35
by solarboy
That's exactly what I was looking for ! Thank you so much !