Page 1 of 1

error in lofile/script script works fine

Posted: Sunday 29 January 2017 18:33
by pvklink
Script works perfect, when activate, it puts my receiver on and when the tv is of, it sets my receiver to radio otherwise its tv.

I got still one error in my logfile, can somebody fix this, i cant. find it...

2017-01-29 18:30:58.458 Hardware Monitor: Fetching data (System sensors)
2017-01-29 18:31:00.172 Error: EventSystem: in Denon aanuit: [string "commandArray = {}..."]:8: attempt to index global 'devicechanged' (a nil value)

Could it be dat i use a commandarray[1] , should i leave the "[1]" out?


SCRIPT for device "Denon aanuit"

commandArray = {}

IP = '192.168.178.176' --IP of denon
IPTV = '192.168.178.13' --IP of tv
DEV='Denon aanuit'
MAXLEVEL=50

if devicechanged[DEV] == 'On' then
local play = 'curl --url "http://' .. IP .. '/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON" &'
os.execute(play)

ping_success=os.execute('ping -c1 192.168.178.13')
if ping_success then
commandArray[1]={['Denon mode']='Set Level 20'} -- switch demo mode op tv zetten
else
commandArray[1]={['Denon mode']='Set Level 10'}-- switch deno mode op radio zetten
end

elseif devicechanged[DEV] == 'Off' then
local play = 'curl --url "http://' .. IP .. '/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FOFF" &' -- oud local play = 'curl --url "http://' .. IP .. '/MainZone/index.put.asp?cmd0=PutVolumeMute%2Fon" &' --mute
os.execute(play)
end

if devicechanged[DEV] then
NewLevel = otherdevices_svalues[DEV]
if NewLevel ~= "Off" and NewLevel ~= "0" then
if tonumber(NewLevel) > MAXLEVEL then --volume maxlevel
NewLevel = MAXLEVEL
end
SendLevel = NewLevel - 80 --79.5
os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/" .. (SendLevel))
end
end

return commandArray

Re: error in lofile/script script works fine

Posted: Sunday 29 January 2017 20:16
by jvdz
Is this a script in the internal editor that fires with each event in stead of just device changes?
There is a dropdown box currently set to All which needs to be changed to Device.

Jos

Re: error in lofile/script script works fine

Posted: Monday 30 January 2017 18:50
by pvklink
Hi Jos (dutch?),

I changed the dropdown and the script.
I now use otherdevices_svalues['Denon mode'] = "20" instead of commandarray[1}........
works error free !
I you have more suggestions to make this script shorter and perfect, you are welcome!
- i think that
-the hardcoded IP used in the ping command could be replaced by a paremeter and
- that the elseif can be changed by a ELSE command and delete the END command before the elseif

Peter (also dutch)

<script>

commandArray = {}

IP = '192.168.178.176' --IP of denon
IPTV = '192.168.178.13' --IP of tv
DEV='Denon aanuit'
MAXLEVEL=50

if devicechanged[DEV] == 'On' then
local play = 'curl --url "http://' .. IP .. '/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON" &'
os.execute(play)
ping_success=os.execute('ping -c1 192.168.178.13')
if ping_success then
otherdevices_svalues['Denon mode'] = "20"
else
otherdevices_svalues['Denon mode'] = "10"
end
elseif devicechanged[DEV] == 'Off' then
local play = 'curl --url "http://' .. IP .. '/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FOFF" &'
os.execute(play)
end

if devicechanged[DEV] then
NewLevel = otherdevices_svalues[DEV]
if NewLevel ~= "Off" and NewLevel ~= "0" then
if tonumber(NewLevel) > MAXLEVEL then --volume maxlevel
NewLevel = MAXLEVEL
end
SendLevel = NewLevel - 80 --79.5
os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/" .. (SendLevel))
end
end

return commandArray

Re: error in lofile/script script works fine

Posted: Monday 30 January 2017 20:15
by jvdz
pvklink wrote:Hi Jos (dutch?)
Ja inderdaad. ;)
pvklink wrote:I changed the dropdown and the script.
This should have solved the reported error.
pvklink wrote:I now use otherdevices_svalues['Denon mode'] = "20" instead of commandarray[1}........
works error free !
Are you sure this really works as this table isn't processed after the lua script completes but rather show the current value?
I think you really need something like:

Code: Select all

commandArray[1]={['Denon mode']='Set Level: 20'}
or 
commandArray['Denon mode']='Set Level: 20'
To trigger the event system to set that switch.

Jos

Re: error in lofile/script script works fine

Posted: Monday 30 January 2017 20:24
by pvklink
Thanks,

You were right!
otherdevices_svalues['Denon mode'] = "20" does not work!
commandArray[1]={['Denon mode']='Set Level: 20'} does !

Re: error in lofile/script script works fine

Posted: Tuesday 31 January 2017 10:21
by pvklink
everything works!
Here my denon lua script..

commandArray = {}

IPDENON = '192.168.178.176'
IPTV = '192.168.178.13'
DEV='Denon aanuit'
MAXLEVEL=60

if devicechanged[DEV] == 'On' then
local play = 'curl --url "http://' .. IPDENON .. '/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON" &'
os.execute(play)
ping_success=os.execute('ping -c1 ' .. IPTV)
if ping_success then
commandArray[1]={['Denon mode']='Set Level 20 AFTER 2'} -- set versterker op tv
commandArray[2]={['Denon mixer']='Set Level 10 AFTER 2'} -- set versterker op stereo
else
commandArray[1]={['Denon mode']='Set Level 10 AFTER 2'} -- set versterker op radio
commandArray[2]={['Denon zender']='Set Level 10 AFTER 2'} -- set radio zender sky
commandArray[3]={['Denon mixer']='Set Level 20 AFTER 2'} -- set versterker op multichannel stereo
end
elseif devicechanged[DEV] == 'Off' then
local play = 'curl --url "http://' .. IPDENON .. '/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FOFF" &'
os.execute(play)
end

if devicechanged[DEV] then
NewLevel = otherdevices_svalues[DEV]
if NewLevel ~= "Off" and NewLevel ~= "0" then
if tonumber(NewLevel) > MAXLEVEL then --volume maxlevel
NewLevel = MAXLEVEL
end
SendLevel = NewLevel - 80 --79.5
os.execute ("curl http://" .. (IPDENON) .. "/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/" .. (SendLevel))
end
end

return commandArray