Lovelace: Mini Media Player

Some of them are default.

You can use the cards built in icon: option to specify any of the available icons from materialdesignicons.com.

- entity: media_player.google_home
  type: "custom:mini-media-player"
  icon: mdi:google-home

Alternatively you could customize the entity icon through the built in Home Assistant customization, and it will
be applied everywhere.

Yep! Good thinking.

I will try and check all my Sonos players when I get onto my desktop next and confirm, I’ve got half a dozen so we should get a good mix.

Let me know if I can do anything to help!

1 Like

Interestingly the media last position updated time/date seems to update on some players even when they haven’t been used, not sure if it could have been to do with a software update though, haven’t put music on in the master bed for weeks.

Here are all my media players - majority I used yesterday,

media_player.master_bed (seporate) - not used for weeks
state: paused
volume_level: 0.17
is_volume_muted: false media_content_type: music media_duration: 0 media_position: 0
media_position_updated_at: 2018-10-28T10:10:06.552717+00:00
media_title:
media_artist:

deck (separate) used yesterday afternoon
state: paused
volume_level: 0.49
is_volume_muted: false
media_content_type: music
media_duration: 129
media_position: 0
media_position_updated_at: 2018-10-28T06:22:10.630788+00:100:

bathroom: (separate) used yesterday
state: paused
volume_level: 0.25
is_volume_muted: false
media_content_type: music
media_duration: 295
media_position: 165
media_position_updated_at: 2018-10-28T01:30:42.263545+00:00
media_title: Hive - Ultrasonic Sound

kitchen (grouped with study) used yesterday evening
state: paused
volume_level: 0.38
is_volume_muted: false
media_content_type: music
media_duration: 320
media_position: 37
media_position_updated_at: 2018-10-28T08:13:57.586234+00:00

study: (grouped with kitchen)
state: paused
volume_level: 0.05
is_volume_muted: true
media_content_type: music
media_duration: 320
media_position: 37
media_position_updated_at: 2018-10-28T08:13:57.586234+00:00

Thank you sm for the data!

I added an option to “consider the player off” after x amount of time since media_position_updated_at.

I could only try this out with my Chromecasts and mock-up data but it seems to work.
However I saw that media_position_updated_at sometimes wouldn’t update frequently even during playback. However this shouldn’t be an issue if “x amount of time” is set to at least 5 minutes or something.

And then there’s the disadvantage of not being able to resume the playback from the card again if it’s considered off.

Sorry if this was confusing :smile:

Would be great if you could try this out with your Sonos for a few days.

  • You can grab the updated mini-media-player.js code here. replace your existing

  • Change your card reference to something like this (make sure the url path is correct)

    - url: /local/mini-media-player.js?v=0.8.9-beta
      type: module
    
  • Add the new option consider_off_after: x to your cards yaml, where x equals amount of minutes since media_position_updated_at

    - type: "custom:mini-media-player"
      consider_off_after: 10
      ...
    

    ``
    If you have any questions/feedback/suggestions, please let me know!

Updated from a very old version and now I get this error message in chrome:

http://localhost:8123/local/mini-media-player.js:348:51 Uncaught SyntaxError: Unexpected token :
22:06 components/system_log/__init__.py (ERROR)

And this very fancy red error message:

Custom element doesn't exist: mini-media-player.

{
  "type": "custom:mini-media-player",
  "entity": "media_player.onkyo_txnr676e"
}

Strange, double check the file, compare it to the source and make sure everything looks alright.

Did you try restarting HA and clearing the browser cache?

@kalkih @Stewface
I have made some changes to the css part of the js file so the player looks like this when state is paused.

Screenshot_6

The only button that works in this case is the Play button.
Just suggesting this as an option :grinning:
This way you also know which music is going to start playing when you hit the Play button :wink:

1 Like

@kalkih - fantastic effort here! I will get that new code rolled out now and give it a test.

@gerard33 nice work :slight_smile: Good idea to soften the look of the players that are paused

Great work.

I’m not sure if I’m doing something wrong, or if this is an unintended use case, but this card doesn’t play nice with the entity-filter card. I’m trying to only show the card when something is actually playing, as I have several media players and things get cluttered quickly.

Here’s my config:

  - type: entity-filter
    entities:
      - media_player.livingroom_directv
    state_filter:
      - playing
    show_empty: false
    card:
      type: custom:mini-media-player
      entity: media_player.livingroom_directv
      icon: mdi:google-home
      group: true
      artwork: cover

And here are the errors I’m getting:

https://XXXXX/local/resources/cards/mini-media-player.js?v=1:2:8 Uncaught SyntaxError: Unexpected token {
6:27 PM components/system_log/__init__.py (ERROR)

https:// https://XXXXX/local/resources/cards/mini-media-player.js?v=1:2:8 Uncaught SyntaxError: Unexpected token {
6:27 PM components/system_log/__init__.py (ERROR)

https://XXXXX/local/resources/cards/mini-media-player.js?v=1:2:8 Uncaught SyntaxError: Unexpected token {
6:26 PM components/system_log/__init__.py (ERROR)

https://XXXXX/local/resources/cards/mini-media-player.js?v=1:2:8 Uncaught SyntaxError: Unexpected token {
6:26 PM components/system_log/__init__.py (ERROR)

https://XXXXX/local/resources/cards/mini-media-player.js?v=1:88:15 Uncaught TypeError: Cannot read property 'addEventListener' of null
6:25 PM components/system_log/__init__.py (ERROR)

https://XXXXX/local/resources/cards/mini-media-player.js?v=1:88:15 Uncaught TypeError: Cannot read property 'addEventListener' of null
6:24 PM components/system_log/__init__.py (ERROR)

https://XXXXX/local/resources/cards/mini-media-player.js?v=1:88:15 Uncaught TypeError: Cannot read property 'addEventListener' of null
6:24 PM components/system_log/__init__.py (ERROR)

https://XXXXX/local/resources/cards/mini-media-player.js?v=1:88:15 Uncaught TypeError: Cannot read property 'addEventListener' of null/local/resources/cards/mini-media-player.js?v=1:2:8 Uncaught SyntaxError: Unexpected token {
6:26 PM components/system_log/__init__.py (ERROR)

https://XXXXX/local/resources/cards/mini-media-player.js?v=1:2:8 Uncaught SyntaxError: Unexpected token {
6:26 PM components/system_log/__init__.py (ERROR)
https://XXXXX/local/resources/cards/mini-media-player.js?v=1:88:15 Uncaught TypeError: Cannot read property 'addEventListener' of null
6:25 PM components/system_log/__init__.py (ERROR)

https://XXXXX/local/resources/cards/mini-media-player.js?v=1:88:15 Uncaught TypeError: Cannot read property 'addEventListener' of null
6:24 PM components/system_log/__init__.py (ERROR)

https://XXXXX/local/resources/cards/mini-media-player.js?v=1:88:15 Uncaught TypeError: Cannot read property 'addEventListener' of null
6:24 PM components/system_log/__init__.py (ERROR)

Any suggestions?

Not sure if I did something wrong but looks like I broke all the media players :expressionless:

updated the code, updated lovelace ui, forced refresh
 wait

I didn’t reboot HASS, looks like they disappeared from the the default dashboard too!

Looks like a restart did the trick :slight_smile:

This improvement is amazing :slight_smile:

I think though @gerard33 is really onto something - my next wishlist for improvements would be for when its goes into off mode:

  • include play icon so you can restart it (move next to down arrow to show sources if at all possible) or replace the icon with a play button
  • show the previous track that was playing in a softer grey - highlight further its ‘not active’
  • hide volume control and track buttons

Working thus far :slight_smile: Getting more closer and closer to moving away from the sonos app - the next challange is how to group / ungroup rooms in the hass front end.

Here is how it looks in the stand alone player.

Although the power button doesn’t seem to function for a sonos, we might need an option to just swap that for a play icon. :slight_smile: Then just add the current track name underneath the media player name and it would be perfect!

Sensational work on this update! Now my front end wont be flooded with all my media players!

1 Like

Are you going to push this 0.8.9-beta out? My custom updater shows 0.8.8 still as the latest?

@kalkih Home Assistant Core needs a new Media Player. Have you though about contributing this to the core? You did a hella nice job on the sensor card. Like to see more of your work on the core features

1 Like

+1 for adding this to the HA core

@kalkih - actually, turns out the power button does work for one of my players. not sure why it doesn’t work for another one. (bathroom didn’t work, but family room did)

I am guessing if we just add the power button to the view when you have multiple players grouped that would avoid having to change it to much as it just expands from there


e.g.

1 Like

I can only use the card to turn my TV off as it doesn’t support LAN control for turning on
 maybe that’s your bathroom issue?

It’s a sonos player so it supports remote turn on (it never really turns off I suspect)

What TV do you have? My Sony had a setting hiding that allows for wake on lan (it had some obscure name) but it fixed the problem you are having.

Samsung
 it’s documented you can’t use the app to turn it on. It’s a bit old now
 longer than 5 years I think


@gerard33 Nice solution, I think we could end up with something great if we combine our ideas.

@Stewface Thanks for the feedback. I love the points in your wishlist and they are certainly possible to implement, I’ll take a stab at it when I got time!

I won’t push betas to the tracker, the code there is really just for testing, and might not work as expected. If you want to try it you’ll have to update the card manually. :wink:

Thank you sm for your kind words. Possibly in the future, if people would like that, I still have some things I want to get done first though!

All Good. You could just get them done in core :stuck_out_tongue_winking_eye: but yea eventually man you have to put this developing power to the core.

1 Like