j3dog
Posts: 2
Joined: Thu May 11, 2017 7:04 pm

control a Panasonic TV via Pi

Fri Nov 30, 2018 8:36 pm

Can you help?

This code purports to control a Panasonic TV. I found it on 'Smart home Controls' forum. I was wondering if it could be adapted for use on a Raspberry Pi?

Any clues to if its possible to convert to python would be very much appreciated.

J3dog

function TVControl(KeyPress)
local DeviceIpAddress = TV_IP_ADDRESS
local http = require "socket.http"
local ltn12 = require"ltn12"

local h_ds = "\045"
local h_lt = "\060"
local h_qm = "\063"
local h_gt = "\062"
local h_qt = "\034"
local req = h_lt..h_qm.."xml version="..h_qt..'1.0'..h_qt.." encoding="..h_qt..'UTF-8'..h_qt..h_qm..h_gt
req = req .. h_lt.."s:Envelope xmlns:s="..h_qt.."http://schemas.xmlsoap.org/soap/envelope/"..h_qt.." s:encodingStyle="..h_qt.."http://schemas.xmlsoap.org/soap/envelope/"..h_qt..h_gt
req = req .. h_lt.."s:Body"..h_gt
req = req .. h_lt.."u:X_SendKey xmlns:u="..h_qt.. "urn:panasonic-com:service:p00NetworkControl:1" .. h_qt..h_gt
req = req .. h_lt.."X_KeyEvent" .. h_gt.. KeyPress .. h_lt .."/X_KeyEvent" .. h_gt
req = req .. h_lt.."/u:X_SendKey" .. h_gt
req = req .. h_lt.."/s:Body"..h_gt
req = req .. h_lt.."/s:Envelope"..h_gt

local reqHeaders = {
["HOST"] = DeviceIpAddress..":55000",
["USER-AGENT"] = "Panasonic iOS VR-CP UPnP/2.0",
["SOAPACTION"] = h_qt .. "urn:panasonic-com:service:p00NetworkControl:1#X_SendKey" .. h_qt,
["Content-Type"] = "text/xml;charset="..h_qt.."utf-8"..h_qt,
["Content-Length"] = tostring(#req)
}

local respBody = { }
local rHeaders, rCode, rError = socket.http.request
{
method = "POST";
url = "http://"..DeviceIpAddress..":55000/nrc/control_0";
headers = reqHeaders;
source = ltn12.source.string(req);
sink = ltn12.sink.table(respBody)
}
end

"NRC_CH_DOWN-ONOFF", // channel down
"NRC_CH_UP-ONOFF", // channel up
"NRC_VOLUP-ONOFF", // volume up
"NRC_VOLDOWN-ONOFF", // volume down
"NRC_MUTE-ONOFF", // mute
"NRC_TV-ONOFF", // TV
"NRC_CHG_INPUT-ONOFF", // AV,
"NRC_RED-ONOFF", // red
"NRC_GREEN-ONOFF", // green
"NRC_YELLOW-ONOFF", // yellow
"NRC_BLUE-ONOFF", // blue
"NRC_VTOOLS-ONOFF", // VIERA tools
"NRC_CANCEL-ONOFF", // Cancel / Exit
"NRC_SUBMENU-ONOFF", // Option
"NRC_RETURN-ONOFF", // Return
"NRC_ENTER-ONOFF", // Control Center click / enter
"NRC_RIGHT-ONOFF", // Control RIGHT
"NRC_LEFT-ONOFF", // Control LEFT
"NRC_UP-ONOFF", // Control UP
"NRC_DOWN-ONOFF", // Control DOWN
"NRC_3D-ONOFF", // 3D button
"NRC_SD_CARD-ONOFF", // SD-card
"NRC_DISP_MODE-ONOFF", // Display mode / Aspect ratio
"NRC_MENU-ONOFF", // Menu
"NRC_INTERNET-ONOFF", // VIERA connect
"NRC_VIERA_LINK-ONOFF", // VIERA link
"NRC_EPG-ONOFF", // Guide / EPG
"NRC_TEXT-ONOFF", // Text / TTV
"NRC_STTL-ONOFF", // STTL / Subtitles
"NRC_INFO-ONOFF", // info
"NRC_INDEX-ONOFF", // TTV index
"NRC_HOLD-ONOFF", // TTV hold / image freeze
"NRC_R_TUNE-ONOFF", // Last view
"NRC_POWER-ONOFF", // Power off

"NRC_REW-ONOFF", // rewind
"NRC_PLAY-ONOFF", // play
"NRC_FF-ONOFF", // fast forward
"NRC_SKIP_PREV-ONOFF", // skip previous
"NRC_PAUSE-ONOFF", // pause
"NRC_SKIP_NEXT-ONOFF", // skip next
"NRC_STOP-ONOFF", // stop
"NRC_REC-ONOFF", // record

// numeric buttons
"NRC_D1-ONOFF", "NRC_D2-ONOFF", "NRC_D3-ONOFF", "NRC_D4-ONOFF", "NRC_D5-ONOFF",
"NRC_D6-ONOFF", "NRC_D7-ONOFF", "NRC_D8-ONOFF", "NRC_D9-ONOFF", "NRC_D0-ONOFF",

Andyroo
Posts: 689
Joined: Sat Jun 16, 2018 12:49 am

Re: control a Panasonic TV via Pi

Fri Nov 30, 2018 11:10 pm

It seems to infer that the TV has a web server built in that takes a POST of xml :?:

Do you have a phone app that controls the TV?

If so I would pop Wireshark onto the Pi and see what it can sniff!

You could also see if the box has a serial port on the back (my old one did unlike the Sony I’ve got now) and see if you can find a manual for that.

Do Panasonic have a developer programme- they normally cost £££ but may be worth checking :roll:
Need Pi spray - these things are breeding in my house...

User avatar
Paul Webster
Posts: 762
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK

Re: control a Panasonic TV via Pi

Sat Dec 01, 2018 8:18 am

You could install Home-Assistant - written in Python and has a plugin for Panasonic TVs that make port 55000 available for remote control

https://www.home-assistant.io/component ... nic_viera/

Return to “Other programming languages”