Looking to combine several LUA scripts for performance. Ideas?
Posted: Sunday 27 August 2017 14:30
As the title says, Looking to get a bit of performance by having less LUA scripts. Quick question about time scripts, does combining them have any performance benefit?
The two scripts for each squeezebox player to get volume status/power etc.. One is for device change and one is time. Please see them below, is it possible to combine all 8 device changes into one LUA script? Many Thanks
The two scripts for each squeezebox player to get volume status/power etc.. One is for device change and one is time. Please see them below, is it possible to combine all 8 device changes into one LUA script? Many Thanks
Code: Select all
commandArray = {}
if ((devicechanged['Bathroom Radio'] == 'On' or devicechanged['Bathroom Radio'] == 'Playing') and uservariables['BTH'] == 'Off') then
commandArray[#commandArray+1]={['Variable:LTV1'] = 'On'}
--commandArray[#commandArray+1]={['Lounge Touch']='Set Volume 30'}
--os.execute('curl -s "http://192.168.1.26:8080/json.htm?type=command¶m=switchlight&idx=265&switchcmd=Set%20Level&level=30" &')
elseif (devicechanged['Bathroom Radio'] == 'Off' or devicechanged['Bathroom Radio'] == 'Stopped' or devicechanged['Bathroom Radio'] == 'Disconnected') then
if otherdevices['Bathroom Radio V'] ~= 'Off' then
commandArray[#commandArray+1]={['Bathroom Radio V'] = 'Off'}
end
commandArray[#commandArray+1]={['Variable:BTH'] = 'Off'}
end
if devicechanged['Bathroom Radio V'] ~= 'Off' and devicechanged['Bathroom Radio V'] ~= nil then
if tonumber(otherdevices_svalues['Bathroom Radio V']) > 0 then
volume = otherdevices_svalues['Bathroom Radio V']
commandArray['Bathroom Radio']='Set Volume '..volume
end
end
return commandArray
Code: Select all
commandArray = {}
if otherdevices['Squeezeboxes'] == 'On' and (otherdevices['Bathroom Radio'] ~= 'Disconnected') then
json = (loadfile '/home/pi/domoticz/scripts/lua/json.lua')()
file = assert(io.popen('curl \'http://192.168.1.26:9000/jsonrpc.js\' --data-binary \'{"id":1,"method":"slim.request","params":["aa:aa:f8:02:4e:bd",["status","-","1",""]]}\''))
raw = file:read('*all')
file:close()
deviceinfo = json:decode(raw)
powerstatus = deviceinfo.result.power
playervolume = deviceinfo.result["mixer volume"] + 1
switchvolume = otherdevices_svalues['Bathroom Radio V']
difference = math.abs(switchvolume - playervolume)
if difference > 1 and tonumber(powerstatus) == 1 then
os.execute('curl -s "http://192.168.1.26:8080/json.htm?type=command¶m=switchlight&idx=361&switchcmd=Set%20Level&level='..playervolume..'" &')
end
if tonumber(powerstatus) == 1 and otherdevices['Bathroom Radio V'] == 'Off' then
os.execute('curl -s "http://192.168.1.26:8080/json.htm?type=command¶m=switchlight&idx=361&switchcmd=Set%20Level&level='..playervolume..'" &')
end
end
return commandArray