Page 1 of 1

triggering an "if"

Posted: Saturday 22 December 2018 21:41
by Adso76
Hi,
In the following simple script the second "if" doesn't work.

Code: Select all

return {
	on = {
		devices = {
			'wall button 1',
			'sleepingroom light'
		}
	},
	execute = function(domoticz, device)
	    if ((device.name == 'wall button 1' and device.changed)) then
		    if ((device.name == 'sleepingroom light' and device.state == "Off")) then
		        domoticz.log('Light will wee turned on ')
		    end
		end
	end
}
I can trigger the first if when I push the "wall button 1" (GPIO), then I want to check wether the light is on or off and this doesn't work.

Or maybe there is another way to do this?

Thanks,
Arek

Re: triggering an "if"

Posted: Saturday 22 December 2018 22:11
by ronaldbro
Hi Arek,

The second if is always false because in the first if you already checked if it is 'wall button 1' and if so the it's not 'sleepingroom light'.
Also no need to check if it's changed, it triggered the event so ofcource it's changed.

Code: Select all

return {
	on = {
		devices = {
			'wall button 1',
			'sleepingroom light'
		}
	},
	execute = function(domoticz, device)
	    if device.name == 'wall button 1' then
		    if domiticz.devices('sleepingroom light').state == "Off" then
		        domoticz.log('Light will wee turned on ')
		    end
		end
	end
}
regards Ronald

Re: triggering an "if"

Posted: Sunday 23 December 2018 12:20
by Adso76
@Ronald

Thanks a lot! Now it works!
However, in the first if I will stay with device.changed because in my case the wall button is not a push button (monostable) but typical physical switch (bistable).

Regardes,
Arek