HOWTO: LGWebOSRemote on LibreELEC via Docker
NamelessCoder opened this issue · 2 comments
Since LibreELEC is my go-to media player, but doesn't play too well with Python applications out of the box, I decided to write up this little HOWTO on running LGWebOSRemote on the very limited OS provided by LibreELEC.
The intention is to do things like use crontab for scheduling certain TV commands during LibreELEC boot and shutdown, and at some point write a Kodi plugin to do some magic with my LG TV.
This should of course also work on any other system than LibreELEC - but the Dockerfile contains some workarounds that were necessary to get things working for me, avoiding some limitations of LibreELEC.
Disclaimer: this is far from perfect as I'm not a genius with Docker. But, it gets the job done. If anyone has feedback, and in particular, feedback about somehow persisting the configuration files, I'd be more than happy to receive it!
I'm hoping this saves some time for someone else trying to wrestle LGWebOSRemote onto LibreELEC or other limited OS'es!
Here goes!
Pre-requisites
- Obviously, install the Docker Kodi add-on.
- Make sure your LibreELEC system has network connectivity.
- Find out how to use SSH to connect to the LibreELEC system.
- Connect via SSH, create a directory to hold the Dockerfile, then continue below.
Dockerfile
FROM python:3.12
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN . /opt/venv/bin/activate && pip install git+https://github.com/klattimer/LGWebOSRemote
RUN mkdir -m 777 -p /opt/venvs/lgtv/config
RUN echo '{"mytv" : {"ip": "10.0.0.69", "client-key": "", "mac-address": "34:e6:e6:a5:c8:3c"}}' > /opt/venvs/lgtv/config/config.json
RUN useradd app
RUN chown app:app /opt/venvs/lgtv/config
RUN chown app:app /opt/venvs/lgtv/config/config.json
USER app
RUN . /opt/venv/bin/activate && exec lgtv auth --ssl 10.0.0.69 mytv
RUN . /opt/venv/bin/activate && exec lgtv setDefault mytv
CMD . /opt/venv/bin/activate && exec lgtvYou'll need to adapt the Dockerfile slightly to fit your system:
- Change the
ipandmac-addresssettings in the JSON array that is written toconfig.json. - Change the IP and TV name in the
authcommand. - If you changed the TV name, also change it in the
setDefaultcommand right below.
Building it
docker build --network=host -t lgtv/remote .- The
--network=hostpart is vital! - While building, your TV will prompt you to authenticate an app. Be ready to accept that dialog.
- Once built, the Docker image contains configuration to operate one TV.
Running it
# example with screenOn command
docker run -t --rm lgtv/remote lgtv --ssl screenOn- The
--rmis added to avoid leaving one dead container for every execution. - The
-tis optional but nice for continuous feedback.
The workarounds
- LibreELEC won't allow network scan with SSDP to discover the TV, so you can't use
lgtv scan- you have to use the IP manually. - Docker (or at least the base image used here) won't allow the configuration file to be automatically created - the build routine must create it.
- Docker won't persist the configuration file changes so you can't store the client key - the
authstep is done when building to make sure the built image contains the right configuration. - The base image has no home directory so the configuration file has to be written to
/opt/venvs/lgtv/config/config.json.
@klattimer If you'd like this moved to the "Discussions" tab or submitted as PR to add a "HOWTO-LibreELEC.md" or other file just let me know and I'll take care of it.
Make it an md file and add it to the project root.