No media_position update

Hi,

i would like to use the media_position when a video is playing and turn on lights when the video is about 90% finished. But the media_positon from media_player is only be update at the start of the video or when i pause and play the video. Is there a way to update the media_positon continuously, for example every 10 seconds, as long as a film is playing? Unfortunately I did not find a function for this.

I use the media_player with Plex.

thx
x-dast

This is actually by design. The media_position and media_position_updated_at are used by the frontend to calculate the current play position. Those attributes are throttled by the backend so the position doesn’t need to be written continuously to the entity (and therefore to the recorder/database). If the player continues to play without pausing or skipping then they don’t need to be updated.

You could use a template that calculated the current play position based on those two values and the current time. Not super trivial, but definitely possible. I’m sure someone is doing that already and can hopefully share.

That’s too bad. In a previous version of Home Assistant this still worked and the media_position was updated automatically. Why was this removed?

Because that was the incorrect way and was considered a bug. If it updated the attribute every time the progress advanced, it would send a huge number of unnecessary updates through the state machine and fill up the recorder database. The frontend knows how to calculate the progress using these two values and it’s also possible using a template.

Problem is there are corner cases and bugs where it really makes sense to be able to force the access of an updated timestamp. Eg, Simplify media player media position attribute · Issue #101 · home-assistant/architecture · GitHub

That’s not a bug for me. It is more of an undesirable behavior. A special case. So why not create a special rule inside the HA core for the recorder that excludes the “media_position” attribute from the recorder?

btw. owntone server shows position and get updates 3-5x /s. no problem. excluded from recorder

As already written, you could generally exclude “media_position” from the recorder in the HA core.
That, or you create the same behavior for all media integration and have consistency in the system.
But please don’t Plex has no media_position and other integrations like owntone do.