Page 1 of 1
how can i get the value of a timer into a variable?
Posted: Sunday 21 January 2024 12:19
by bitzy
english is not primary language so i'm sure the title is not suggestive and the explanation will be a struggle
i want to take the value that i set for a timer into a variable inside the script, something like:
timer = { 'every x minutes' }
...
local dt = time_Of_The_Timer -- (x).
i know i can do this manually when i set the value of the timer (but i'm kinda lazy) so i want this to be done automatically when i change 'x', in case i forget to change dt also. is there a way to do this?
Re: how can i get the value of a timer into a variable?
Posted: Sunday 21 January 2024 18:28
by waltervl
You could do it the other way around:
local dt = time_Of_The_Timer
timer = { 'every dt minutes' }
Re: how can i get the value of a timer into a variable?
Posted: Sunday 21 January 2024 18:43
by willemd
Or you could take the second value after you split the trigger into words, as shown in the example dzVents script below
Code: Select all
return {
on = {
timer = {
'every 2 minutes',
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'template',
},
execute = function(domoticz, timer)
domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
local deltaT=domoticz.utils.stringSplit(timer.trigger," ")[2]
domoticz.log("deltaT="..deltaT, domoticz.LOG_INFO)
end
}
Re: how can i get the value of a timer into a variable?
Posted: Sunday 21 January 2024 19:02
by Kedi
waltervl wrote: ↑Sunday 21 January 2024 18:28
You could do it the other way around:
local dt = time_Of_The_Timer
timer = { 'every dt minutes' }
Sorry @waltervl that does not work, this works:
Code: Select all
local dt = 2
return {
on = {
timer = {
'every '..tostring(dt)..' minutes',
},
And sorry @willemd I think it is the better solution: does not involve further programming.
Re: how can i get the value of a timer into a variable?
Posted: Sunday 21 January 2024 19:44
by HvdW
Or use
Code: Select all
local current_time = os.date("%c")
and
Code: Select all
local subject = 'My time in a string. '
local message =
' ' .. current_time .. '\n'..
'Succeede ! \n'
domoticz.notify(subject, message, domoticz.PRIORITY_NORMAL)
Where current_time is your string.
Formatting the output of os.date() is
explained over here.
Re: how can i get the value of a timer into a variable?
Posted: Tuesday 23 January 2024 7:04
by bitzy
waltervl wrote: ↑Sunday 21 January 2024 18:28
You could do it the other way around:
local dt = time_Of_The_Timer
timer = { 'every dt minutes' }
was so easy, i feel a little bit ashamed now
for me worked:
dt = 2
timer = {'every '..dt..' minutes'} and also the Kedi's version.
the local dt=domoticz.utils.stringSplit(timer.trigger," ")[2] don't work for me. i get an error related to the use of 'timer.trigger' - attempt to index a nil value 'timer'
thanks for the answears.
Re: how can i get the value of a timer into a variable?
Posted: Tuesday 23 January 2024 9:50
by willemd
It does not work because you probably don't have execute=function(domoticz,timer) in your script but something else for example "item" instead of "timer".
If you use "item" then you should also use "item.trigger". It has to match.
Re: how can i get the value of a timer into a variable?
Posted: Tuesday 23 January 2024 14:14
by bitzy
willemd wrote: ↑Tuesday 23 January 2024 9:50
It does not work because you probably don't have execute=function(domoticz,timer) in your script but something else for example "item" instead of "timer".
If you use "item" then you should also use "item.trigger". It has to match.
u are right

. is working now