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:
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