dvents scripting for beginners  [Solved]

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

Moderator: leecollings

Post Reply
bce626
Posts: 17
Joined: Saturday 03 November 2018 10:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

dvents scripting for beginners

Post by bce626 »

hello via this way i want to ask the following.

I try to switch a switch via dzvents scripting.
Hereby the following information;
switch 1 called no value 1
switch 2 called no value 2
switch 3 called dummy switch.

if I switch on switch 1 or 2 then the dummy must switch on (it does not matter which switch switches on). this works the way I want

but now I want to switch off the switch in the same script as follows,
switches 1 and 2 are off, then switch 3 may go out.
(I want them all off before the switch goes off)
I don't get this working and I tried different ways, the last one in the spoiler.

would someone like to help me with this or indicate the right path.

thank you in advance

Spoiler: show
return {
on = {
devices = {'test dummie',
'geenwaarde1',
'geenwaarde2'
}
},
execute = function(domoticz, devices)
if ((devices.name == 'geenwaarde1' and devices.active) or (devices.name == 'geenwaarde2' and devices.active)) then
domoticz.devices('test dummie').switchOn()
end

if ((devices.name == 'geenwaarde1' == switchOff) and (devices.name == 'geenwaarde2' == switchOff)) then
domoticz.devices('test dummie').switchOn()
end
end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dvents scripting for beginners

Post by waaren »

waaren wrote: Sunday 26 May 2019 21:40
bce626 wrote: Sunday 26 May 2019 21:21 I try to switch a switch via dzvents scripting.
if I switch on switch 1 or 2 then the dummy must switch on (it does not matter which switch switches on). this works the way I want
Can you try this ?

Code: Select all

return 
{
    on = 
    {
            devices = 
            { 
                'geenwaarde1',    -- You don't need your dummy here. It is not used as trigger but will only 'follow'
                'geenwaarde2' 
            }
    },
    
    execute = function(domoticz, device) -- I would not use the word 'devices' here; it will not fail but can be confused with domoticz.devices (an internal name)
        if device.active then -- either geenwaarde1 or -2 is active ( On )
            domoticz.devices('test dummie').switchOn()
        else
            if not ( domoticz.devices(geenwaarde1).active or domoticz.devices(geenwaarde2).active ) then 
                domoticz.devices('test dummie').switchOff()
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
bce626
Posts: 17
Joined: Saturday 03 November 2018 10:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: dvents scripting for beginners

Post by bce626 »

thank you for your response, and text with explanation.
Part I knew from the dzvents page, the if not function not (cannot find it on the page).

it still does not work exactly as I had imagined, no matter which switch goes out the dummy switch also goes out.
and what I am trying to do is that, when both switch are switched off, the dummy switch switch off.
so i thought simple to "if not (domoticz.devices (no value1) .active or domoticz.devices (no value2) .active) then"

to convert to if not (domoticz.devices (no value1) .active and domoticz.devices (no value2) .active) then

but that was apparently a bit too simple. ;)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dvents scripting for beginners  [Solved]

Post by waaren »

bce626 wrote: Monday 27 May 2019 17:15 thank you for your response, and text with explanation.
Part I knew from the dzvents page, the if not function not (cannot find it on the page).
dzVents is a set of functions / methods build with standard Lua code specifically for domoticz. The wiki page explains these functions and methods but it is not a Lua tutor so you will not find explanations for standard Lua concepts like if, for or dealing with tables. These can be easily found using google with the words Lua tables, string etc..
Lua is quite an easy language to learn once you understand the way it deals with tables. Luckily there is a lot of excellent stuff about that in google.
it still does not work exactly as I had imagined, no matter which switch goes out the dummy switch also goes out.
wrt the script; I Forgot some quotes....
This should do it

Code: Select all

return 
{
    on = 
    {
            devices = 
            { 
                'geenwaarde1',    -- You don't need your dummy here. It is not used as trigger but will only 'follow'
                'geenwaarde2' 
            }
    },
    
    execute = function(domoticz, device) -- I would not use the word 'devices' here; it will not fail but can be confused with domoticz.devices (an internal name)
        if device.active then -- either geenwaarde1 or -2 is active ( On )
            domoticz.devices('test dummie').switchOn()
        else
            if not ( domoticz.devices('geenwaarde1').active or domoticz.devices('geenwaarde2').active ) then 
                domoticz.devices('test dummie').switchOff()
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
bce626
Posts: 17
Joined: Saturday 03 November 2018 10:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: dvents scripting for beginners

Post by bce626 »

this was indeed the solution (I myself had not seen that the quote brackets were not there). thank you for helping. I still have a question, in the dzvents wiki list of domoticz, it says that dzvents is a simpler version of lua. is lua scripting 100% usable within dzvents scripting?
I ask this because I have 100% deposited on the dzvent list to understand how this scripting works (bit by bit it works) otherwise I will look further towards lua

thank you again
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dvents scripting for beginners

Post by waaren »

bce626 wrote: Tuesday 28 May 2019 18:31 In the dzvents wiki list of domoticz, it says that dzvents is a simpler version of lua.
I don't read that. The wiki starts with stating
Spoiler: show
dzVents /diː ziː vɛnts/, short for Domoticz Easy Events, brings Lua scripting in Domoticz to a whole new level. Writing scripts for Domoticz has never been so easy. Not only can you define triggers more easily, and have full control over timer-based scripts with extensive scheduling support, dzVents presents you with an easy to use API to all necessary information in Domoticz. No longer do you have to combine all kinds of information given to you by Domoticz in many different data tables. You don't have to construct complex commandArrays anymore. dzVents encapsulates all the Domoticz peculiarities regarding controlling and querying your devices. And on top of that, script performance has increased a lot if you have many scripts because Domoticz will fetch all device information only once for all your device scripts and timer scripts. And ... it is 100% Lua! So if you already have a bunch of event scripts for Domoticz, upgrading should be fairly easy.
Is lua scripting 100% usable within dzvents scripting?
from the wiki " And ... it is 100% Lua!"
I ask this because I have 100% deposited on the dzvent list to understand how this scripting works (bit by bit it works) otherwise I will look further towards lua
You should!! dzVents wil give you're an easy API to domoticz but the real coding fun is what you put in yourself and that is all about Lua
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
bce626
Posts: 17
Joined: Saturday 03 November 2018 10:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: dvents scripting for beginners

Post by bce626 »

In the dzvents wiki list of domoticz, it says that dzvents is a simpler version of lua.
I don't read that. The wiki starts with stating
that's right, that's not directly in the text, that's what I read from it.
Spoiler: show
No longer do you have to combine all kinds of information given to you by Domoticz in many different data tables. You don't have to construct
complex commandArrays anymore. dzVents encapsulates all the Domoticz peculiarities regarding controlling and querying your devices
but I admit that I did not write it well because it is not directly there, but an interpretation of my self.


I found a site that explains the basics for lua scripting.
I'm going to delve into this.

thank you for the help and explanation 8-)

ps this was written with the help of google translate, but you probably realized that.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest