Skip to content

Instantly share code, notes, and snippets.

@saamerm
Last active July 1, 2026 14:43
Show Gist options
  • Select an option

  • Save saamerm/e0fc57906a31535fea6591a8650e92b2 to your computer and use it in GitHub Desktop.

Select an option

Save saamerm/e0fc57906a31535fea6591a8650e92b2 to your computer and use it in GitHub Desktop.
Use this code to Control your Hisense TV with In-built Fire TV remotely. This is the server code, needed for the front end code https://gist.github.com/saamerm/df3e08e9564c5a65b1cbf41b6c5be6ea
// You need a server in order to prevent CORS errors from allowing you to communicate with the TV
// Steps to get started: Make sure you have node installed, then download this file (or create a new file and put it in a blank directory and then run the commands below in your terminal
// npm init -y
// npm install express cors adbkit wakeonlan
// node hisense-online-remote.js
const express = require('express');
const cors = require('cors');
const adb = require('adbkit');
const wol = require('wakeonlan');
const app = express();
app.use(cors());
app.use(express.json());
// ⚠️ Configurations for your Hisense Fire TV
const TV_IP = "{YOUR TVS IP ADDRESS, EG: 192.168.0.12}";
const TV_MAC = "{YOUR TVS MAC ADDRESS, EG: 14:14:16:92:28:9F}"; // For the Wake Up functionality
// Initialize the ADB Client
const adbClient = adb.createClient();
const deviceId = `${TV_IP}:5555`;
// Connect to the Fire TV over the network
function connectADB() {
adbClient.connect(TV_IP, 5555)
.then(() => console.log(`Connected to Fire TV ADB at ${deviceId}`))
.catch(err => console.error(`ADB Connection failed (Is ADB turned on in TV settings?):`, err.message));
}
connectADB();
// Endpoint to turn the TV ON via Wake-on-LAN
app.post('/api/wakeup', (req, res) => {
console.log(`Sending Wake-on-LAN packet to MAC: ${TV_MAC}`);
wol(TV_MAC).then(() => {
// Wait 5 seconds for network to initialize, then reconnect ADB
setTimeout(connectADB, 5500);
res.json({ success: true, message: "Magic packet sent successfully." });
}).catch((err) => {
console.error("Wake-on-LAN failed:", err);
res.status(500).json({ success: false, error: err.message });
});
});
// Primary Endpoint Route for Fire TV KeyEvents
app.post('/api/command', (req, res) => {
const { key } = req.body;
if (!key) return res.status(400).json({ success: false, error: "Missing key parameter" });
console.log(`Relaying Android KeyEvent to TV: [${key}]`);
// Sends standard Android keyevents directly to Fire OS
adbClient.shell(deviceId, `input keyevent ${key}`)
.then(adb.util.readAll)
.then(() => {
res.json({ success: true });
})
.catch((err) => {
console.error("Failed to send command. Attempting reconnection...", err.message);
connectADB(); // Try to repair connection if dropped
res.status(500).json({ success: false, error: "TV connection offline" });
});
});
app.listen(3000, () => console.log('Fire TV Relay server active on http://localhost:3000'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment