Hey
I recently inherited a Optoma Themescene HD86 projector which I wanted to control via Home Remote. It’s a few years old and doesn’t have a network port, but rather than opt for IR control I used an IP to RS232 adapter so I could address its serial port over the network. Using this I wrote a basic plugin so Home Remote can turn it on and off, and know its state:
plugin.Name = "OptomaProjector";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 2000;
plugin.DefaultSettings = { "Host": "192.168.1.100", "Port": "23" };
var tcp = new TCPClient();
var tcpDeviceId = "projector";
function onChangeRequest(device, attribute, value) {
switch (attribute) {
case "Switch":
switch (value) {
case "On":
console.log("Turning On Projector");
tcp.send("~0000 1\r");
return;
case "Off":
console.log("Turning Off Projector");
tcp.send("~0000 2\r");
return;
};
default:
return;
}
}
function onConnect() {
var host = plugin.Settings["Host"];
var port = plugin.Settings["Port"];
if (host && port) {
tcp.connect(host, parseInt(port));
console.log("Connected to " + host + ":" + port);
}
else {
tcp.connect("192.168.1.100", 23);
}
}
function onDisconnect() {
console.log("Disconnecting...")
tcp.close();
}
function onPoll() {
console.log("Polling...");
tcp.send("~00124 1\r");
sleep(1000);
var data = tcp.receive({timeout: 1000});
console.log("message received: " + data);
var lastResponse = data.trim().split("\r").pop();
console.log("response: " + lastResponse);
switch (lastResponse) {
case "OK0":
console.log("State is off");
plugin.Devices[tcpDeviceId].Switch = "Off";
break;
case "OK1":
console.log("State is on");
plugin.Devices[tcpDeviceId].Switch = "On";
break;
}
}
function onSynchronizeDevices() {
var projectorDevice = new Device();
projectorDevice.Id = tcpDeviceId;
projectorDevice.DisplayName = "Optoma Projector";
projectorDevice.Capabilities = ["Switch"];
projectorDevice.Attributes = [];
plugin.Devices[projectorDevice.Id] = projectorDevice;
}
It took a few iterations to get the tcp handling right - it’s very easy to get blocked on tcp.receive()
, even with a timeout (doesn’t seem to work?) - but it’s working pretty well at this point. Serial commands are listed in the user manual found here. I took a quick look through the manual of newer projectors and the command codes look the same, so this should work for those too if anyone needs that.