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.
The script has support to do the the following (default config button):
EXCLUSIVE_MODE = False
near the top. Note that with exclusive mode disabled, a button's default behavior will not be blocked, which means you will not be able to ovveride app buttons or buttons such as "guide".INPUT_DEVICE = "/dev/input/event1"
. To use with both the magic remote and IR remote, run two copies of this script with different INPUT_DEVICE
settings.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
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
}
}
Use this to completely disable a button. Note this will not work if EXCLUSIVE_MODE = False
"netflix": "disabled"
If you wanted to replace the Amazon Prime button with Plex:
wget https://raw.githubusercontent.com/andrewfraley/magic_mapper/main/list_apps.py
python list_apps.py
python3 list_apps.py
Plex : cdp-30
, cdp-30 is the app id for Plex. "prime": {
"function": "launch_app",
"inputs": {
"app_id": "cdp-30"
}
}
start_magic_mapper will redirect output to /tmp/magic_mapper.log
"yellow": {
"function": "cycle_energy_mode",
"inputs": {
"reverse_order": false,
"notifications": true
}
}
"green": {
"function": "set_energy_mode",
"inputs": {
"mode": "auto",
"notifications": true
}
}
"red": {
"function": "reduce_oled_light",
"inputs": {
"increment": 10
}
}
"3": {
"function": "set_oled_backlight",
"inputs": {
"backlight": 50,
"notifications": true
}
}
"9": {
"function": "screen_off"
}
"blue": {
"function": "toggle_eye_comfort",
"inputs": {
"notifications": false
}
}
python list_apps.py
on C9/CX, python3 list_apps.py
on C1/C2+)"1": {
"function": "launch_app",
"inputs": {
"app_id": "netflix"
}
}
"4": {
"function": "press_button",
"inputs": {
"button": "play"
}
}
"5": {
"function": "press_button",
"inputs": {
"button": "pause"
}
}
"0": {
"function": "send_ir_command",
"inputs": {
"tv_input": "optical",
"keycode": "IR_KEY_POWER",
"device_type": "audio"
}
},
Examples: Simple Url call
"7": {
"function": "curl",
"inputs": {
"url": "http://simple_url.example.com",
}
}
Call a Home Assistant webhook trigger with a json payload
"9": {
"function": "curl",
"inputs": {
"url": "http://homeassistant.localdomain:8123/api/webhook/your-webhook-id",
"method": "POST",
"data": "{\"somekey\": \"somevalue\"}",
"headers": "Content-Type: application/json"
}
},
"6": {
"function": "set_dynamic_tone_mapping",
"inputs": {
"value": "HGIG"
}
}
"...": {
"function": "send_cec_button",
"inputs": {
"code": 18882561
}
}
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.
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"
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"
}
}
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
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!
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.
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.