Page 1 of 2
dzVents - Possible to use a variable for a timed event
Posted: Tuesday 31 July 2018 13:06
by rbisschops
Hi All,
As I'm using dzVents for all my Lua scripts now, i stumbled into a thought, but not sure how to do this or even if it is possible.
I created a script controling my blinds. It lowers the blinds at a fixed time in the morning and raises them in the evening. Both at a fixed time coded in the script as follows:
Code: Select all
return {
active = true,
on = {
timer = {
'at 07:30',
'at 17:30'
}
},
As we (the wife) wants to be able to influence the timers, I would like to put these in a variable in Domoticz. Is it possible to use the variables for the timed events. So something like:
I know this code won't work, but is put in as an example to explain my thinking
Thanks all for your thoughts.
Ralph
Re: dzVents - Possible to use a variable for a timed event
Posted: Friday 03 August 2018 14:44
by TheCondor
Re: dzVents - Possible to use a variable for a timed event
Posted: Sunday 05 August 2018 9:00
by rbisschops
Hi,
That is not exactly what i was lookling for. I want the time set in the domoticz variable to be the trigger. So 7:30 in the variable should be the trigger to kick off the script. For now I have a 15 minute time trigger and check in the script if the domo variable time is the same as the system time. This has some limitations in the time you set in the variable.
Re: dzVents - Possible to use a variable for a timed event
Posted: Sunday 05 August 2018 21:02
by waaren
I guess the solution is to read the content of the var when it changed and with that content calculate what the afterSec should be to be used with an openURL of which the repsonse will trigger the event that will do your required action and do sent the openURL in 24 hours.
Re: dzVents - Possible to use a variable for a timed event
Posted: Monday 06 August 2018 16:26
by rbisschops
@waaren: but unfortunately the var does not change that often (its more a setting)
Re: dzVents - Possible to use a variable for a timed event
Posted: Monday 06 August 2018 17:50
by randytsuch
Define the time as a user variable of type string.
Then you can read it into dzvents
Re: dzVents - Possible to use a variable for a timed event
Posted: Tuesday 07 August 2018 4:26
by randytsuch
Oops, I lied
Make a user variable of type time
Then, if you can do something like this to create local variables with hours and mins, for example.
local thour = domoticz.variables('SpkrStart').time.hour
local tmin = domoticz.variables('SpkrStart').time.min
user variable is name SpkrStart in the user variable page, with value set to whatever time you want to use, ie 19:00
Re: dzVents - Possible to use a variable for a timed event
Posted: Tuesday 07 August 2018 10:05
by waaren
rbisschops wrote: ↑Monday 06 August 2018 16:26
@waaren: but unfortunately the var does not change that often (its more a setting)
What you can do is trigger a script on that variable change and use the appropriate API call to delete / add the timer for that the device.
Look at the domoticz API wiki
domoticz API wiki for the exact syntaxis of the calls
Re: dzVents - Possible to use a variable for a timed event
Posted: Tuesday 07 August 2018 18:08
by waaren
rbisschops wrote: ↑Monday 06 August 2018 16:26
@waaren: but unfortunately the var does not change that often (its more a setting)
Something like this ?
Code: Select all
-- setTimers.lua
return {
on = { variables = {"timer*"}}, -- One time var for On and one for Off
execute = function(dz,triggerObject)
local myDevice = 1012 -- myDevice = idx of myDevice
local onTimeVar = "timerTestOn" -- uservariable of type time, format hh:mm
local offTimeVar = "timerTestOff"
local function clearTimers(idx)
local api = dz.settings['Domoticz url'] .. "/json.htm?type=command¶m=cleartimers&idx=".. idx
dz.openURL({ url = api, method = "GET" })
end
local function decomposeVarTime(timeVar)
return dz.variables(timeVar).time.hour, dz.variables(timeVar).time.minutes
end
local function setTimers(idx,sethour,setminute,state)
local command = 0
if state == "Off" then
command = 1
end
local api = dz.settings['Domoticz url'] .. "/json.htm?active=true&command=" .. command ..
"&hour=".. sethour ..
"&min=" .. setminute .. "¶m=addtimer" ..
"&randomness=false&timertype=2;&type=command&days=1234567&idx=" .. idx
dz.openURL({ url = api, method = "GET" })
end
clearTimers(myDevice)
local hour,minute = decomposeVarTime(onTimeVar)
setTimers(myDevice,hour,minute)
hour,minute = decomposeVarTime(offTimeVar)
setTimers(myDevice,hour,minute,"Off")
end
}
Re: dzVents - Possible to use a variable for a timed event
Posted: Tuesday 07 August 2018 21:53
by randytsuch
Re: dzVents - Possible to use a variable for a timed event
Posted: Thursday 09 August 2018 17:01
by rbisschops
@waaren: Thx for setting this up. Highly appreciated!
Is it possible to do this:
Code: Select all
dz.variables(timeVar).time.hour, dz.variables(timeVar).time.minutes
As far as I understand from the documentation, its a string (even though its a date var)
What I can't figure out is why you use:
This requires one of the variables to change right? Otherwise the script won't fire.
Thx
Ralph
Re: dzVents - Possible to use a variable for a timed event
Posted: Thursday 09 August 2018 18:28
by waaren
rbisschops wrote: ↑Thursday 09 August 2018 17:01
@waaren: Thx for setting this up. Highly appreciated!
Is it possible to do this:
Code: Select all
dz.variables(timeVar).time.hour, dz.variables(timeVar).time.minutes
As far as I understand from the documentation, its a string (even though its a date var)
yes this works. I tested this with uservars type time
What I can't figure out is why you use:
This requires one of the variables to change right? Otherwise the script won't fire.
Thx
Ralph
The idea is that when one uservar is changed a new set of timers (on/off) will be set after the current ones are cleared.
Until the uservar is changed again the timerset will stay active.
That is what I understand was your requirement.
Re: dzVents - Possible to use a variable for a timed event
Posted: Friday 10 August 2018 8:35
by rbisschops
waaren wrote: ↑Thursday 09 August 2018 18:28
rbisschops wrote: ↑Thursday 09 August 2018 17:01
@waaren: Thx for setting this up. Highly appreciated!
Is it possible to do this:
Code: Select all
dz.variables(timeVar).time.hour, dz.variables(timeVar).time.minutes
As far as I understand from the documentation, its a string (even though its a date var)
yes this works. I tested this with uservars type time
Which version did you test this on (i'm on V3.9639)? I have user vars of typ time in my Domoticz, but when I add the code you propose, I get a nil value.
Re: dzVents - Possible to use a variable for a timed event
Posted: Sunday 12 August 2018 16:55
by waaren
rbisschops wrote: ↑Friday 10 August 2018 8:35
waaren wrote: ↑Thursday 09 August 2018 18:28
rbisschops wrote: ↑Thursday 09 August 2018 17:01
@waaren: Thx for setting this up. Highly appreciated!
Is it possible to do this:
Code: Select all
dz.variables(timeVar).time.hour, dz.variables(timeVar).time.minutes
As far as I understand from the documentation, its a string (even though its a date var)
yes this works. I tested this with uservars type time
Which version did you test this on (i'm on V3.9639)? I have user vars of typ time in my Domoticz, but when I add the code you propose, I get a nil value.
Tested with V4.9796

- timeVars.PNG (60.12 KiB) Viewed 5501 times
Re: dzVents - Possible to use a variable for a timed event
Posted: Monday 17 September 2018 15:19
by Inso80
randytsuch wrote: ↑Monday 06 August 2018 17:50
Define the time as a user variable of type string.
Then you can read it into dzvents
If I may ask: how?
I am planning to do a lot with my global variables. Timer will become important, also f.e.
would be awesome to be changeable with (global?) variables.
If I try
Code: Select all
active = domoticz.variables(domoticz.globalData.test),
it tells me
Code: Select all
Status: dzVents: Error (2.4.6): .../domoticz/scripts/dzVents/generated_scripts/testVari.lua:3: attempt to index field 'globalData' (a nil value)
Printing domoticz.globalData.test in log shows true.
Also if I just try "active = domoticz.globalData.test" , active = domoticz.variables(globalData.test) and so on, I always get an error.
I also had the problem with time =domoticz.globalData.test
What am I missing? Dzvents documentation does not show anything helpful, it only says
Seems to be a bit awkward to create dummies within domotics for every global variable and then change them using the api and so on.
Re: dzVents - Possible to use a variable for a timed event
Posted: Monday 17 September 2018 18:19
by waaren
Inso80 wrote: ↑Monday 17 September 2018 15:19
.....
What am I missing? Dzvents documentation does not show anything helpful, it only says
...
the active = section defaults to true and can only be true or false
If you need to evaluate something from domoticz you have to parse the domoticz object to it.
Something like
Code: Select all
active = function(domoticz)
return domoticz.startTime.secondsAgo < 180
end,
works
Re: dzVents - Possible to use a variable for a timed event
Posted: Monday 17 September 2018 20:11
by Inso80
waaren wrote: ↑Monday 17 September 2018 18:19
Inso80 wrote: ↑Monday 17 September 2018 15:19
.....
What am I missing? Dzvents documentation does not show anything helpful, it only says
...
the active = section defaults to true and can only be true or false
If you need to evaluate something from domoticz you have to parse the domoticz object to it.
Something like
Code: Select all
active = function(domoticz)
return domoticz.startTime.secondsAgo < 180
end,
works
Thanks for your reply.
Do you know any way to parse (global) variables this way (which can also be true or false)? Atm the only way I see to parse "a text of my choice" seems to be to set a text note to the text I want, (f.e.: true, 6:30..) and then parse the value of it where I need my variable..
Re: dzVents - Possible to use a variable for a timed event
Posted: Monday 17 September 2018 22:56
by waaren
Inso80 wrote: ↑Monday 17 September 2018 20:11
Do you know any way to parse (global) variables this way (which can also be true or false)? Atm the only way I see to parse "a text of my choice" seems to be to set a text note to the text I want, (f.e.: true, 6:30..) and then parse the value of it where I need my variable..
Not quite sure I understand your question.
Do you mean domoticz variables or variables from dzVents persistent data or something else?
Re: dzVents - Possible to use a variable for a timed event
Posted: Monday 17 September 2018 23:58
by Inso80
waaren wrote: ↑Monday 17 September 2018 22:56
Not quite sure I understand your question.
Do you mean domoticz variables or variables from dzVents persistent data or something else?
In short what I am planning to do: I´d like to change the time of my WakeUpLight on multiple places. MySensors, here in Domoticz event manager, later on Raspi, tasker at my phone and so on.
So i´d like to have a variable to store the time, which I can read, update and so on.
Some of my variables are global (f.e. CT and brightness), located in domoticz/scripts/dzVents/scripts/global_data.lua
I can read and manipulate them perfectly within execute = function...
but if I try to replace
with
Code: Select all
active = domoticz.globalData.myVar
while myVar = 'true', I get the error it has a nil value. Also havent found a way to convert String to boolean in Lua or something like this.
same with
Code: Select all
timer = { domoticz.globalData.myVar }
, I can not just set the variable to 'at 6:30'
log always says:
Code: Select all
attempt to index field 'globalData' (a nil value)
and
Code: Select all
timer = { 'domoticz.globalData.myVar' }
simply does not get executed.
Would be perfect if I could get that to work.
For the case it is not possible:
I have checked other options. Easiest seemed to be a text dummy. With your hint I got
Code: Select all
active = function(domoticz)
return domoticz.devices('Texttest').text == os.date("%H")
end,
running
Strangely,
Code: Select all
active = true,
on ={
timer = function(domoticz)
return domoticz.devices('Texttest').text == os.date("%H")
end,
},
does _not_ run a single time. As the wiki says, timer = should be triggered every minute. "active = " runs fine while "timer =" using same function call was not executed a single time within ~30 minutes.
Re: dzVents - Possible to use a variable for a timed event
Posted: Tuesday 18 September 2018 0:46
by waaren
Inso80 wrote: ↑Monday 17 September 2018 23:58
Strangely,
Code: Select all
active = true,
on ={
timer = function(domoticz)
return domoticz.devices('Texttest').text == os.date("%H")
end,
},
does _not_ run a single time. As the wiki says, timer = should be triggered every minute. "active = " runs fine while "timer =" using same function call was not executed a single time within ~30 minutes.
You are close...
Code: Select all
return {
on = {
timer = { function(domoticz)
return domoticz.devices('Texttest').text == os.date("%H")
end
}},
execute = function(domoticz)
print ( "Executing!!!")
end
}
But would it not be less complicated to use timer = { "every minute" }, and a helper function in the execute = section as described
here ?