error in lofile/script script works fine

Moderator: leecollings

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

error in lofile/script script works fine

Post 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
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
jvdz
Posts: 2332
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: error in lofile/script script works fine

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: error in lofile/script script works fine

Post 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
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
jvdz
Posts: 2332
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: error in lofile/script script works fine

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: error in lofile/script script works fine

Post by pvklink »

Thanks,

You were right!
otherdevices_svalues['Denon mode'] = "20" does not work!
commandArray[1]={['Denon mode']='Set Level: 20'} does !
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: error in lofile/script script works fine

Post 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
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest