triggering an "if"

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

Moderator: leecollings

Post Reply
Adso76
Posts: 20
Joined: Tuesday 28 August 2018 21:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

triggering an "if"

Post 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
Domoticz Version: 4.9895 running on Raspberry Pi B 3+ (Raspbian). PCF8574 as input and output.
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: triggering an "if"

Post 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
Adso76
Posts: 20
Joined: Tuesday 28 August 2018 21:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: triggering an "if"

Post 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
Domoticz Version: 4.9895 running on Raspberry Pi B 3+ (Raspbian). PCF8574 as input and output.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest