Thanks Thom,
OK, if anyone wants to test my working LG TV template please follow these steps.
1. Ensure that your LG TV has the same commands as device template 2126. Check your manual. As far as I can see (looking at recent LG manuals) most LGs share mostly the same RS232 commands.
2. Change the Plug and Play script on your MD in /usr/pluto/pnp/20_LG_TV.sh to point to device template 2126. It should look like this.
#!/bin/bash
echo "LG TV Detection script queue $2"
/usr/pluto/bin/TestSerialPort -p $3 -P N81 -b 9600 -t "ka 01 01\r\n" -s "a 01 " -i 8
if [[ "$?" -ne 0 ]]; then
echo "It's not a LG TV"
/usr/pluto/bin/MessageSend dcerouter -r 0 $1 1 806 224 $2 13 "$4" 44 0
else
echo "It is an LG TV"
/usr/pluto/bin/MessageSend dcerouter -r 0 $1 1 806 224 $2 13 "$4" 44 2126
fi
Note! This is where we can add support for different models later. We can issue model specific commands and if we get a good ack we point to the relevant template, if not try the next one etc.
3. In Web Admin go to Advanced > Configuration > Device Templates. Select LG in the first box and 'apply filter' then find '37LH30 RS232' in the 'Device Template' box (or type 2126 in the bottom box and type 'GO'). Then click 'Pick Device Template'.
4. A new window will open. Near the top click 'Edit Ruby Codes'.
5. Another window will open with the codes.
6. Go to the inputs section. There are lots of different inputs (hdmi 1, hdmi2, AV1 etc). Change all the input commands from 'kb' to 'xb'. Check your manual to confirm this.
7. Go to #355 Process Initialize and copy and paste this:
# Initialize --- Date: 28.02.2008
# the docs are wrong. they say responses are terminated with a \r. In reality some sets do, others don't.
# some sets won't respond to ka 01 ff when the tv is off. others do.
@mute = false;
# unfortunately we have to turn the device on if it's off to know that it's alive or else it won't respond to anything
@input=-1
for iRetry in 0...4
print "Initializing unit\n"
# Query the current volume level
conn_.Send("kf 1 ff\r")
# wait 4 seconds for the status command, which won't work if the tv is off
$buf = conn_.RecvDelimited("x", 4000)
if( !$buf.nil? && !$buf.index("01 OK").nil? )
print "Initialized ok - tv is on\n"
# Use the returned response to set the volume
x = $buf.index("OK")
volume_level =$buf[x+2,2].to_i(16)
print "Setting volume to ", volume_level, "\n"
cmd_313(volume_level)
return
end
print "TV is either off or not connected\n"
# try turning it on
conn_.Send("ka 1 01\r")
# wait 10 seconds for the TV to respond
sleep(10)
# Query the current volume level
conn_.Send("kf 1 ff\r")
# wait 4 seconds for the status command, which won't work if the tv is off
$buf = conn_.RecvDelimited("x", 4000)
if( !$buf.nil? && !$buf.index("01 OK").nil? )
print "Initialized ok - tv was off\n"
# Use the returned response to set the volume
x = $buf.index("OK")
volume_level =$buf[x+2,2].to_i(16)
print "Setting volume to ", volume_level, "\n"
cmd_313(volume_level)
# Turn TV off again
conn_.Send("ka 1 00\r")
return
end
print "TV is not connected\n"
sleep(1)
end
#DisableDevice( device_.devid_, true )
print "The device wouldn't respond. Disabling it.\n"
8. Go to #313 Set Volume and copy and paste this.
@volume=level.to_i()
ilevel = (@volume).to_i
print "setting volume to ", ilevel , "\n"
if ilevel <16
SendCommand("kf 01 0" + "%x" % ilevel,1000,4)
else
SendCommand("kf 01 " + "%x" % ilevel,1000,4)
end
SetDeviceDataInDB( device_.devid_,device_.devid_.to_i , ilevel.to_s)
print "volume and corresponding device data set\n"
9. At the bottom of the page click 'Update'
10. Do a quick reload router. Or even a full reboot (can't remember what I did). The LG TV should be autodetected and you should be presented with the setup wizard to confirm the device and select your inputs etc
11. Come back here and let me know if it works.
Good luck,
Barney