项目作者: TroyFernandes

项目描述 :
Fill out your Media Player Entity with MQTT Topics
高级语言: Python
项目地址: git://github.com/TroyFernandes/hass-mqtt-mediaplayer.git
创建时间: 2020-09-15T04:37:47Z
项目社区:https://github.com/TroyFernandes/hass-mqtt-mediaplayer

开源协议:MIT License

下载


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

  • volume_up
  • volume_down
  • volume_set
  • media_play_pause
  • media_play
  • media_pause
  • media_next_track
  • media_previous_track

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:

  • volume: put your custom payload here and replace where your value would be with "{{volume}}" (see config ex.)
  • status_keyword: This is the keyword your player publishes when it is PLAYING. You only need to mention the keyword for playing. For example, my player indicates it is playing by publishing playing = true to my broker. Therefore I enter "true" in my configuration.yaml
  • vol_up/vol_down: Setting this disables the volume_set service. Use vol_up/vol_down if your media player doesn’t publish a volume level (i.e if your media player only responds to simple “volumeup”/“volumedown” commands. If you use the “volume” topic you DONT need to use vol_up/vol_down. Same for the reverse

Example configuration.yaml

  1. media_player:
  2. - platform: mqtt-mediaplayer
  3. name: "Musicbee"
  4. topic:
  5. song_title: "{{ states('sensor.musicbee_nowplaying_songtitle') }}"
  6. song_artist: "{{ states('sensor.musicbee_nowplaying_artist') }}"
  7. song_album: "{{ states('sensor.musicbee_nowplaying_album') }}"
  8. song_volume: "{{ states('sensor.musicbee_nowplaying_playervolume') }}"
  9. player_status: "{{ states('sensor.musicbee_playingstatus') }}"
  10. album_art: "musicbee/albumart"
  11. volume:
  12. service: mqtt.publish
  13. data:
  14. topic: "musicbee/command"
  15. payload: "{\"command\":\"volume_set\", \"args\":{\"volume\":\"{{volume}}\"}}"
  16. status_keyword: "true"
  17. next:
  18. service: mqtt.publish
  19. data:
  20. topic: "musicbee/command"
  21. payload: "{\"command\": \"next\"}"
  22. previous:
  23. service: mqtt.publish
  24. data:
  25. topic: "musicbee/command"
  26. payload: "{\"command\": \"previous\"}"
  27. play:
  28. service: mqtt.publish
  29. data:
  30. topic: "musicbee/command"
  31. payload: "{\"command\": \"play\"}"
  32. pause:
  33. service: mqtt.publish
  34. data:
  35. topic: "musicbee/command"
  36. payload: "{\"command\": \"pause\"}"

Example MQTT Broker

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

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