Events at startup

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

Moderator: leecollings

Post Reply
candrea77
Posts: 32
Joined: Saturday 25 February 2017 18:42
Target OS: Linux
Domoticz version: 2021.1
Location: Milano, Italy
Contact:

Events at startup

Post 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

Sorry for any spelling mistake, English is not my native language.

DomoticZ running on Ubuntu 20.04 LTS , dzVents Version: 3.1.7 , Python Version: 3.8.5
SweetPants

Re: Events at startup

Post by SweetPants »

What are you trying to achieve?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Events at startup

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Events at startup

Post by dannybloe »

In the future I want to support system events.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
candrea77
Posts: 32
Joined: Saturday 25 February 2017 18:42
Target OS: Linux
Domoticz version: 2021.1
Location: Milano, Italy
Contact:

Re: Events at startup

Post by candrea77 »

Mmmm ... what is this "domoticz.startTime" ..... I'm using stable version ... is present here ?
Sorry for any spelling mistake, English is not my native language.

DomoticZ running on Ubuntu 20.04 LTS , dzVents Version: 3.1.7 , Python Version: 3.8.5
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Events at startup

Post by dannybloe »

No. You need the beta.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
candrea77
Posts: 32
Joined: Saturday 25 February 2017 18:42
Target OS: Linux
Domoticz version: 2021.1
Location: Milano, Italy
Contact:

Re: Events at startup

Post by candrea77 »

dannybloe wrote:No. You need the beta.
Ok. Thank you

Inviato dal mio SM-G920F utilizzando Tapatalk

Sorry for any spelling mistake, English is not my native language.

DomoticZ running on Ubuntu 20.04 LTS , dzVents Version: 3.1.7 , Python Version: 3.8.5
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: Events at startup

Post 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

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Events at startup

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Events at startup

Post by dannybloe »

I'm planning to have system events for a future version of dzVents like

Code: Select all

on = {
    system = {'start', 'error'}
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
salvacalatayud
Posts: 112
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Spain
Contact:

Re: Events at startup

Post 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
doh
Posts: 82
Joined: Monday 01 December 2014 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: London, UK
Contact:

Re: Events at startup

Post 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.
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Events at startup

Post 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.
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Events at startup

Post 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.
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest