I currently use an infrared repeater (broadlink), and I’ve programmed the button sequence, but it is very unreliable and depends on the TV’s responsiveness and current state, which sometimes differs.
Best would be to directly trigger spotify as an app. Is there a way to do this? Adding this as the sourcelist? I’ve added the TV from the integration page; it was auto detected.
Not that I’m aware of, I’m afraid. Had a similar use-case, but although the smart tvs do have APIs and some even have home assistant integrations I could not personally get them to work for things like selecting playlists and performing actions inside of the apps on the TV. All they seem to do is control the basic TV functions.
I eventually went with “alexa play spotify on hifi” where “hifi” is another muted echo connected to the amplifier or a bluetooth receiver. Then I use the phone to control.
I also use ollo69’s code to select sources. It works fine to select sources. However, Spotify is a special case:
Selecting the Spotify app from the drop-down list in the UI is no problem, but I wanted to select the Spotify app from a script and this turned out to be difficult:
The select source script returned with no error but didn’t work when I used Spotify or spotify as source name.
In German, the source is called “Spotify – Musik und Podcasts” in the UI. Something is special about the spaces and the dash.
The solution was to use the developer menu “states”. Here, the media player shows the sources as YAML.
The Spotify entry contains a backslash.
I copied this entry verbatim into the YAML for the service call, and it works.
Hope this helps other non-English users.
Thanks for the tip! Unfortunately I still cannot get it to work.
In the developer tools stats it says “Spotify\_– Musik und Podcasts” (including the quotation marks).
When I enter that verbatim into a service call I get “unknown error” and node red (where I want to use this) is complaining about “unsupported escape sequence”…
Do you have any other idea how to get this work?
The other integrations mentioned here didn’t work for me either.
Edit: My frustration got to the point where I simply changed my TV language to english which fixed it for me… still curious how to to select a source with a backslash in it.
Thanks to the advice of @hvb I got my automation to work.
However I also want to set the icon color depending on the state, but this Jinja2 template doesn’t work for me. It returns grey even so “Spotify” is the current source:
{{ is_state_attr("media_player.lg_tv", "source", "Spotify\_– Musik und Podcasts") | iif("#1DB954", "grey") }}
Has anybody a clue?
Edit:
Alright figured it out myself.
Turns out Jinja2 interprets source (“Spotify\_– Musik und Podcasts”) as Spotify – Musik und Podcasts with a Non-Breaking Space between “y” and the dash. See attached image.
Once I added this, the template renders as expected:
{{ is_state_attr("media_player.lg_tv", "source", "Spotify – Musik und Podcasts") | iif("#1DB954", "grey") }}