TroyFernandes / hass-mqtt-mediaplayer

Fill out your Media Player Entity with MQTT Topics
MIT License
32 stars 18 forks source link
homeassistant homeassistant-components mediaplayer mqtt

hass-mqtt-mediaplayer

Allows you to use MQTT topics to fill out the information needed for the Home Assistant Media Player Entity

Supported Services

Media Player Entity

Options

Variables Type Default Description Expected Payload Example
name string required Name for the entity string "Musicbee"
song_title template optional Value for the song title string * see configuration.yaml ex.
song_artist template optional Value for the song artist string * see configuration.yaml ex.
song_album template optional Value for the song album string * see configuration.yaml ex.
song_volume template optional Value for the player volume int (0 to 100) * see configuration.yaml ex.
album_art string optional Topic to listen to for the song album art (Must be a base64 encoded string) string (base64 encoded url) "musicbee/albumart"
player_status template optional Value for the player status string * see configuration.yaml ex.
vol_down* service call optional MQTT service to call for the media_player.volume_down command N/A * see configuration.yaml ex.
vol_up* service call optional MQTT service to call for the media_player.volume_up command N/A * see configuration.yaml ex.
volume service call optional MQTT service to call for the media_player.volume_set command string * see configuration.yaml
status_keyword* string optional Keyword used to indicate your MQTT enabled player is currently playing a song string "true"
next service call optional MQTT service to call when the "next" button is pressed N/A * see configuration.yaml ex.
previous service call optional MQTT service to call when the "previous" button is pressed N/A * see configuration.yaml ex.
play service call optional MQTT service to call when the "play" button is pressed N/A * see configuration.yaml ex.
pause service call optional MQTT service to call when the "pause" button is pressed N/A * see configuration.yaml ex.

*NOTES:

Example configuration.yaml

media_player:  
  - platform: mqtt-mediaplayer
    name: "Musicbee"
    topic:
      song_title: "{{ states('sensor.musicbee_nowplaying_songtitle') }}"
      song_artist: "{{ states('sensor.musicbee_nowplaying_artist') }}"
      song_album: "{{ states('sensor.musicbee_nowplaying_album') }}"
      song_volume: "{{ states('sensor.musicbee_nowplaying_playervolume') }}"
      player_status: "{{ states('sensor.musicbee_playingstatus') }}"
      album_art: "musicbee/albumart"
      volume:
        service: mqtt.publish
        data:
          topic: "musicbee/command"
          payload: "{\"command\":\"volume_set\", \"args\":{\"volume\":\"{{volume}}\"}}"
    status_keyword: "true"
    next:
      service: mqtt.publish
      data:
        topic: "musicbee/command"
        payload: "{\"command\": \"next\"}"
    previous:
      service: mqtt.publish
      data:
        topic: "musicbee/command"
        payload: "{\"command\": \"previous\"}"
    play:
      service: mqtt.publish
      data:
        topic: "musicbee/command"
        payload: "{\"command\": \"play\"}"
    pause:
      service: mqtt.publish
      data:
        topic: "musicbee/command"
        payload: "{\"command\": \"pause\"}"

Example MQTT Broker

This is what my player outputs and what I see when I use MQTT Explorer

musicbee
    playing = true
    songtitle = Repeat After Me (Interlude)
    artist = The Weeknd
    volume = 86
    album = After Hours
    command = {"command": "next"}
    albumart = /9j/4AAQSkZJRgABAQEASABI ...