dzVents timer with switch

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

Moderator: leecollings

Post Reply
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

dzVents timer with switch

Post by parrotface »

Hi
I have dzVents script running every minute OK but I am trying to run it only when a switch is on.

Code: Select all

{
         timer = {'every 1 minutes'},
 },
I still need it to run every minute but only when switch is on
Thanks
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: dzVents timer with switch

Post by emme »

Code: Select all

return {
	on = { 
		device = { 'myDevice'},
		timer = {'every 1 minutes'}
	},

	execute = function(domoticz, device, triggerInfo)
	    if triggerInfo.type  == domoticz.EVENT_TYPE_TIMER then
	        -- do timer event stuff
	    elseif triggerInfo.type  == domoticz.EVENT_TYPE_DEVICE then
	        -- do device event stuff
	    end
	end
}	
Last edited by dannybloe on Wednesday 17 January 2018 16:15, edited 1 time in total.
Reason: code block
The most dangerous phrase in any language is:
"We always done this way"
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: dzVents timer with switch

Post by parrotface »

Thanks for your reply - very helpful but I am still having problem with the switch section. Every minute appears in log but when I switch On nothing happens. Do I have to check that it is either On or Off?

return {
on = {
device = { 'Switch1'},
timer = {'every 1 minutes'}
},

execute = function(domoticz, device, triggerInfo)
if triggerInfo.type == domoticz.EVENT_TYPE_TIMER then
-- do timer event stuff
domoticz.log(' timer ')
elseif triggerInfo.type == domoticz.EVENT_TYPE_DEVICE then
-- do device event stuff
domoticz.log(' switch ')
end
end
}

Thanks for your help
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: dzVents timer with switch

Post by emme »

that's quite wired....
is Switch1 wrote correctly and reflect the correct UPPER and lower case? (Swith1 is no switch1 ;) )

try also to add this line after the extecute = (and before the if statement)
domoticz.log('Trigger ==> '..triggerInfo.type)
just to understand who's doing what ;)
ciao
M
The most dangerous phrase in any language is:
"We always done this way"
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: dzVents timer with switch

Post by parrotface »

Thanks for you help will try that next.
in the mean time I have got it doing what I want but I don't think it is the correct way of going about things

execute = function(domoticz, device, triggerInfo)
if triggerInfo.type == domoticz.EVENT_TYPE_TIMER and domoticz.devices('Switch1').state == 'On'then
-- do timer event stuff
domoticz.log(' === Switch On ===== ')
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: dzVents timer with switch

Post by parrotface »

triger info

2018-01-18 10:53:00.162 dzVents: Info: Trigger ==> timer
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: dzVents timer with switch

Post by emme »

and the switch never triggers?!
The most dangerous phrase in any language is:
"We always done this way"
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: dzVents timer with switch

Post by emme »

uuuuuh... F***!!!


return {
on = {
deviceS = { 'Switch1'},
timer = {'every 1 minutes'}
},

sorry... my fault :cry:
The most dangerous phrase in any language is:
"We always done this way"
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: dzVents timer with switch

Post by parrotface »

Hi
Have tried devices before
still No Go
I will try again later as I have to go out for a few hours
Thanks for your help will let you know later
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents timer with switch

Post by dannybloe »

Read the troubleshooting section in the docs.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
TheWoodenGamer
Posts: 7
Joined: Sunday 29 January 2017 22:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents timer with switch

Post by TheWoodenGamer »

Hi,

Perhaps this works? It does for me.

Code: Select all


return {

	-- triggers
	on = {
		-- device triggers
		devices = {
			-- scripts is executed if the device that was updated matches with one of these triggers
			42, -- Philips Hue Wall Switch
		},

	},

	-- custom logging level for this script
	logging = {
        level = domoticz.LOG_DEBUG,
        marker = "Hue wall switch initiated"
    },

    	-- do something with the event
	execute = function(domoticz, device, info)

		if (device.active) then -- state == 'On'
			device.switchOff().afterMin(1) -- if it is a switch, turn off after 1 minute
}


Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest