Events at startup

Easy to use, 100% Lua-based event scripting framework.
Post Reply
candrea77
Posts: 39
Joined: Saturday 25 February 2017 19:42
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Milano, Italy
Contact:

Events at startup

Post by candrea77 » Friday 20 October 2017 10:53

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 Raspberry PI 3 Model B , with Raspbian Jessie Lite ,Monit , Ramfs, and Persistent USB device

SweetPants
Posts: 2255
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10007
Location: The Netherlands
Contact:

Re: Events at startup

Post by SweetPants » Friday 20 October 2017 15:04

What are you trying to achieve?
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

dannybloe
Posts: 1473
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Events at startup

Post by dannybloe » Saturday 21 October 2017 0:57

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: 1473
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Events at startup

Post by dannybloe » Saturday 21 October 2017 0:58

In the future I want to support system events.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

candrea77
Posts: 39
Joined: Saturday 25 February 2017 19:42
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Milano, Italy
Contact:

Re: Events at startup

Post by candrea77 » Saturday 21 October 2017 20:13

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 Raspberry PI 3 Model B , with Raspbian Jessie Lite ,Monit , Ramfs, and Persistent USB device

dannybloe
Posts: 1473
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Events at startup

Post by dannybloe » Saturday 21 October 2017 20:21

No. You need the beta.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

candrea77
Posts: 39
Joined: Saturday 25 February 2017 19:42
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Milano, Italy
Contact:

Re: Events at startup

Post by candrea77 » Saturday 21 October 2017 22:22

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 Raspberry PI 3 Model B , with Raspbian Jessie Lite ,Monit , Ramfs, and Persistent USB device

salvacalatayud
Posts: 30
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi
Domoticz version: 3.8072
Location: Spain
Contact:

Re: Events at startup

Post by salvacalatayud » Wednesday 31 January 2018 15:34

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: 928
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Events at startup

Post by waaren » Thursday 01 February 2018 4: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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

dannybloe
Posts: 1473
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Events at startup

Post by dannybloe » Thursday 01 February 2018 9:03

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: 30
Joined: Monday 26 June 2017 21:16
Target OS: Raspberry Pi
Domoticz version: 3.8072
Location: Spain
Contact:

Re: Events at startup

Post by salvacalatayud » Friday 02 February 2018 13:47

waaren wrote:
Thursday 01 February 2018 4: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

Post Reply

Who is online

Users browsing this forum: Maxx, waaren and 1 guest