Sony BD Player Plugin

This is a plugin for a Sony Blu-ray Player that is controlled over IP.

I have a Sony BDP-S3700 and I am not familiar enough with how various kinds of Sony BD players are controlled, so this may only work with a subset, at least without a little modification. I pulled parts of it from these topics on controlling other Sony devices:

I also included the Wake-on-LAN functionality discussed in one of the topics from the old forum and I added a Select command that wasn’t present in the linked documentation that I got from iRule.

The plugin has 5 settings that can be configured: Host, Port, MAC, UseIPforWOL, and WOLPort. Host should be set to the player’s hostname/IP address and port seems to vary based on the specific model of BD player (50001, 52323, or even 80). MAC is the MAC address of the player. UseIPforWOL, if it is set to anything other than an empty string, will also send the Host and, if specified, WOLPort in the WOL message. My particular player only needs the MAC address, but the WOL API supports the additional information so I included but did not test them.

Last Updated: 2020-04-28
SonyBDPlayer-2020-04-28.plugin (7.2 KB)

plugin.Name = "SonyBDPlayer";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = -1;
plugin.DefaultSettings = {
    "Host"          : "192.168.1.1",
    "Port"          : "50001",  // some use 52323 or standard 80 instead
    "MAC"           : "11:22:33:44:55:66",
    "UseIPforWOL"   : "",   // set this to anything other than empty string if need to send IP (and port) for WOL; host must be IP address and not name in this case
    "WOLPort"       : "",   // standard is 9; if left empty, the port will not be sent
};

var VERSION = "2020-04-28";

var http = new HTTPClient();

var powerOn = false;

var mediaCommandMappings = {
    "PowerOn"       : "WOL",
    "PowerOff"      : "AAAAAwAAHFoAAAAVAw==",

    "DirectionUp"   : "AAAAAwAAHFoAAAA5Aw==",
    "DirectionLeft" : "AAAAAwAAHFoAAAA7Aw==",
    "DirectionDown" : "AAAAAwAAHFoAAAA6Aw==",
    "DirectionRight": "AAAAAwAAHFoAAAA8Aw==",
    "Select"        : "AAAAAwAAHFoAAAA9Aw==",

    "Home"          : "AAAAAwAAHFoAAABCAw==",
    "Options"       : "AAAAAwAAHFoAAAA/Aw==",
    "Return"        : "AAAAAwAAHFoAAABDAw==",

    "Number1"       : "AAAAAwAAHFoAAAAAAw==",
    "Number2"       : "AAAAAwAAHFoAAAABAw==",
    "Number3"       : "AAAAAwAAHFoAAAACAw==",
    "Number4"       : "AAAAAwAAHFoAAAADAw==",
    "Number5"       : "AAAAAwAAHFoAAAAEAw==",
    "Number6"       : "AAAAAwAAHFoAAAAFAw==",
    "Number7"       : "AAAAAwAAHFoAAAAGAw==",
    "Number8"       : "AAAAAwAAHFoAAAAHAw==",
    "Number9"       : "AAAAAwAAHFoAAAAIAw==",
    "Number0"       : "AAAAAwAAHFoAAAAJAw==",

    "Display"       : "AAAAAwAAHFoAAABBAw==",
    "Audio"         : "AAAAAwAAHFoAAABkAw==",
    "SubTitle"      : "AAAAAwAAHFoAAABjAw==",
    "Favorites"     : "AAAAAwAAHFoAAABeAw==",

    "Yellow"        : "AAAAAwAAHFoAAABpAw==",
    "Blue"          : "AAAAAwAAHFoAAABmAw==",
    "Red"           : "AAAAAwAAHFoAAABnAw==",
    "Green"         : "AAAAAwAAHFoAAABoAw==",

    "Play"          : "AAAAAwAAHFoAAAAaAw==",
    "Stop"          : "AAAAAwAAHFoAAAAYAw==",
    "Pause"         : "AAAAAwAAHFoAAAAZAw==",
    "Rewind"        : "AAAAAwAAHFoAAAAbAw==",
    "FastForward"   : "AAAAAwAAHFoAAAAcAw==",
    "Prev"          : "AAAAAwAAHFoAAABXAw==",
    "Next"          : "AAAAAwAAHFoAAABWAw==",
    "SkipBackward"  : "AAAAAwAAHFoAAAB2Aw==",
    "SkipForward"   : "AAAAAwAAHFoAAAB1Aw==",

    "Angle"         : "AAAAAwAAHFoAAABlAw==",
    "TopMenu"       : "AAAAAwAAHFoAAAAsAw==",
    "PopUpMenu"     : "AAAAAwAAHFoAAAApAw==",
    "Eject"         : "AAAAAwAAHFoAAAAWAw==",

    "Karaoke"       : "AAAAAwAAHFoAAABKAw==",
    "Qriocity"      : "AAAAAwAAHFoAAABMAw==",
    "Netflix"       : "AAAAAwAAHFoAAABLAw==",
    "Mode3D"        : "AAAAAwAAHFoAAABNAw==",
};



