MCPcopy Index your code
hub / github.com/SLG/lgtv2mqtt

github.com/SLG/lgtv2mqtt @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
390 symbols 1,076 edges 6 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

LG TV 2 MQTT WebOS Service

For WebOS 6. Maybe it works for earlier or later versions...?

Setup tv

WebOS developer

Register as an LG WebOS developer

Connect TV

  • Then you can connect with your tv:
ares-setup-device

Install app and service

  • Check out the code
  • Run the following command:
npm install
  • Update these fields in src\index.ts:
const config: LgTvMqttConfig = {
   host: 'YOUR MQTT BROKER HOST',
   port: 1883,
   username: 'YOUR MQTT USERNAME',
   password: 'YOUR MQTT PASSWORD',
   deviceID: 'webOSTVService'
};
  • Update package-and-install.bat with the id of your tv, if needed
  • Run package-and-install.bat

The service and app are now installed.

Starting the service

The app is now installed on the home screen, and can be started from there.

Automatically with an automation

Based on a notification (Can MQTT be turned on?) and home-assistant-variables:

alias: "Start TV app MQTT "
description: ""
trigger:
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: TURN_TV_MQTT_ON
condition: []
action:
  - service: var.update
    data:
      entity_id: var.tv_media_source
  - service: media_player.select_source
    data:
      source: LG TV 2 MQTT TV App
    target:
      entity_id: media_player.living_room_tv
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: media_player.select_source
    data:
      source: "{{states('var.tv_media_source')}}"
    target:
      entity_id: media_player.living_room_tv
mode: single

Using the service

If you have the MQTT integration enabled in Home Assistant, the service should be auto discovered:

The sensor.webostvservice_play_state should be updated when you play, pause, or stop an app on the tv.

An example automation:

alias: Turn lights off when playing a movie
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.webostvservice_play_state
    to: playing
condition: []
action:
  - service: light.turn_off
    target:
      entity_id:
        - light.some_light_entity
    data: {}
mode: single

Renew Devmode session

Manually

  1. Make sure the sdk is working
  2. Run ssh prisoner@<tv IP> -p 9922 -i <key location> "/bin/sh -i"
  3. Run cat /var/luna/preferences/devmode_enabled and safe the promting key
  4. in Home Asisstant configuration.yaml: yaml rest_command: update_lg_dev: url: "https://developer.lge.com/secure/ResetDevModeSession.dev?sessionToken=<the key from step 3>"
  5. Create an automation: ```yaml alias: Reset LG Dev session description: "" trigger:
    • platform: time at: "01:00:00" condition: [] action:
    • service: rest_command.update_lg_dev data: {} mode: single ```

notes:

The key is located in ~/ssh name is webos with your device name

You can ignore the prompting error message

source

TODO

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 364
Method 17
Class 4
Interface 4
Enum 1

Languages

TypeScript100%

Modules by API surface

tv-app/webOSTVjs-1.2.7/webOSTV.js330 symbols
tv-app/webOSTVjs-1.2.7/webOSTV-dev.js27 symbols
tv-service/src/lgtv-mqtt.ts21 symbols
tv-app/js/script.js7 symbols
tv-service/src/logging.ts5 symbols

For agents

$ claude mcp add lgtv2mqtt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page