YouTube cast automation - get_lounge_token_batch error

Hello,

I have an automation that, at a time in the morning, starts casting a YouTube video to a Nest HUB. When I first set this up, it worked fine:

alias: Wake Up
description: ""
trigger:
  - platform: time
    at: "07:30:00"
condition: []
action:
  - data:
      media_content_type: cast
      media_content_id: " { \"app_name\": \"youtube\", \"media_id\": \"GOCWT8Ng0yo\" }"
      enqueue: play
    service: media_player.play_media
    target:
      device_id: 323a99912ae05ec9a79471e420b87103
  - service: media_player.volume_set
    data:
      volume_level: 0.4
    target:
      device_id: 323a99912ae05ec9a79471e420b87103
mode: single

Since then, I have updated HA to 2023.8, and migrated my HA to a new Pi 4 with a different IP address that it had previously.

Now the automation fails to automatically work.

In the logs Iā€™m getting:

Wake Up: Error executing script. Unexpected error for call_service at pos 1: 400 Client Error: Parameter missing. for url: https://www.youtube.com/api/lounge/pairing/get_lounge_token_batch

07:30:10 ā€“ (ERROR) Automation - message first occurred at 07:30:10 and shows up 2 times

Failed to update screen_id

07:30:10 ā€“ (WARNING) /usr/local/lib/python3.11/site-packages/pychromecast/controllers/youtube.py

The strange thing is if I manually run the automation / script it starts casting fine, itā€™s just when left to run automatically itā€™s failing.

Any ideas?

1 Like

Check the release note, there is a breaking change for Nest.

see full release Full Changelog for Home Assistant Core 2023.8 - Home Assistant (home-assistant.io)

Iā€™ve had a look and can see mention that things have changed around Nest, but as a newbie to HA, Iā€™m none the wiser as to what Iā€™m required to do to resolve any issue.

Donā€™t the logs suggest itā€™s more so a YouTube issue in some way?

From my understanding, itā€™s google removing API.
itā€™s mentioned Remove Legacy Works With Nest by allenporter Ā· Pull Request #96111 Ā· home-assistant/core Ā· GitHub
ā€œAdditionally, as a reminder, the Legacy Works With Nest API is being shut down in September 2023ā€

I donā€™t know what will replace and if there is something that will work. Personnaly, I found that Nest hub a bit weird. Apart ask something to google and reply, those products are not giving me a lot of possibilities.

No, that integration is for different nest products not a nest hub. This is not related to legacy nest integration

Is this using a custom component? It may need to be updated from a change to services in 2023.07. I am assuming you updated past multiple versions.

@allenporter
oh okay. Itā€™s confusingā€¦ I know only 2 products with ā€œNestā€, itā€™s Nest Audio or Nest Hub.
Thanks to highlight that.

So what does it mean for our Nest Hub concretely, nothing change ?

See Google Nest - Home Assistant to see the products this integration supports. Nothing changed here related to nest hub.

Iā€™m not sure what you mean by a custom component. The automation was built using HAā€™s standard interface of triggers and actions (and then changing the YAML to cast YouTube as described here ).

The actions used are ā€˜call a serviceā€™ which use media_player.play_media which are native to HA is my understanding.

I tried some small tests and basic cast is ok (cast local camera) but even by using multimedia tab, choose spotify to Google TV or Nest Hub, nothing is played.

Cast radio available in multimedia work just fine.

If I open spotify app and cast to those devices, itā€™s OK.

So for me, itā€™s not your automation. I also test using dev tool - service play media . I didnā€™t have a chance to play something from youtube

This gets a bit stranger.

Last night I created a brand-new automation, and throughout the evening I changed its trigger to test at different times. It worked fine and would kick in automatically, casting YouTube to the device.

Thinking everything was working fine, I then set itā€™s time for 07:30 for this morning.

The script triggered, but no YouTube cast started on the device.

Looking at the trace this is shown:

I have no idea what get_lounge_token_batch is but it seems to be the common error on all failed attempts.

Doing a bit of digging around the 'ol internet I get the sense this might be due to YouTube lounge tokens expiring and needing to be refreshed. But I could be wrong. I know nothing about this topic.

via developper tool, you can trigger the service without need of the automation.

I tried this but I canā€™t have the youtube video started on the Nest Hub even from accesing HA via https. Iā€™m still searching.

service: media_player.play_media
data:
  media_content_id: video_url=https://www.youtube.com/watch?v=iwT42Gi0pis
  media_content_type: video/youtube
target:
  entity_id: media_player.nest

Ok I follow the google cast integration and it works in dev tools like in this example below

service: media_player.play_media
data:
  media_content_id: '{"app_name": "youtube", "media_id": "iwT42Gi0pis" }'
  media_content_type: cast
target:
  entity_id: media_player.yournest

Just to update that Iā€™ve had no joy resolving this.

My super low-tech idea for a solution was that if itā€™s a refresh issue, that Iā€™d make two automations with a minute between them. So the first one would fire (and fail, but hopefully refresh any API / tokens), and the second one would then kick in:

However, they consistently both fail in the same way:

What I fundamentally donā€™t understand is if I manually run / force the automation, they work fine. Thereā€™s something about the inclusion of the automatic time trigger, which when used means they donā€™t work.

I donā€™t understand why that would make a difference, but thatā€™s what Iā€™m experiencing.

I am having the exact same issue. Automation worked. I changed to .8 and started getting the failure to get lounge token or missing api parameter error.

Any one have any ideas?

Sorry that I donā€™t have any solution to offer, but I am glad Iā€™m not the only one experiencing this. Points to a broader issue.

Iā€™m going to report it as a bug.

SO it gets stranger:

If I run this script (where Iā€™ve hardcoded the media and play list

alias: Youtube Hardcode_kidrock
sequence:
  - service: media_player.play_media
    target:
      entity_id: media_player.wcast_tv
    data:
      media_content_id: >-
        {"app_name": "youtube", "playlist_id":
        "PLJ2hx9Xyf-QpN0qhaLJjaiMKgz2kyBM2x", "media_id": "MOWDb2TBYDg"}
      media_content_type: cast
mode: single

Everything works.

If I call that script from another script and pass the playlist_id and media_ id I get the failure to get lounge token

Iā€™m having the issue also, it produces the ā€˜token batchā€™ error and also ā€˜unknown errorā€™. If an automation includes any media casting it doesnā€™t work. This includes both the cast and url methods.

I see a GitHub issue raised but no activity yet.

Iā€™m still plagued with issues. I have scripts that repeat a cast or url command several times, and sometimes they work. But mostly not. Anyone else?