Page 1 of 1

start a notify after afterSec / forMin

Posted: Wednesday 13 December 2017 13:31
by acaonweb
hi guys i'm learning dzevents.
im writing a simple scripts that sends a sounds through xiaomi gateway after

Code: Select all


return {

	-- 'active' controls if this entire script is considered or not
	active = true, -- set to false to disable this script

	-- trigger
	-- can be a combination:
	on = {
		devices = {
		    'test'
		}
	},

	-- actual event code
	-- in case of a timer event or security event, device == nil
	execute = function(domoticz, device)
	    if(domoticz.devices('test').state == 'On') then
	        domoticz.log('triggered')
	        domoticz.devices('test').switchOff()
	        domoticz.devices('GatewayMP3').switchOn().afterSec(20).forMin(1)
	        domoticz.notify('DZ test','test è on',PRIORITY_NORMAL,0,'iPhone6S',domoticz.NSS_PUSHOVER)
	        domoticz.log('mp3 '..domoticz.devices('GatewayMP3').state)
        end
end
}
the script works fine except the notify: i'm not able to send the notification AFTER THE SWITCH OFF.
how can I resolve that?

thanx in advance

Fabrizio

Re: start a notify after afterSec / forMin

Posted: Wednesday 13 December 2017 20:24
by dannybloe
What do you mean exactly?

Re: start a notify after afterSec / forMin

Posted: Thursday 14 December 2017 1:17
by acaonweb
I mean the notification is sent in the same time of the switchon(): but then switch on starts n seconds later
I would like the notification starts n seconds later too

Re: start a notify after afterSec / forMin

Posted: Thursday 14 December 2017 8:43
by dannybloe
Sending notifications doesn't support delays as far as I know. What you can do is:

Code: Select all

return {
	on = {
		devices = {
		    'test',
		    'GatewayMP3'
		}
	},
	execute = function(domoticz, device)
	
		if (device.name == 'test' and device.active) then
			domoticz.devices('test').switchOff()
			domoticz.devices('GatewayMP3').switchOn().afterSec(20).forMin(1)						
		elseif (device.name == 'GatewayMP3' and device.active) then
			domoticz.notify('DZ test','test è on',PRIORITY_NORMAL,0,'iPhone6S',domoticz.NSS_PUSHOVER)
			domoticz.log('mp3 '..domoticz.devices('GatewayMP3').state)
		end
        end
end
}
You create two triggers, one for the test switch and one for your gateway. When the gateway is turned on your script is triggered again and the elseif part will be executed.

Re: start a notify after afterSec / forMin

Posted: Thursday 14 December 2017 9:01
by acaonweb
great!!!
you make me understand everything

now the last question is why forSec doesn't work

thnx for now