function onChangeRequest(device, attribute, value) {
    console.log("onChangeRequest called...");

    var host = plugin.Settings["Host"];
    var port = plugin.Settings["Port"];
    var mac = plugin.Settings["MAC"];
    var useipforwol = (plugin.Settings["UseIPforWOL"] == "") ? false : true;
    var wolport = plugin.Settings["WOLPort"];

    switch(attribute) {
        case "MediaCommand":

            var cmd = mediaCommandMappings[value];

            if(cmd) {
                if(cmd == "WOL") {
                    console.log("  MAC: " + mac);
                    console.log("  use IP for WOL?: " + useipforwol);
                    console.log("  Host: " + host);
                    console.log("  WOLPort: " + wolport);

                    var wolOpts = {};
                    if(useipforwol) {
                        wolOpts["address"] = host;
                        if(wolport != "") {
                            wolOpts["port"] = parseInt(wolport);
                        }

                        console.log("  sending WOL to: " + mac + " with " + wolOpts);
                        WOL.wake(mac, wolOpts);

                    } else {
                        console.log("  sending WOL to: " + mac);
                        WOL.wake(mac);
                    }

                    // very simple power state monitoring
                    powerOn = true;

                } else if(!powerOn && value == "PowerOff") {
                    // we're not on, so don't try to turn us off (this avoid an annoying message in some situations)
                    console.log("  not powered on, so power off command ignored");

                } else {
                    var url = "";
                    var body = "";
                    var httpOptions = {};

                    console.log("  Host: " + host);
                    console.log("  Port: " + port);

                    url += "http://" + host;
                    if(port != 80) {
                        url += ":" + port;
                    }
                    // NOTE: some devices apparently use "/sony/IRCC" instead
                    url +=  "/upnp/control/IRCC";

                    body += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:X_SendIRCC xmlns:u=\"urn:schemas-sony-com:service:IRCC:1\"><IRCCCode>";
                    body += cmd;
                    body += "</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>";

                    httpOptions = {
                        headers: {
                            "Content-Type" : "text/xml",
                            "SOAPACTION" : "\"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC\"",
                        }
                    };

                    console.log("  sending request to: " + url);
                    console.log("  command: " + cmd);

                    http.post(url, body, httpOptions);

                    if(value == "PowerOff") {
                        // update power state
                        powerOn = false;
                    }

                    // all done
                }

            } else {
                console.log("ERROR: unsupported command: " + value);
            }

            break;

        default:
            console.log("ERROR: unsupported attribute type: " + attribute);
            break;
    }
}

function onConnect() {
    console.log("onConnect called...");

    var device = plugin.Devices[plugin.Name];

    if(device) {
        console.log("  setting supported media commands...");
        device.SupportedMediaCommands = Object.keys(mediaCommandMappings);
        console.log("  set...");
    }
}

function onDisconnect() {
    console.log("onDisconnect called...");
}

function onPoll() {
    console.log("onPoll called...");
}

function onSynchronizeDevices() {
    console.log("onSynchronizeDevices called...");

    var device = new Device();

    device.Name = plugin.Name;  // override default naming conversion so it looks nicer
    device.Id = plugin.Name;
    device.DisplayName = "Sony BD Player";
    device.Icon = "Disc";
    device.Capabilities = [ "MediaControl" ];
    device.Attributes = [ ];

    plugin.Devices[plugin.Name] = device;

    console.log("  done syncing");
}
2 Likes

Many thanks for this! I had to use UseIPforWOL to 1 to get PowerOn/WOL to work with my BDP-S5200.

1 Like

Great! Glad to know that part of the code works as intended, since I wasn’t able to test it myself :slight_smile:

Hi I,m very new to homeremote and am having trouble understanding how to program it having come across from irule. I had no idea how to use the plugin you developed and so loaded a .hrp file with the plugin already there. Once I changed the ip address it worked fine but when i tried to add another device (my receiver) the message “no devices found” was shown on the screen although the receiver icon was there under the devices tab. Also there are no commands available on this device when trying to bind a button. I then started with a new project and imported your plugin. I noticed that the IR part was now missing? and, I cannot seem to get the commands to work. Just a quick explanation of how to get one command to work would help. Thank You. Oh, by the way do you know any sites that i can download button icons and logo files from. Cheers

Hi Dave,

I came from iRule also and the Home Remote has a bit of a learning curve (but then, so did iRule). I’m not sure about some of the more general THR issues you mention, but in terms of importing this plugin and the IR part missing, I can help. This plugin is for IP-based control of the player, not IR. If you are controlling it via IR (using a global cache, I assume), then this plugin is not what you want. I saw you had another open question that Bill was helping you with on the IR stuff, so I’ll totally defer on those.

If you do still want to use this plugin, once you’ve imported it and changed the Settings to point it at the right device, you just need to create buttons and then bind their EventTrigger to send the right MediaCommands. For example, once you have a button selected, go to the Actions for the default EventTrigger (select the button with the 3 dots next to “(Collection)”) and then set the binding like this:

You can see in the plugin which MediaCommands it supports, and those are the ones you put in the Value field. The way to think of it is that when the button is pushed, it’s EventTrigger is fired and that then sets the value to the bound parameter of the device. The plugin detects the value that is set and then sends the right command over the network.

I hope that’s relatively clear. I apologize, but I recently moved and I no longer have my home theater :frowning: so I don’t do much with THR at the moment. Hoping to build a new one in my new house, but that may take a while. I also am very rusty on the iRule terminology, so I’m afraid I can’t even help with that level of translation. That said, once you get the hang of how THR does things, it’s pretty powerful and intuitive–getting started is definitely the tricky part.

Good luck!

HFN

Hi I am using both types of command, IR for some components but mainly IP commands for my Sony blueray player etc. I thank you for your reply and tomorrow I will try your suggestions. Where do you get your button icons /backgrounds etc, are there any libraries, Irule had a load built in.
Thanks so far.

There are builtin icons (although not nearly as many as in iRule) as discussed in bill’s post here: How to add additional icons? - #7 by bill. In addition, this thread might be helpful: Where to download icon packs? I think a lot of people kind of do their own thing with icons and such.