Page 1 of 1

Events at startup

Posted: Friday 20 October 2017 10:53
by candrea77
Dear forum users,
I wonder if using dzVents we are able to trigger a script in order to get it run only 1 time at startup.

Thank you for your attention

Regards

Inviato dal mio SM-G920F utilizzando Tapatalk


Re: Events at startup

Posted: Friday 20 October 2017 15:04
by SweetPants
What are you trying to achieve?

Re: Events at startup

Posted: Saturday 21 October 2017 0:57
by dannybloe
You can. You can use a timer script and a condition that checks the domoticz.startTime. Only run when startTime is less than two minutes ago.

Re: Events at startup

Posted: Saturday 21 October 2017 0:58
by dannybloe
In the future I want to support system events.

Re: Events at startup

Posted: Saturday 21 October 2017 20:13
by candrea77
Mmmm ... what is this "domoticz.startTime" ..... I'm using stable version ... is present here ?

Re: Events at startup

Posted: Saturday 21 October 2017 20:21
by dannybloe
No. You need the beta.

Re: Events at startup

Posted: Saturday 21 October 2017 22:22
by candrea77
dannybloe wrote:No. You need the beta.
Ok. Thank you

Inviato dal mio SM-G920F utilizzando Tapatalk


Re: Events at startup

Posted: Wednesday 31 January 2018 14:34
by salvacalatayud
This can be great, with this you can set milght to switch off after start up, as they turn on after plugged and this happens in case of a cut of electricity.

I have no idea of dzvents, if someone can give a light on code would be useful.

Enviado desde mi Redmi 4X mediante Tapatalk


Re: Events at startup

Posted: Thursday 01 February 2018 3:40
by waaren
Please have a look at the script below. Maybe not the optimal solution but it does the job as expected.

Code: Select all

--[[
	active when function returns true ( domoticz started less then 180 seconds ago )  
	
	The defined tasks will only execute once after domoticz started.
	Please note that this is not a failsafe way of handling this. 
	
	If domoticz crashes / is stopped after the first excution of this script and before 120 seconds after 
	it started, the Executed value is not set back to 0 and the script needs to be reloaded to reset the persisitent data.
	
	If domoticz starts extremely slow, in theory it could be that this script will not be evaluated before the 180 seconds 
	after startup has passed. On my test system (PI-3), first execution is well within that window. (somewhere between 13 and 60 seconds)
	
 ]]-- 
 
 
return {
	active = function(domoticz)
			  return domoticz.startTime.secondsAgo < 180
			end,
	
    on 		= {  	timer 		= { 'every minute'  } },
	data 	= { 	Executed 	= { initial = 0 } },
    
	
            
    execute = function(domoticz)
		if domoticz.data.Executed == 0 then
			domoticz.data.Executed = domoticz.startTime.secondsAgo
			local minute=60
			local hour=60*minute
			local day=24*hour
			
			local seconds = domoticz.systemUptime
			
			local days = math.floor(seconds/day)
			seconds = seconds - days * day
			
			local hours = math.floor(seconds/hour)  
			seconds = seconds - hours * hour
			
			local minutes = math.floor( seconds/minute )
			seconds = seconds - minutes * minute
			
			-- [DEFINE YOUR TASKS HERE] 
			
			
			print ("System active time: " .. tostring (days) .. " days, " .. tostring(hours) .. " hours and " .. tostring(minutes) .. " minutes." )
			print ("Domoticz started " .. tostring (domoticz.startTime.secondsAgo) .. " seconds ago. I will do the startup tasks") 
		else
			print ("Älready executed; " .. tostring(domoticz.data.Executed) .. " seconds after domoticz started.")
			if domoticz.startTime.secondsAgo > 119 then
				domoticz.data.Executed = 0
			end	
		end			
	end
}

Re: Events at startup

Posted: Thursday 01 February 2018 8:03
by dannybloe
I'm planning to have system events for a future version of dzVents like

Code: Select all

on = {
    system = {'start', 'error'}
}

Re: Events at startup

Posted: Friday 02 February 2018 12:47
by salvacalatayud
waaren wrote: Thursday 01 February 2018 3:40 Please have a look at the script below. Maybe not the optimal solution but it does the job as expected.

Code: Select all

--[[
	active when function returns true ( domoticz started less then 180 seconds ago )  
	
	The defined tasks will only execute once after domoticz started.
	Please note that this is not a failsafe way of handling this. 
	
	If domoticz crashes / is stopped after the first excution of this script and before 120 seconds after 
	it started, the Executed value is not set back to 0 and the script needs to be reloaded to reset the persisitent data.
	
	If domoticz starts extremely slow, in theory it could be that this script will not be evaluated before the 180 seconds 
	after startup has passed. On my test system (PI-3), first execution is well within that window. (somewhere between 13 and 60 seconds)
	
 ]]-- 
 
 
return {
	active = function(domoticz)
			  return domoticz.startTime.secondsAgo < 180
			end,
	
    on 		= {  	timer 		= { 'every minute'  } },
	data 	= { 	Executed 	= { initial = 0 } },
    
	
            
    execute = function(domoticz)
		if domoticz.data.Executed == 0 then
			domoticz.data.Executed = domoticz.startTime.secondsAgo
			local minute=60
			local hour=60*minute
			local day=24*hour
			
			local seconds = domoticz.systemUptime
			
			local days = math.floor(seconds/day)
			seconds = seconds - days * day
			
			local hours = math.floor(seconds/hour)  
			seconds = seconds - hours * hour
			
			local minutes = math.floor( seconds/minute )
			seconds = seconds - minutes * minute
			
			-- [DEFINE YOUR TASKS HERE] 
			
			
			print ("System active time: " .. tostring (days) .. " days, " .. tostring(hours) .. " hours and " .. tostring(minutes) .. " minutes." )
			print ("Domoticz started " .. tostring (domoticz.startTime.secondsAgo) .. " seconds ago. I will do the startup tasks") 
		else
			print ("Älready executed; " .. tostring(domoticz.data.Executed) .. " seconds after domoticz started.")
			if domoticz.startTime.secondsAgo > 119 then
				domoticz.data.Executed = 0
			end	
		end			
	end
}
Thanks a lot, I'll try as soon as I can

Re: Events at startup

Posted: Saturday 13 April 2019 22:37
by doh
dannybloe wrote: Thursday 01 February 2018 8:03 I'm planning to have system events for a future version of dzVents like

Code: Select all

on = {
    system = {'start', 'error'}
}
Has this been implemented yet? Would really love to use it.

Re: Events at startup

Posted: Sunday 14 April 2019 9:02
by rrozema
dannybloe wrote: Thursday 01 February 2018 8:03 I'm planning to have system events for a future version of dzVents like

Code: Select all

on = {
    system = {'start', 'error'}
}
Can you also add triggers for device's meta data changes? I use the description field to put a json text in containing many settings for this particular device, so I can write one generic script that works for all devices that have a specific value (or values) in their description field. As it is now I need to periodically execute the scripts and scan all devices on every run. I would like to be able to read all meta data once at startup to collect in variables those devices that have specific values. This way I only need to scan those devices when the generic script runs, instead of scanning all devices every time. I can already do most of this now, however when a device's description gets changed, my variables will not be updated and the device will no longer react according to the values in it's description field.

I would very much welcome a trigger for when a device's meta data changes. In other words: a "device meta data trigger" would be called when any property changes that not currently triggers the existing "device value" trigger.

Re: Events at startup

Posted: Tuesday 20 August 2019 0:37
by Geitje
Would be great if in the event system can be added a standard value for running time of Domoticz. This way we can let run an event if domoticz is running for 12 hours, for example make a backup (just to give an example).

I need it myself to cancel an event which for some reason is running everytime Domoticz starts up.