Page 1 of 1

What is wrong with my parantheses?

Posted: Wednesday 12 July 2017 18:29
by havnegata
Raspberry Pi
V3.8035

There are two motion sensors, one virtual switch and a group of lights, and this script gives me the error:
scripts/lua/script_device_lysPåNatt.lua:3: 'then' expected near ')'

What's wrong with the parantheses?

Code: Select all

commandArray = {}

if ((devicechanged['Bevegelse Neo'] == 'On') or (devicechanged['Bevegelse'] == 'Motion')) and ((otherdevices['Natta']) == 'On') and (otherdevices['Group:Lys stue']) == 'On')) then
		commandArray['TomStue']='Off'
		print ("Noen har våknet og lyset er på igjen")	
if (uservariables['Natta'] == 0) then
		commandArray['SendNotification']='Noen har våknet og lyset er på igjen'
		commandArray['Variable:Natta']=tostring (1)
end
end
return commandArray

Re: What is wrong with my parantheses?

Posted: Wednesday 12 July 2017 18:48
by Doler

Code: Select all

...((otherdevices['Natta']) == 'On')...
There is a closing parenthesis too much just after ['Natta'].

Re: What is wrong with my parantheses?

Posted: Wednesday 12 July 2017 19:25
by K3rryBlue
Please use corrected code below.
There are 2 errors with parantheses. Use notepad++, it will help you detecting the error.

Code: Select all

commandArray = {}

if ((devicechanged['Bevegelse Neo'] == 'On') or (devicechanged['Bevegelse'] == 'Motion')) and ( (otherdevices['Natta'] == 'On') and (otherdevices['Group:Lys stue'] == 'On')) then
      commandArray['TomStue']='Off'
      print ("Noen har våknet og lyset er på igjen")   
if (uservariables['Natta'] == 0) then
      commandArray['SendNotification']='Noen har våknet og lyset er på igjen'
      commandArray['Variable:Natta']=tostring (1)
end
end
return commandArray
Image

Re: What is wrong with my parantheses?

Posted: Wednesday 12 July 2017 23:22
by havnegata
Thanks both of you! Works perfectly now

Sent from my Nexus 6P using Tapatalk