script lua night lamp

Moderator: leecollings

Post Reply
Mazzokun
Posts: 89
Joined: Thursday 28 April 2016 23:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Milan, Italy
Contact:

script lua night lamp

Post 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? :D

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
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: script lua night lamp

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Mazzokun
Posts: 89
Joined: Thursday 28 April 2016 23:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Milan, Italy
Contact:

Re: script lua night lamp

Post 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
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: script lua night lamp

Post 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
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: script lua night lamp

Post by Flopp »

OK found it, it has to be Capital G

https://www.domoticz.com/wiki/LUA_commands
Mazzokun
Posts: 89
Joined: Thursday 28 April 2016 23:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Milan, Italy
Contact:

Re: script lua night lamp

Post by Mazzokun »

I rewrote and this works :) Thank you for support!! :D

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
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: script lua night lamp

Post by Flopp »

Great
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest