Last active
January 6, 2024 10:56
-
-
Save D34DC3N73R/e4d4d13c6fb26eed0002d99a1dd1b2eb to your computer and use it in GitHub Desktop.
This will add a progress bar to conditional media cards. Add progress_bar.yaml to button_card_templates directory. Add the lines from themes.yaml to themes.yaml. Add - progress_bar to conditional_media cards in ui-lovelace.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
progress_bar: | |
styles: | |
custom_fields: | |
progress: | |
- background-color: var(--progress-bar-background-color) | |
- position: absolute | |
- left: 0% | |
- top: 73.9% | |
- height: var(--progress-bar-height) | |
- width: 100% | |
bar: | |
- background-color: var(--progress-bar-color) | |
- position: absolute | |
- left: 0% | |
- top: 73.9% | |
- height: var(--progress-bar-height) | |
- z-index: 1 | |
- transition: 1s ease-out | |
custom_fields: | |
bar: > | |
[[[ | |
if (entity.attributes.media_position !== undefined) { | |
setTimeout(() => { | |
let elt = this.shadowRoot, | |
card = elt.getElementById('card'), | |
container = elt.getElementById('container'), | |
bar = elt.getElementById('bar'); | |
if (elt && card && container && bar) { | |
card.insertBefore(bar, container); | |
function update() { | |
let mediaPositionUpdatedAt = entity.attributes.media_position_updated_at, | |
mediaPosition = entity.attributes.media_position, | |
mediaDuration = entity.attributes.media_duration, | |
mediaContentID = entity.attributes.media_content_id; | |
let percentage = entity.state === 'paused' | |
? (mediaPosition / mediaDuration * 100) | |
: entity.state === 'playing' | |
? (((Date.now() / 1000) - (new Date(mediaPositionUpdatedAt).getTime() / 1000) + mediaPosition) / mediaDuration * 100) | |
: 0; | |
percentage = Math.min(percentage, 100); | |
bar.style.width = percentage.toFixed(1) + '%'; | |
requestAnimationFrame(update); | |
} | |
requestAnimationFrame(update); | |
} | |
}, 0); | |
return ' ';} | |
]]] | |
progress: > | |
[[[ | |
if (entity.attributes.media_position !== undefined) { | |
setTimeout(() => { | |
let elt = this.shadowRoot, | |
card = elt.getElementById('card'), | |
container = elt.getElementById('container'), | |
progress = elt.getElementById('progress'); | |
if (elt && card && container && progress) { | |
card.insertBefore(progress, container); | |
} | |
}, 0); | |
return ' ';} | |
]]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
progress-bar-color: '#e5a00d' | |
progress-bar-background-color: rgba(0,0,0,0.33) | |
progress-bar-height: 2% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- type: conditional | |
conditions: | |
- entity: select.conditional_media | |
state: Shield TV | |
card: | |
type: custom:button-card | |
entity: media_player.shield_tv_plex | |
triggers_update: sensor.youtube_watching | |
template: | |
- conditional_media | |
- icon_shield_tv | |
- progress_bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment