Page 1 of 1
Syntax
Posted: Saturday 02 May 2020 10:31
by jkimmel
I want temperature beeing read every 3 minutes.
Is this ok?
Code: Select all
devices =
{
SETPOINT_DEVICE,
TEMPERATURE_SENSOR = {'every 3 minutes' }
}
},
Because temperature does not trigger the script
Re: Syntax
Posted: Saturday 02 May 2020 11:09
by waaren
jkimmel wrote: ↑Saturday 02 May 2020 10:31
I want temperature being read every 3 minutes.
Is this ok?
No this does not work. You should use something like
Code: Select all
return
{
on =
{
timer =
{
'every 3 minutes',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- switch to LOG_ERROR when OK
marker = 'time triggered temp reading',
},
execute = function(dz)
local setpoint = dz.devices(SETPOINT_DEVICE).setPoint
local temperature = dz.devices(TEMPERATURE_SENSOR).temperature
-- rest of your code
end
}
Re: Syntax
Posted: Saturday 02 May 2020 11:58
by jkimmel
I took this from the Wiki:
The name or idx of your device followed by a time constraint, such as: ['myDevice'] = { 'at 15:*', 'at 22:* on sat, sun' } The script will be executed if myDevice was changed, and it is either between 15:00 and 16:00 or between 22:00 and 23:00 in the weekend. See time trigger rules.
and my idea is trigger the script when setpoint changes and not at every change of temperature but wait every 3 minutes for acting on temperature change
Re: Syntax
Posted: Saturday 02 May 2020 12:08
by waaren
jkimmel wrote: ↑Saturday 02 May 2020 11:58
I took this from the Wiki:
The name or idx of your device followed by a time constraint, such as: ['myDevice'] = { 'at 15:*', 'at 22:* on sat, sun' } The script will be executed if myDevice was changed, and it is either between 15:00 and 16:00 or between 22:00 and 23:00 in the weekend. See time trigger rules.
That's correct but ' every 3 minutes' are specific times so it will only work when the temperature is updated at the same moment the time trigger is true which is 00:03:00:000, 00:06:00:000, ..., 23:57:00:000
Re: Syntax
Posted: Saturday 02 May 2020 12:18
by jkimmel
Some more questions:
Is this
Code: Select all
local setpoint = dz.devices(SETPOINT_DEVICE).levelName
the same as
Code: Select all
setpoint = dz.devices(SETPOINT_DEVICE).setPoint
and there is no need of specifying "local"
and how to use the shortcut dz for domoticz edit: found it was to simple I have to declare dz = domoticz?
Re: Syntax
Posted: Saturday 02 May 2020 12:38
by rrozema
local IS needed. You won't notice the difference until you create another variable with the same name in another script though. dzVents merges all active scripts into one big script for Domoticz to execute, so if you don't specify local on a variable, the 2 scripts will both have a variable with that name resulting in either an error message when you 'save' your script or unexpected behavior of the both scripts because they both start using each other's values.
The name for the dz 'shortcut' is nothing else than the name of the parameters you defined in the execute() - definition. What waaren does is to specify his execute() parameters as "dz, device" instead of "domoticz, device". He could have specified "x, y" as well, but that's less descriptive.
You may also notice that sometimes execute() has 3 2 or even 1 parameters. This is because for dzVents the parameters are optional: if you don't need the information, don't specify a name for the parameter and dzVents calls your execute()-function without passing in the data. You hardly ever need the full set of 3 parameters any more, specifying only the first 2 is sufficient for most scripts. The first parameter gives you access to the domoticz environment. The second parameter depends on the reason why the script was executed: if your script was called because one of the devices you specified in on { devices = {}} changed, the second parameter will hold the device that was changed. If your script was executed because of a timer event you specified in the on = { timers = {}} -section, the second parameter will hold the actual timer event, etc. The third parameter has information on why the execute()-function was called ("triggerInfo" is what it is called). In older versions of dzVents this would be used to determine what the reason was to call the execute()-function . This same information is however in current dzVents versions easier accessible from the 2nd parameter, so the 3rd parameter is almost always left off. Most of the times you will see it written as "execute( domoticz, device)", or "execute( dz, device)" if you don't like typing "domoticz" all the time.
Re: Syntax
Posted: Saturday 02 May 2020 12:40
by jkimmel
What about declaring devices, like
Code: Select all
devices =
{
SETPOINT_DEVICE,
TEMPERATURE_SENSOR
}
not needed anymore?
Re: Syntax
Posted: Saturday 02 May 2020 13:22
by elmortero
jkimmel wrote: ↑Saturday 02 May 2020 12:40
What about declaring devices, like
Code: Select all
devices =
{
SETPOINT_DEVICE,
TEMPERATURE_SENSOR
}
not needed anymore?
Hi, you don't declare devices here, these are the devices that will trigger the script.
Re: Syntax [Solved]
Posted: Saturday 02 May 2020 16:04
by rrozema
elmortero wrote: ↑Saturday 02 May 2020 13:22
jkimmel wrote: ↑Saturday 02 May 2020 12:40
What about declaring devices, like
Code: Select all
devices =
{
SETPOINT_DEVICE,
TEMPERATURE_SENSOR
}
not needed anymore?
Hi, you don't declare devices here, these are the devices that will trigger the script.
indeed: the code you specify in the
execute() function is WHAT you want the script to do. All options inside the
on = { } - section defines WHEN to do it. You've got multiple possibilites there:
- devices -> execute when any of the devices in the list changed its value.
- timer -> exectute when at all of the specified times or in the specifed time ranges (dzvents checks once every minute, so your script will run once every minute inside any range).
- variables -> execute when the value of any of the specified variables changes.
- security -> execute when Domoticz' armed status changes.
- scenes -> execute when one of the specifed scenes changes status.
- groups -> execute when one of the specifed groups changes status.
- httpResponses -> execute when a response to a url call returns.
- system -> execute when any of the specified system events occurs.
- customEvents -> some diy construct to have your code executed (this is new and I haven't used this myself yet)
The on-part is really powerfull, you can even make the craziest combinations. For all of the details read:
https://www.domoticz.com/wiki/DzVents:_ ... _scripting
Next there are 3 more optional sections in each dzvents script:
active,
data and
logging. They define other behavior of the script and details on these section can be found in the same document.
Re: Syntax
Posted: Saturday 02 May 2020 17:45
by dannybloe
Awesome!!

Re: Syntax
Posted: Sunday 03 May 2020 18:48
by jkimmel
I understand, my wording was wrong.