Can someone point me in the right direction to add a line of code in my custom app to pull what is currently playing (title & artist) from media_player (sonos)?
I just can’t seem to figure it out and google has not helped me either.
Can someone point me in the right direction to add a line of code in my custom app to pull what is currently playing (title & artist) from media_player (sonos)?
I just can’t seem to figure it out and google has not helped me either.
I don’t have a sonos but shouldn’t it just be get_state and then look for the attributes?
The attributes don’t include the title and artist in get_state (unless I’m doing something wrong).
Shouldn’t be an issue - what version of AD are you running?
I do:
self.log(self.get_state("media_player.living_room", attribute="all"))
And get:
{'attributes': {'media_album_name': 'Electric Ladyland', 'entity_picture': '/api/media_player_proxy/media_player.living_room?token=aee9677961c8669398c241c364bb1e010ee5dc49b28f512769d5cfba35e1012a&cache=4361560a602a682e', 'is_volume_muted': False, 'media_duration': 241, 'supported_features': 64015, 'media_content_type': 'music', 'media_artist': 'Jimi Hendrix', 'volume_level': 0.35, 'media_position': 2, 'media_position_updated_at': '2018-02-14T21:47:15.033667+00:00', 'media_title': 'All Along the Watchtower', 'is_coordinator': True, 'source_list': ['Pink Floyd Radio'], 'media_content_id': 'All Along the Watchtower', 'friendly_name': 'Living Room', 'shuffle': False}, 'last_changed': '2018-02-14T21:47:56.548916+00:00', 'state': 'paused', 'entity_id': 'media_player.living_room', 'last_updated': '2018-02-14T21:47:56.548916+00:00'}
So for instance:
state = self.get_state("media_player.living_room", attribute="all")
title = state["attributes"]["media_album_name"]
artist = state["attributes"]["media_artist"]
2.1.12.
Will try what you have above again…I thought I did that…