Sending remote press via the command line

Hi,

I have been reading the docs here - CLI Developer Guide | webOS TV Developer

And i see you can use

ares-novacom --device tv --run "ps aux"

Ive tried

ares-novacom --device tv --run "luna://com.webos.service.audio/volumeUp"

To run cmds on the TV.

What I am trying to do it is be able to control the TV from the cmd line without the remote.

I have also tried websockets

const WebSocket = require('ws');
const fs = require('fs');

const TV_IP = '192.168.8.xxx';
const KEY_FILE = 'lgtv_key.json';

function connectToTV() {
    return new Promise((resolve, reject) => {
        const ws = new WebSocket(`ws://${TV_IP}:3000`, { perMessageDeflate: false });

        let clientKey = null;
        if (fs.existsSync(KEY_FILE)) {
            clientKey = JSON.parse(fs.readFileSync(KEY_FILE)).clientKey;
        }

        ws.on('open', () => {
            console.log('✅ Connected to LG TV. Requesting authentication...');

            const authPayload = {
                type: 'register',
                id: 'register_0',
                payload: {
                    forcePairing: false,
                    manifest: {
                        appVersion: '1.0',
                        manifestVersion: 1,
                        permissions: [
                            'ssap://api/getServiceList',
                            'ssap://com.webos.service.networkinput/getPointerInputSocket',
                            'ssap://com.webos.service.ime/sendEnterKey'
                        ],
                        signatures: [{
                            signature: 'dummy_signature',
                            signatureVersion: 1
                        }]
                    }
                }
            };

            if (clientKey) {
                console.log('🔑 Using existing clientKey:', clientKey);
                authPayload.payload['client-key'] = clientKey;
            }

            ws.send(JSON.stringify(authPayload));
        });

        ws.on('message', (data) => {
            const message = JSON.parse(data);
            console.log('📩 Received message:', message);

            if (message.type === 'registered') {
                const newClientKey = message.payload['client-key'];
                if (newClientKey) {
                    fs.writeFileSync(KEY_FILE, JSON.stringify({ clientKey: newClientKey }));
                    console.log('✅ Authentication successful! Key saved:', newClientKey);
                } else {
                    console.log('⚠️ Authentication failed: No client key received.');
                }

                ws.close();
                resolve();
            }
        });

        ws.on('error', (err) => {
            console.error('❌ WebSocket error:', err);
            reject(err);
        });

        ws.on('close', () => {
            console.log('🔌 Connection closed.');
        });
    });
}

async function start() {
    console.log('🔑 Running LG TV Authentication...');
    try {
        await connectToTV();
        console.log('✅ Done! You can now control the TV.');
    } catch (err) {
        console.error('❌ Error during authentication:', err);
    }
}

start();

And send like this.

const WebSocket = require('ws');
const fs = require('fs');

const TV_IP = '192.168.8.xxx';
const KEY_FILE = 'lgtv_key.json';

let clientKey = null;
if (fs.existsSync(KEY_FILE)) {
    clientKey = JSON.parse(fs.readFileSync(KEY_FILE)).clientKey;
}

if (!clientKey) {
    console.error('❌ No client key found. Run auth_store.js first.');
    process.exit(1);
}

async function sendKeyCommand(key) {
    return new Promise((resolve, reject) => {
        const ws = new WebSocket(`ws://${TV_IP}:3000`, { perMessageDeflate: false });

        ws.on('open', () => {
            console.log('✅ Connected to LG TV. Sending key:', key);

            ws.send(JSON.stringify({
                id: 'send_key',
                type: 'request',
                uri: 'ssap://com.webos.service.ime/sendEnterKey',
                payload: {},
                clientKey: clientKey  // ✅ Include the clientKey in the request
            }));
        });

        ws.on('message', (data) => {
            console.log('📩 Response:', data.toString());
            ws.close();
            resolve();
        });

        ws.on('error', (err) => {
            console.error('❌ WebSocket error:', err);
            reject(err);
        });

        ws.on('close', () => {
            console.log('🔌 Connection closed.');
        });
    });
}

// 🕹️ Send the "ENTER" key command
sendKeyCommand('ENTER');

But this doesn’t seem to work for arrows etc.

Can someone suggest the best way to do this without an IR blaster like the RM Mini? I would appreciate any suggestions on the right setup to use.