andrewfraley / magic_mapper

Remap LG Magic Remote buttons
MIT License
56 stars 5 forks source link

Magic Mapper

Summary

Magic Mapper is a script that will let you remap unused buttons on the LG Magic Remote. The script itself runs on your rooted LG TV, detects button presses, and allows you to control anything available via the luna-send api. Note your TV must be rooted to use this.

Currently Supported Functions

The script has support to do the the following (default config button):

TV Models supported (Likely any LG TV after 2018 are supported until this stops working with unknown future models)

Known Issues

Installation / Setup

cd /home/root
wget https://raw.githubusercontent.com/andrewfraley/magic_mapper/main/magic_mapper.py
wget https://raw.githubusercontent.com/andrewfraley/magic_mapper/main/magic_mapper_config.json
cd /var/lib/webosbrew/init.d
wget https://raw.githubusercontent.com/andrewfraley/magic_mapper/main/start_magic_mapper
chmod +x /var/lib/webosbrew/init.d/start_magic_mapper

Configuring buttons

Buttons are configured via the magic_mapper_config.json file. magic_mapper_config.json contains a json formatted dictionary where each primary key is the name of the button to map (see the Button List below). Note that changes to magic_mapper_config.json require you to restart the script, so just reboot your TV or if testing over SSH, kill the magic_mapper.py process and run the script manually.

"yellow": {  # The name of the button to remap, see the Button List below
  "function": "cycle_energy_mode",   # The matching function to execute in magic_mapper.py - see Function List below
  "inputs": {                        # The input dict to send to the function, different functions use different inputs, see the Function List below
    "reverse_order": false,
    "notifications": true
  }
}

Disabling a button

Use this to completely disable a button. Note this will not work if EXCLUSIVE_MODE = False

"netflix": "disabled"

Overriding App Buttons

If you wanted to replace the Amazon Prime button with Plex:

  "prime": {
    "function": "launch_app",
    "inputs": {
      "app_id": "cdp-30"
    }
  }

Logs

start_magic_mapper will redirect output to /tmp/magic_mapper.log

Function List

cycle_energy_mode

set_energy_mode

reduce_oled_light / increase_oled_light

set_oled_light

screen_off

toggle_eye_comfort

launch_app

press_button

send_ir_command

curl

set_dynamic_tone_mapping

send_cec_button

Disable Mouse (Experimental)

To disable the mouse, edit the script and change BLOCK_MOUSE = True near the top. This will prevent WebOS from seeing that the remote has activated its mouse. Note that this does not disable the mouse inside the remote, but it prevents WebOS from seeing that it has been activated. Due to the way this works there could be erratic behavior, please report any problems by opening an issue.

Button List

List of known buttons and their codes. Not all remote buttons are on this list, but if needed, you can modify magic_mapper.py to add other button codes. Just run magic_mapper.py manually and it will list all button codes it sees.

Note that long presses (longer than 1s) are ignored. I will eventually add support for different actions based on short vs long press.

 "red"
 "green"
 "yellow"
 "blue"
 "ch_up"
 "ch_down"
 "vol_up"
 "vol_down"
 "play"
 "pause"
 "stop"
 "fastforward"
 "rewind"
 "1"
 "2"
 "3"
 "4"
 "5"
 "6"
 "7"
 "8"
 "9"
 "0"
 "prime"
 "netflix"
 "disney"
 "lg_channels"
 "alexa"
 "google"
 "guide"
 "voice"
 "channels"
 "..."
 "...alt"  - Seen on a non-magic remote
 "search"
 "search_alt" - Seen on a non-magic remote
 "exit"  - Not the back button, this exits apps, seen on a non-magic remote
 "sap"
 "info"
 "tv"
 "home"

Other Use Cases

Input Switching

The remote has built in shortcuts for input switching using the "Quick Select" functionality where you long press the number keys. If you'd rather have short press input shortcuts instead (and the ability to use the color buttons), you can use the launch_app function.

"1": {
  "function": "launch_app",
  "inputs": {
    "app_id": "com.webos.app.hdmi3"
  }
}

Help!

If you need assistance, please open an issue on Github here: https://github.com/andrewfraley/magic_mapper/issues

You can view all issues (closed and still open) here: https://github.com/andrewfraley/magic_mapper/issues?q=is%3Aissue

Modifying the script

The function names supplied in magic_mapper_config.json map to the function names in the script. If you wanted to have the yellow button do something unsupported by this script, create a new function in magic_mapper.py and then add the function to magic_mapper_config.json such as:

"yellow": {
  "function": "your_new_function_name"
  "inputs": {
    "variable_passed_to_function": "value_for_variable",
    "another_variable": "value_for_var"
  }
}

There are some various examples of the luna-send endpoints and payloads here (scroll down a bit): https://gist.github.com/Ircama/1f29c2d2def75da6604756a3c91a8ab4

For documentation on each endpoint, see the WebOS developer docs: https://www.webosose.org/docs/reference/ls2-api/ls2-api-index/

If you add new novel functionality that others might make use of, please submit a PR!

Donations

If you love this project and want to donate to support it, donate your money somewhere else! If you don't have a charity in mind, food banks are always in dire need of your support, consider donating to your local regional food bank.

Similar projects

There is now a similar app in the HomeBrew app store called LG Input Hook. This app can provide similar functionality, and is easy to setup, especially if your only needs are remapping simple buttons and executing basic luna-send commands.

TODO Items