Syntax  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
jkimmel
Posts: 129
Joined: Monday 25 November 2013 17:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Mallorca
Contact:

Syntax

Post 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
Rfxcom
Raspi 4
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Syntax

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
jkimmel
Posts: 129
Joined: Monday 25 November 2013 17:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Mallorca
Contact:

Re: Syntax

Post 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
Rfxcom
Raspi 4
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Syntax

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
jkimmel
Posts: 129
Joined: Monday 25 November 2013 17:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Mallorca
Contact:

Re: Syntax

Post 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?
Rfxcom
Raspi 4
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Syntax

Post 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.
Last edited by rrozema on Saturday 02 May 2020 18:30, edited 1 time in total.
jkimmel
Posts: 129
Joined: Monday 25 November 2013 17:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Mallorca
Contact:

Re: Syntax

Post by jkimmel »

What about declaring devices, like

Code: Select all

devices =
        {
            SETPOINT_DEVICE,
            TEMPERATURE_SENSOR
            }
not needed anymore?
Rfxcom
Raspi 4
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Syntax

Post 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.
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Syntax  [Solved]

Post 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.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Syntax

Post by dannybloe »

Awesome!! 😆
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
jkimmel
Posts: 129
Joined: Monday 25 November 2013 17:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Mallorca
Contact:

Re: Syntax

Post by jkimmel »

I understand, my wording was wrong.
Rfxcom
Raspi 4
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest