Skip to content

Feature: Media is playing sensor #309

@ydyote

Description

@ydyote

Please make sure that the feature you'd like to request is not already requested :)

I looked it up, didn't find anything also when media is enabled then it doesn't show this kind of sensor


Is your feature request related to a problem? Please describe.

The problem would be that to be able to determine whether user of a pc is "active" the "lastactive" sensor is not enough, this sensor would be addition to that and combining "lastactive", "monitorpowerstate", "mediaisplaying" might be enough to be able to tell whether the pc is in use or not except some unique cases, but if I get to those then I will deal with those


Describe the solution you'd like

A sensor which shows true/false based on whether media is playing or not. It should not report more stuff so privacy of the user is ensured (or the sensor should be configurable)


Describe alternatives you've considered

Alternative solution would be writing it myself and create sensor which would call it via cmd


Additional context

This is a short example of C# code which seems to work if you build it for windows with .net8 to retrieve the playing state and other info, this can be adjusted and then used to determine whether media is playing or not

using Windows.Media.Control;

namespace HassSensorTest
{
    internal class GlobalSystemMediaTransportControlsTest
    {
        static async Task Main(string[] args)
        {
            var sessions = await GlobalSystemMediaTransportControlsSessionManager.RequestAsync();
            var currentSession = sessions.GetCurrentSession();

            if (currentSession == null)
            {
                Console.WriteLine("No media session is currently active.");
                return;
            }

            var mediaProperties = await currentSession.TryGetMediaPropertiesAsync();
            var playbackInfo = currentSession.GetPlaybackInfo();

            Console.WriteLine("App: " + currentSession.SourceAppUserModelId);
            Console.WriteLine("Title: " + mediaProperties.Title);
            Console.WriteLine("Artist: " + mediaProperties.Artist);
            Console.WriteLine("Album: " + mediaProperties.AlbumTitle);
            Console.WriteLine("Playback Status: " + playbackInfo.PlaybackStatus);
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions