Page 1 of 1

Trigger on two conditions

Posted: Friday 28 December 2018 16:35
by DespyNL
Hi,

I would like to trigger my Hue Motion sensor script only between specific time. Is this possible?

Code: Select all

on = {
        devices = {
            'Hue Motion 1'
        },
		timer = {
			'at 06:00-09:00'
		}
    }
At this point it always triggers

Re: Trigger on two conditions

Posted: Friday 28 December 2018 17:42
by waaren
DespyNL wrote: Friday 28 December 2018 16:35 I would like to trigger my Hue Motion sensor script only between specific time. Is this possible?
Check the dzVents wiki

syntax to achieve this is

Code: Select all

devices = {["Hue Motion 1"] = {"at 06:00-09:00"}},

Re: Trigger on two conditions

Posted: Tuesday 01 January 2019 21:44
by Aadr
Hi,
I'am stuggeling with this syntaxis, specially with more than one device and more than one timeframe.
I have come up with this code:

return {

on = {
devices =
{[ 'Motion Kantine'] = {'at 13:00-22:00 on sat','at 19:00-23:30 on mon,tue,wed,fri',
'at 19:00-02:30 on thu'},
['Status_Muziek'] = {'at 13:00-22:00 on sat','at 19:00-23:30 on mon,tue,wed,fri',
'at 19:00-02:30 on thu'},
['Verlichting_Kantine_Mode'] = {'at 13:00-22:00 on sat','at 19:00-23:30 on mon,tue,wed,fri',
'at 19:00-02:30 on thu'}
},

but this code never triggers.

can someone point me in the right way?
thanks

Re: Trigger on two conditions

Posted: Tuesday 01 January 2019 22:34
by waaren
Aadr wrote: Tuesday 01 January 2019 21:44 I'am struggling with this syntaxis, specially with more than one device and more than one timeframe.
I have come up with this code:
Hopefully you are on a more recent version then what your profile shows :)
The problem in your "on = " section is one missing }

Code: Select all

local timeTable = {'at 13:00-22:00 on sat','at 19:00-23:30 on mon,tue,wed,fri','at 19:00-02:30 on thu'}
return {

            on =    {  
                        devices =   { 
                                        ['Motion Kantine']           = timeTable,
                                        ['Status_Muziek']            = timeTable,
                                        ['Verlichting_Kantine_Mode'] = timeTable
                                    }
                    },

    logging =   {   level   =   domoticz.LOG_DEBUG,
                    marker  =   "multiple device triggers"               },
     
    execute = function(dz, item)
        
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end

        logWrite ("triggered by " .. item.name)
    end
} 

Re: Trigger on two conditions

Posted: Wednesday 02 January 2019 19:24
by Aadr
Thank you, Waaren

It works well and I can start now with the next DzVents-beginners challenge.

Was there a way I could have know this syntaxis by my self, I am not educated in programming. Is there some more documentation to read, except for the wiki and the forum?

And I have updated my profile

thank you.

Re: Trigger on two conditions  [SOLVED]

Posted: Wednesday 02 January 2019 20:25
by waaren
Aadr wrote: Wednesday 02 January 2019 19:24 Was there a way I could have know this syntaxis by my self, I am not educated in programming. Is there some more documentation to read, except for the wiki and the forum?
dzVents is for the biggest part Lua. Behind the scenes there is some C++ code to efficiently communicate from and to the domoticz data but most of the Lua code that makes it easier to script in Lua and work with domoticz data is in the domoticz/dzVentz/runtime/ directory's
What I did to better understand how stuff is working is looking at the code in these directory's. What also worked for me is to search te internet for all kinds of information on Lua. If you already know a bit about other programming languages, Lua is not extremely difficult and once you get a better understanding on how Lua tables work you are more then halfway :D Luckily you can find tons of information on that and a good starting point is https://www.lua.org/pil/2.5.html

What confuses most people at first is the difference between {} and [] and that tableName.keyName is the same as tableName["keyName"]

In general terms:
everything between {} is a table
everything between [] is a key in a table. And a key can be any Lua datatype (yes also a table :D ) except nil

if a table has no explicit keys than the keys are integers starting from 1

Hope this will help