Control your Home Assistant media players using MPRIS
Project description
Control your Home Assistant media players from your desktop using MPRIS!
What?
This project bridges your Home Assistant instance and your desktop to control media players known to your Home Assistant instance.
It works by by communicating with Home Assistant using its websocket API, and exposes media players to your desktop using widely-implemented MPRIS ("Media Player Remote Interfacing Specification") interfaces.
Features
- Shows information about what's currently being played (artist, album, title, cover art)
- Basic playback controls (play, pause, previous, next)
- Volume controlling
- Seeking forwards/backwards
- Minimal configuration needed, autodetects players as they come!
tl;dr:
I want it right now, but how?!
- Install from PyPI, the simplest way is to use pipx. Alternatively, simple clone this repository and run
poetry install
pipx install homeassistant-mpris-bridge
- Launch
hassbridge
hassbridge --endpoint http://192.168.123.123:8123 --token <long lived token>
Instead of using --endpoint
and --token
you can also define the following environment variables to achieve the same:
export HASSBRIDGE_ENDPOINT="http://192.168.123.123:8123"
export HASSBRIDGE_TOKEN="<long lived token>"
Running as systemd service
The simplest way to make sure the bridge is started alongside your desktop session is to create a systemd user service for it:
- Create a service file
~/.config/systemd/user/hassbridge.service
with the following content:
[Unit]
Description=hassbridge
[Service]
ExecStart=<PATH TO HASSBRIDGE>
Environment="HASSBRIDGE_TOKEN=<YOUR TOKEN>"
Environment="HASSBRIDGE_ENDPOINT=<URL TO HOMEASSISTANT>"
[Install]
WantedBy=multi-user.target
You have to do the following substitutions:
- Replace
<PATH TO HASSBRIDGE>
with the location of thehassbridge
script (usewhich hassbridge
) - Replace
<YOUR TOKEN>
with your long-lived token (https://www.home-assistant.io/docs/authentication/#your-account-profile) - Replace
<URL TO HOMEASSISTANT>
with the URL to your instance (e.g., http://192.168.123.123:8123).
- Start the service and verify that it is running correctly
systemctl --user start hassbridge
systemctl --user status hassbridge
- Enable the service so that it starts automatically when you log in
systemctl --user enable hassbridge
hassbridge --help
$ hassbridge --help
Usage: hassbridge [OPTIONS] COMMAND [ARGS]...
hass-mpris bridge.
Options:
--endpoint TEXT
--token TEXT
-d, --debug
--help Show this message and exit.
Commands:
connect
How does it work?
Homeassistant connectivity is achived with homeassistant's websockets API.
Every media_player
entity in the homeassistant instance will then be exposed over D-Bus to other applications to use, implementing two MPRIS interfaces:
- org.mpris.MediaPlayer2
- org.mpris.MediaPlayer2.Player
Each time homeassistant informs over websocket API about a state change, the details for known entities are signaled over the D-Bus interfaces to clients.
Specs
- https://developers.home-assistant.io/docs/api/websocket/
- https://specifications.freedesktop.org/mpris-spec/2.2/
Contributing
Contributions in form of pull requests are more than welcome.
Before submitting a PR, verify that the code is correctly formatted by calling tox -e lint
.
Alternatively, you can use pre-commit
to enforce the checks:
$ pre-commit install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file homeassistant-mpris-bridge-0.0.2.tar.gz
.
File metadata
- Download URL: homeassistant-mpris-bridge-0.0.2.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0066a7fce8e3f3918ac6980f5cae9ebe7121f5aad0ec5870fadaa6c88fca9dec |
|
MD5 | 676641722f7ec21d14463d68690c65a9 |
|
BLAKE2b-256 | 1ddf008e5b2c9a95474e5b18cfe4c297134fd367aaed708a8e4bab21c911e89e |
File details
Details for the file homeassistant_mpris_bridge-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: homeassistant_mpris_bridge-0.0.2-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c5628b2ed7e4474d7588270c04073d9e38cfc97e76d6e5d0f22f92349cfdba3 |
|
MD5 | f9fab576d2c0541349c4b0bc19badacc |
|
BLAKE2b-256 | 9c9d30f1d33912f164e4d7a512947f611f2f078a71db1512986e7a6425785479 |