Trigger on two conditions  [SOLVED]

Moderator: leecollings

Post Reply
DespyNL
Posts: 11
Joined: Thursday 23 July 2015 11:42
Target OS: Linux
Domoticz version: v4.9701
Location: The Netherlands
Contact:

Trigger on two conditions

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

Re: Trigger on two conditions

Post 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"}},
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Aadr
Posts: 19
Joined: Tuesday 09 June 2015 21:26
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Nederlands
Contact:

Re: Trigger on two conditions

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

Re: Trigger on two conditions

Post 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
} 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Aadr
Posts: 19
Joined: Tuesday 09 June 2015 21:26
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Nederlands
Contact:

Re: Trigger on two conditions

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

Re: Trigger on two conditions  [SOLVED]

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest