Right now, no. There is no good way of mapping the chromecast name with an internally generated entity_id for a media_player (I guess you mean the generated entitiy id from the built-in cast media_player)
I love this! Coffee on its way
@Pliind
So when ill add this, the script wont work. But the config says its okey. Got in the log that it was not able to find shuffle. For the formating here, just use four spaces.
script:
play_music_cc:
alias: Spela Spotify i Kƶk
sequence:
- service: spotcast.start
data:
device_name: "Kƶkshƶgtalare"
uri: āspotify:playlist:*********ā
- service: media_player.shuffle_set
data:
entity_id: media_player.spotify
shuffle: true
I presume you have the spotify module installed correctly? can you see the media_player.spotify entity in your list of States? also youāll need to activate (authenticate) it. If you enable discover you should see the card pop up for authentication. after that you are set.
also, as chromcast is pretty slow it wouldnt hurt to add a timeout between the 1st and 2nd step
In my case the Spotify entity controls are instant, When my bathroom light turns off it stops the music, and itās instant.
that is correct but he is trying to first start spotify on an idle chromecast device which takes time
@fondberg I will add a timeout to test.
@Pliind Its correct installed, i see the media_player.spotify and its activated.
True, but my setup works fine, if the shuffle didnt make its way to its destination spotcast would just start playing the first song in the playlist every time.
@catt00 Have you restarted your home-assistant also? sorry for trivial questions, sometimes the solution is super-silly
@Pliind A few times. But are you able to put your config on hastebin or something so i could take a peek at the lines? Looking at it to long makes one blind.
Sure, https://hastebin.com/upehopakud.bash
Do you also get errors when calling the service through the services tool?
I got an idea. Can you check that your friendly_name for the media_player.* (chromecasts) always matches an entry with attribute name
in my sensor sensor.chromecast_devices
?
My idea is that if this is true I can look for entity_id
if device_id
is missing and look up the name.
Yes it does. The attribute friendly_name is always the same. Im also currently trying to filter it in the python. Im stuck at getting only a specific attribute from the hass.states object.
so for example: media_player.tv
In the python i can get the full state via:
state = hass.states.get('media_player.tv')
From the documentation of the hass object it seems like the get
does not directly support attributes.
So i need to find a way to filter only the friendly_name attribute
A delay did the trick, thank you.
Got it Took a while, but it works perfectly now with the existing entity_id (provided the user didnt change the friendly_name manually just in HA).
I can now fire the service call with selecting the media_players that i already have from the cast component. I made a branch for this.
If you want i can make a merge request for you to check it out as well.
Nice! Please open a PR.
Doneā¦ im a complete noob to GITā¦ and accidentally opened also a pull request to the other Fork
But should now be in the correct one.
Would it be possible to add functionality to start at a random place in the playlist instead of the first song? I know I can use shuffle, but Iād really like to start of the playlist with a random song each time I kick it off.
What can I do if the Spotcast sensor doesnāt pick up any media players? Iāve got three Chromecasts (1 TV 2nd gen, 2 Audio) that show up in HASS as media players but not in the sensor. From my config:
spotcast:
username: !secret spotify_username
password: !secret spotify_password
From the debug log:
2019-05-18 21:14:11 INFO (SyncWorker_2) [homeassistant.loader] Loaded spotcast from custom_components.spotcast
2019-05-18 21:14:11 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for spotcast which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-05-18 21:14:21 INFO (MainThread) [homeassistant.components.media_player] Setting up media_player.spotify
2019-05-18 21:14:23 INFO (MainThread) [homeassistant.components.media_player] Setting up media_player.cast
2019-05-18 21:14:24 DEBUG (SyncWorker_4) [custom_components.spotcast.sensor] updating
2019-05-18 21:14:29 DEBUG (SyncWorker_4) [custom_components.spotcast.sensor] Found chromecast devices: []
I can call the script and the log says the service is starting but then I get a small error message saying Unable to start service spotcast/start. Could not find device with name Kƶksradion
despite Kƶksradion showing up as one of my media player (itās a CC Audio).
{
"device_name" : "Kƶksradion",
"uri" : "spotify:playlist:37i9dQZF1DX3yvAYDslnv8"
}
Iāve tried restarting HASS, Iāve tried with Koksradion instead of Kƶksradion but it makes no difference. The sensor doesnāt update even if I start casting from my phone, I would have thought that made the player announce itself on the network. The media_player entity however is correctly updated if I cast from my phone so that should be fine.
I want to keep this component to a bare minimum wrt to spotify integration. Reason is that we want this to be gone when HASS has a proper integration with spotify and starting a chromecast session can be done from the ānormalā spotify mediaplayer in core HASS.
That said, I think you can call the spotify mediaplayer with shuffle right after staring the session using this component? Check the entire thread because Iām pretty certain Iāve seen some automation examples