start a notify after afterSec / forMin

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

Moderator: leecollings

Post Reply
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

start a notify after afterSec / forMin

Post 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
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: start a notify after afterSec / forMin

Post by dannybloe »

What do you mean exactly?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: start a notify after afterSec / forMin

Post 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
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: start a notify after afterSec / forMin

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: start a notify after afterSec / forMin

Post by acaonweb »

great!!!
you make me understand everything

now the last question is why forSec doesn't work

thnx for now
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest