├── .gitattributes ├── nowplaying.jpg ├── Design Tool ├── back.jpg ├── echo.png ├── kodi.png ├── roku.png ├── works best in chrome or firefox.txt └── rotate.html ├── now-playing-card.js └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /nowplaying.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradcrc/now-playing-card/HEAD/nowplaying.jpg -------------------------------------------------------------------------------- /Design Tool/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradcrc/now-playing-card/HEAD/Design Tool/back.jpg -------------------------------------------------------------------------------- /Design Tool/echo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradcrc/now-playing-card/HEAD/Design Tool/echo.png -------------------------------------------------------------------------------- /Design Tool/kodi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradcrc/now-playing-card/HEAD/Design Tool/kodi.png -------------------------------------------------------------------------------- /Design Tool/roku.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bradcrc/now-playing-card/HEAD/Design Tool/roku.png -------------------------------------------------------------------------------- /Design Tool/works best in chrome or firefox.txt: -------------------------------------------------------------------------------- 1 | this tool works best in chrome or firefox. 2 | 3 | Other browsers may not work as well or at all due to funky css incompatibilities. -------------------------------------------------------------------------------- /now-playing-card.js: -------------------------------------------------------------------------------- 1 | class NowPlayingPoster extends HTMLElement { 2 | set hass(hass) { 3 | if (!this.content) { 4 | const card = document.createElement('ha-card'); 5 | this.content = document.createElement('div'); 6 | 7 | 8 | //this.content.style = "!important;"; 9 | 10 | 11 | card.appendChild(this.content); 12 | card.style = "background: none;"; 13 | this.appendChild(card); 14 | 15 | 16 | } 17 | 18 | const offposter = this.config.off_image; 19 | const entityId = this.config.entity; 20 | const state = hass.states[entityId]; 21 | const stateStr = state ? state.state : 'unavailable'; 22 | 23 | 24 | 25 | if (state) { 26 | 27 | const movposter = state.attributes.entity_picture; 28 | 29 | if (["playing", "on"].indexOf(stateStr) > -1 ) { 30 | if ( !movposter ) { 31 | if ( offposter ) { 32 | this.content.innerHTML = ` 33 | 34 | 35 | `; 36 | } 37 | else 38 | { 39 | this.content.innerHTML = ` 40 | 41 | `; 42 | } 43 | } 44 | else 45 | { 46 | const img = new Image(); 47 | img.onload = () => { 48 | this.content.innerHTML = ` 49 | 50 | 51 | `; 52 | }; 53 | img['src']= movposter 54 | } 55 | } 56 | else 57 | { 58 | 59 | if ( offposter ) { 60 | this.content.innerHTML = ` 61 | 62 | 63 | `; 64 | } 65 | else 66 | { 67 | this.content.innerHTML = ` 68 | 69 | `; 70 | } 71 | 72 | } 73 | 74 | 75 | } 76 | else 77 | { 78 | 79 | 80 | this.content.innerHTML = ` 81 | 82 | `; 83 | 84 | } 85 | 86 | } 87 | 88 | 89 | 90 | 91 | setConfig(config) { 92 | if (!config.entity) { 93 | throw new Error('You need to define an entity'); 94 | } 95 | this.config = config; 96 | } 97 | 98 | 99 | // The height of your card. Home Assistant uses this to automatically 100 | // distribute all cards over the available columns. 101 | getCardSize() { 102 | return 3; 103 | } 104 | } 105 | 106 | customElements.define('now-playing-poster', NowPlayingPoster); 107 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![title](nowplaying.jpg) 2 | # now-playing-card 3 | 4 | 5 | Custom card for [Home Assistant](https://www.home-assistant.io/) to display a poster of the currently playing item in designated media_player. 6 | 7 | #### Demo: [Youtube video](https://youtu.be/1ZU4WMgwU6s) 8 | 9 | This works with those media_player entities supporting the entity_picture attribute. Roku, Kodi, and Amazon Echo Dot all seem to work well for me. 10 | 11 | The card is stackable, so you can position cards from several media players in the same spot to show whichever one is playing. 12 | 13 | The card only shows the entity_picture while the status is playing. This is because some roku players and echo dots will show images even when not actively playing media content. It should be easy to edit this function out if you don't want it. 14 | 15 | #### Known issues: 16 | Transform is highly dependent on the image size, so if you attempt to display an image of a different size (this can happen in kodi) the transform will not work correctly and the image will look weird or in the wrong place. 17 | 18 | If you use an old browser that doesn't display transform css properly, transform just won't work. 19 | 20 | ------------ 21 | 22 | #### entity 23 | (string)(Required) 24 | 25 | Entity id 26 | 27 |   28 | 29 | 30 | #### off_image 31 | (string)(optional) 32 | 33 | Optional Image to display when idle. This must be the same size as the media image if using transform. 34 | 35 | 36 | 37 | 38 | ------------ 39 | 40 | ## Example Usage 41 | 42 | 43 | - type: "custom:now-playing-poster" 44 | entity: media_player.dot_lr 45 | style: 46 | width: 10% 47 | top: 20% 48 | left: 9% 49 | transform: rotate(-76deg) rotateX(-57deg) skewX(-25deg) 50 | 51 | 52 | 53 | 54 | 55 | 56 | # Installation 57 | 58 | Installation is the same as any custom card. 59 | 60 | 1. Copy the file [now-playing-card.js](https://github.com/bradcrc/Now-Playing-Card) to your /config/www/js/ directory 61 | 62 | 2. Add the following to the resources area of your ui-lovelace.yaml (or add to resources on the lovelace dashboard) 63 | 64 | 65 | - url: /local/js/now-playing-card.js 66 | type: module 67 | 68 | 69 | 70 | Once the card is copied and referenced, you can just add the entry as listed above. 71 | 72 | Most likely you'll also want to move the image around your floorplan. This can be accomplished with CSS. A tool has been included to help figure out the skew and rotate values, it's not necessary to use this tool, but hopefully it makes things easier. To use the tool just open rotate.html from the Design Tool folder, and then copy your floorplan image and media image to the folder, or enter a valid URL for those images. 73 | -------------------------------------------------------------------------------- /Design Tool/rotate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | CSS Generator Tool 4 | 5 | 6 | 7 | 8 | 76 | 77 | 78 | 146 | 147 | 148 | 149 | 150 | 151 | 154 |
152 |
153 |
155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 |
164 |
165 | 166 | 167 |
👉
168 |

169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 |
adjust
Width: %
Top: %
Left: %
Rotate:
Rotate X:
Rotate Y:
Skew X:
Skew Y:
180 |

181 | 182 | 183 | 184 | 185 |
images
Test image:
Background:
186 |

187 | 188 | 189 | 190 |
output
191 | 192 |

193 | 194 | 195 | 196 | 197 | 200 | 201 | 202 | --------------------------------------------------------------------------------