Page 1 of 1

Trigger depending of time AND device

Posted: Saturday 29 June 2019 8:28
by usky73
Hi all
I am updating all my scripts in DzVent. And this is really a great improvement.

Then I want more !
Is there a way to link 2 trigger conditions : time AND devices instead of time OR devices.
I want my script to run from sunset to morning and only if one device (motion sensor) state change.

At the moment I have only a trigger on the devices but I dont't want to run the script in day time.

Any idea ?

Re: Trigger depending of time AND device

Posted: Saturday 29 June 2019 8:57
by Geuvert
Hi Usky,

Personally I have a timer script running in which I use an if statement to check the state of a switch.
My (simplified) code looks like this:

Code: Select all

return {
    active = true,
	on = {
		timer =	{
			'every minute at 14:00-22:16',
		}
	},
	
	execute = function(domoticz, device, switch)
	    local I2    = domoticz.devices('Qubino Dimmer I2')
        
        if (I2.state == 'On') then
            light.switchOn()
        end
	end
}
I removed some of the code, so not sure is this runs as is.

If this is not what you're looking for I believe you can add a device after the time. Not sure how that works though.
It should look something like:

Code: Select all

return {
    active = true,
	on = {
		timer =	{
			'every minute at 14:00-22:16',
		},
		devices = {
			'Switch 1'
		}
	},
	...
	
Though I am not sure whether this triggers if both conditions are met (time and device) or if either one is met.

Hope this helps.


Geuvert

Re: Trigger depending of time AND device

Posted: Saturday 29 June 2019 9:45
by waaren
usky73 wrote: Saturday 29 June 2019 8:28 Hi all
I am updating all my scripts in DzVent. And this is really a great improvement.

Then I want more !
Is there a way to link 2 trigger conditions : time AND devices instead of time OR devices.
I want my script to run from sunset to morning and only if one device (motion sensor) state change.

At the moment I have only a trigger on the devices but I dont't want to run the script in day time.

Any idea ?

Code: Select all

return 
{
   on = 
   {
      devices = { ['myMotionSensor'] = { 'at nighttime' } }
   },
   
   execute = function(domoticz,item)
      if (item.state == 'On') then
         domoticz.log('Sensor ' .. item.name .. ' was turned on.',domoticz.LOG_FORCE)
      end
   end
}
Look here for more examples

Re: Trigger depending of time AND device

Posted: Saturday 29 June 2019 13:29
by usky73
Thanks a lot to all.
Waaren you got my point. That's exactly what I was looking for. I missed that point in the doc.

Re: Trigger depending of time AND device

Posted: Saturday 29 June 2019 13:44
by usky73
for testing purpose I have tested that :

Code: Select all

on = {
		devices = { ['Hue motion sensor salon'] = {'at civildaytime'} }
	},
but it is not working, any idea ?

Re: Trigger depending of time AND device

Posted: Saturday 29 June 2019 20:00
by usky73
Just did test and it works with other timer parameters but not with 'at civildaytime'
For this value should work for any day time. But it is not the case. Am I correct ?

Re: Trigger depending of time AND device

Posted: Sunday 30 June 2019 11:34
by waaren
usky73 wrote: Saturday 29 June 2019 20:00 Just did test and it works with other timer parameters but not with 'at civildaytime'
For this value should work for any day time. But it is not the case. Am I correct ?
You are correct. Nice catch and thanks for reporting. Fixed in next beta.

Re: Trigger depending of time AND device  [Solved]

Posted: Sunday 30 June 2019 18:35
by usky73
:-)