checkFirst doesn't work in my script

Easy to use, 100% Lua-based event scripting framework.
Post Reply
domogijs
Posts: 44
Joined: Monday 17 August 2015 23:18
Target OS: Raspberry Pi
Domoticz version:
Contact:

checkFirst doesn't work in my script

Post by domogijs » Friday 09 February 2018 16:09

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
}
Raspberry Pi3, RFlink, Zwave, ThermoSmart, XiaomiGateway (Aqara)

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

Re: checkFirst doesn't work in my script

Post by dannybloe » Friday 09 February 2018 18:37

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).
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

domogijs
Posts: 44
Joined: Monday 17 August 2015 23:18
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: checkFirst doesn't work in my script

Post by domogijs » Friday 09 February 2018 21:21

thanks! I had read it but I think I understand it now
Raspberry Pi3, RFlink, Zwave, ThermoSmart, XiaomiGateway (Aqara)

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests