it checks for png, jpg and jpeg in the media_content_id.
Unfortunately, the media_content_type is not visible in the attributes of the media_player, otherwise I could have used that. So it should work for all images with that file extension, regardless if they are local or from the internet.
It is also case sensitive now, I will make sure that is no longer the case.
Itâs there a way to add a timeout for resuming whatever action?
Like cast using dashcast or the dashboard for X seconds then resume.
Ok it seems to work using lovelace cast with two separate scripts.
First script: cast.show_lovelace_view, timeout e.g. 30 seconds, media_player.turn_off
Second script: call script.google_home_resume with first script as action.
Thatâs great.
Also: original spotcast branch seems to be fixed as I use it just fine.
If you are using Spotify and it looks like doesnât work randomly, might be due to the 1 minute pooling (update) time of the core module. Hereâs a quick fix.
I just did a check, and casting a dashboard (guess that service needs to be renamed as lovelace is no longer used) actually shows the device as playing.
It also clearly shows it is casting a dashboard in the attributes
That means I can build in support natively rather easily, and also support it within the automation automatically.
Will see if I can find some time to make version 2.9.0
BTW I use homeassistant.update_entity on the entities in the Spotify integration before saving their states, so the low polling rate is not an issue for the script.
I found it unresponsive, for a reason, on Nest Hub 2nd when the pooling rate was default, 1 minute for Spotify.
Maybe it is from the updates on Spotcast and something in Spotify API or from my configuration.
Whatever, it is good to know thereâs alternatives.
If I understand correctly, lines between 658-688 are used to restore volume level back if it is changed.
The problem is that when you want to use the script standalone, without automation, and call other script using it, it will add delay if nothing is already playing (e.g. state idle or off) on the media player. It also shows you the Home Assistant standard image when you turn_on on a display device, like Nest Hub, which is kind of not elegant.
Commenting these lines for scripts âTurn non playing entities on if neededâ and âAdd volume for players which were offâ seems to âfixâ this, but it will not update the volume of idle players.
Two others solutions would be: add condition to check if you need to actually resume something and run resume or standard version in according. Turn on the player (e.g. Google Nest Hub) before running the resume script, that way you, at least, customize the image.
Only those entities which are targeted are turned on, so the screen should be overwritten by the service call issued in triggering the script.
Adding a condition if resume is needed is a bit pointless, as the player would be on then, and the volume would be known. I could check if a media_player.set_volume service call is used, but I have no way of knowing that when another script is used.
We actually would not have this problem if the media_players would not turn off, but stayed idle, as they did shortly in April this year (from versions 2022.4.0 to 2022.4.3)
Resume after casting a dashboard is now also supported. A separate variable is also provided for the delay after which the resume should start has also been added. Default delay if ommitted is 20 seconds. A trigger has been added to the automation (v0.2.0) as well, so it is resumed automatically. Remove this trigger if you donât want automatic resume when casting a dashboard.
Bug fixes
Updated automation to v0.2.0 to include volume of idle cast entities
Donât try to restore the volume when it is not provided in the player data
Not sure if I have missed something, but my Spotify resume is still not working. I have updated this script and updated spotcast, but it still doesnât resume.
You can test it faster by modifying ...homeassistant/components/spotify/media_player.pySCAN_INTERVAL = timedelta(minutes=1) to SCAN_INTERVAL = timedelta(seconds=5) then restart HA.
Just did a quick test, and Spotify resume works fine here, without the changes suggested by @addy2022 (which should not be needed, as the Spotify entities by the script before data is stored)
(line 303 - 309)
- alias: "Update Spotify data if there are Spotify entities"
if: "{{ spotify_entities | count > 0 }}"
then:
- alias: "Update Spotify entities"
service: homeassistant.update_entity
target:
entity_id: "{{ spotify_entities }}"
If you can send me the traces of the script, I can have a look.
Using the steps you sent for the faster Spotify updates, I was able to make the cast devices remain idle in my own setup.
Basically you need to change 2 lines in media_player.py from the cast component. I already did this several times, but it is overwritten every time you update HA (and I usually keep up with every update as soon as it is available).
So the alternative is to run cast as a custom component, but that breaks spotcast
The solution was in your link, I had to refer spotcast to the custom cast component instead of the built in one.
Edit media_player.py in the cast folder
(line numbers can differ after changes to the cast component)
Line 52: Remove this line (contents are STATE_OFF,)
Line 797: Change return STATE_OFF to return STATE_IDLE
Change the helpers.py file in the custom_components/spotcast folder. The link you provided uses a relative import, like ..cast.media_player, when I posted this solution on the spotcast Github in the issue I created there, I was told relative imports should be avoided.
Change:
from homeassistant.components.cast.media_player import CastDevice
        to
from custom_components.cast.media_player import CastDevice
If you do this, you do need to make sure you keep the custom component up to date, so keep track of the changes to the cast component, and make the changes in the helper.py after updating spotcast
Well, that is exactly what that template in the automation does, however, it returned an empty list ([]) in the trace you sent.
Could you try updating the automation to the latest version (0.2.0) and see if that helps?
Oh wait, I think I understand what is going wrong.
How did you issue this TTS command? Did you use it as an action in the service call for the script? In that case this is indeed the expected result from the automation, and then I need the trace of the script, not the automation.