Page 1 of 1

checkFirst doesn't work in my script

Posted: Friday 09 February 2018 15:09
by domogijs
Hi

First of all big thank for dzVents!

This is my first script so excuse me for my noob question.

Goal of this script. When motion in my house, the dummy switch ' iemand thuis' = on. When for 20 minutes no motion is detected switch = off. But with the script below i only get ' off' messages and no ' on' message.See last 3 lines. What is wrong?

Greets Gijs


Code: Select all

 return {
	on = {
		devices = {
			'Motion Woon',
			'Motion Studeer',
			'Motion Keuken',
			'Motion Badkamer',
			'Motion Hal',
			'Motion Emma'
			
		}
	},
	execute = function(domoticz, device)
        if ((device.name == 'Motion Woon' and device.state == 'On') or
            (device.name == 'Motion Studeer' and device.state == 'On')or
            (device.name == 'Motion Keuken' and device.state == 'On')or
            (device.name == 'Motion Badkamer' and device.state == 'On')or
            (device.name == 'Motion Hal' and device.state == 'On')or
            (device.name == 'Motion Emma' and device.state == 'On')) then
            domoticz.devices('Iemand Thuis').switchOn().checkFirst()
            domoticz.devices('Iemand Thuis').cancelQueuedCommands()
            domoticz.devices('Iemand Thuis').switchOff().afterMin(20)
            
        end
	end
}

Re: checkFirst doesn't work in my script

Posted: Friday 09 February 2018 17:37
by dannybloe
First of all, read: Important note.

This code should do the trick:

Code: Select all

return {
	on = {
		devices = { 'Motion*'}
	},
	execute = function(domoticz, device)
		if (device.active) then
			domoticz.devices('Iemand Thuis').switchOn().checkFirst().forMin(20)
			domoticz.devices('Iemand Thuis').switchOff().checkFirst().afterMin(20)
		end
	end	
}
There is no need for that huge if-statement as your on-trigger already makes sure that only those devices trigger your script so device is always one of these. And perhaps you can use the wild-card option there as well (unless you have more motion sensors around the house of course).

Re: checkFirst doesn't work in my script

Posted: Friday 09 February 2018 20:21
by domogijs
thanks! I had read it but I think I understand it now