Page 1 of 1
script lua night lamp
Posted: Friday 27 May 2016 19:31
by Mazzokun
Hi guys, I'm trying writing a lua script to put on some light if time is night but there are some mistake.. can someone help me?
Code: Select all
commandArray{}
if time > Sunset or time < Sunrise and
otherdevices['Corridoio'] == 'Off'
or otherdevices['Lampada Sala'] == 'Off'
or otherdevices['Faro Retro'] == 'Off'
or otherdevices['Faro Garage'] == 'Off'
or otherdevices['Lanterna Ingresso'] == 'Off'
or otherdevices['Lanterna Nonna'] == 'Off'
or otherdevices['Accento Ingresso'] == 'Off'
or otherdevices['Lampione'] == 'Off'
or otherdevices['Luce Garage'] == 'Off'
then
commandArray['Corridoio'] == 'On'
commandArray['Lampada Sala'] == 'On'
commandArray['Faro Retro'] == 'On'
commandArray['Faro Garage'] == 'On'
commandArray['Lanterna Ingresso'] == 'On'
commandArray['Lanterna Nonna'] == 'On'
commandArray['Accento Ingresso'] == 'On'
commandArray['Lampione'] == 'On'
commandArray['Luce Garage'] == 'On'
elseif time= Sunrise commandArray[group:Luci Notturne] == 'Off'
end
return commandArray
Re: script lua night lamp
Posted: Friday 27 May 2016 19:47
by jvdz
Normally it helps when you state what kind of error you get or what isn't working.

I've made some changes like adding brackets and a then on the elseif line but am not sure i found all issues:
Code: Select all
commandArray{}
if (time > Sunset or time < Sunrise)
and (otherdevices['Corridoio'] == 'Off'
or otherdevices['Lampada Sala'] == 'Off'
or otherdevices['Faro Retro'] == 'Off'
or otherdevices['Faro Garage'] == 'Off'
or otherdevices['Lanterna Ingresso'] == 'Off'
or otherdevices['Lanterna Nonna'] == 'Off'
or otherdevices['Accento Ingresso'] == 'Off'
or otherdevices['Lampione'] == 'Off'
or otherdevices['Luce Garage'] == 'Off')
then
commandArray['Corridoio'] = 'On'
commandArray['Lampada Sala'] = 'On'
commandArray['Faro Retro'] = 'On'
commandArray['Faro Garage'] = 'On'
commandArray['Lanterna Ingresso'] = 'On'
commandArray['Lanterna Nonna'] = 'On'
commandArray['Accento Ingresso'] = 'On'
commandArray['Lampione'] = 'On'
commandArray['Luce Garage'] = 'On'
elseif time == Sunrise then
commandArray[group:Luci Notturne] = 'Off'
end
return commandArray
Jos
Re: script lua night lamp
Posted: Friday 27 May 2016 22:50
by Mazzokun
Thanks

.
I've made some changes like adding brackets and a then on the elseif line but am not sure i found all issues:
This is log error for your code.
Code: Select all
Error: EventSystem: in script_device_powerknnlkkn: [string "commandArray = {}..."]:3: attempt to compare two nil values
Re: script lua night lamp
Posted: Friday 27 May 2016 22:55
by Flopp
Try to put -- in front of these rows
Code: Select all
elseif time == Sunrise then
commandArray[group:Luci Notturne] = 'Off'
maybe it can be something with group i dont know if group has to be with a Capital G.
I have almost no knowledge of LUA so I always put -- in front of each row until it works then start to solve the problem
Re: script lua night lamp
Posted: Friday 27 May 2016 22:57
by Flopp
Re: script lua night lamp
Posted: Saturday 28 May 2016 7:31
by Mazzokun
I rewrote and this works

Thank you for support!!
Code: Select all
commandArray = {}
-- LUCI NOTTURNE
if (timeofday['Nighttime']) and otherdevices['Corridoio'] == 'Off' then commandArray[1]={['Corridoio'] = 'On' } end
if (timeofday['Nighttime']) and otherdevices['Lampada Sala'] == 'Off' then commandArray[2]={['Lampada Sala'] = 'On' } end
if (timeofday['Nighttime']) and otherdevices['Faro Garage'] == 'Off' then commandArray[3]={['Faro Garage'] = 'On'} end
if (timeofday['Nighttime']) and otherdevices['Lanterna Ingresso'] == 'Off' then commandArray[4]={['Lanterna Ingresso'] = 'On'} end
if (timeofday['Nighttime']) and otherdevices['Lanterna Nonna'] == 'Off' then commandArray[5]={['Lanterna Nonna'] = 'On' } end
if (timeofday['Nighttime']) and otherdevices['Lampione'] == 'Off' then commandArray[6]={['Lampione'] = 'On' } end
if (timeofday['Nighttime']) and otherdevices['Luce Garage'] == 'Off' then commandArray[7]={['Luce Garage'] = 'On'} end
if (timeofday['Nighttime']) and otherdevices['Faro Retro'] == 'Off' then commandArray[8]={['Faro Retro'] = 'On'} end
-- ACCENTI
if (timeofday['Nighttime']) and otherdevices['Accento Ingresso'] == 'Off' then commandArray[9]={['Accento Ingresso'] = 'On'} end
-- SPEGNIMENTO
if (timeofday['Sunrise']) then commandArray[10]={['Group:Luci Notturne'] = 'Off'} end
return commandArray
Re: script lua night lamp
Posted: Saturday 28 May 2016 7:37
by Flopp
Great
