Cast and re-cast a lovelace view to a Google Hub

Tags: #<Tag:0x00007fc41bb9d048> #<Tag:0x00007fc41bb9cf08>

Small automation that casts a lovelace view to a Google Hub (or any Chromecast device for that mattter) when the hub is not playing anything. It re-casts the same view every 9 minutes to compensate for the fact that the hub automatically goes into picture frame mode after 10 min.

For this to function you need have the lovelace cast setup:

  1. Have HTTPS setup on your HA install
  2. Make sure you HA is accesible from the internet via HTTPS and also check in Configuration -> General (the external URL)
  3. Have the lovelace casting setup by authenticating on https://cast.home-assistant.io/

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

blueprint:
  name: Cast to Google Hub
  description: 'Cast a lovelace view to a Google Hub. 
    This tries to bypass the 10 min timeout for the picture frame
    by re-casting every 9 min'
  domain: automation
  input:
    player:
      name: Google Hub
      description: Google Hub or Chromecast device to cast to
      selector:
        entity:
          integration: cast
    view:
      name: Lovelace view path
      description: Path of the view to cast. A path has to be defined in your Lovelace YAML for each view, as outlined in the views documentation.
    dashboard:
      name: Lovelace dashboard
      description: Path to lovelace. Defaults to 'lovelace' if empty.
      default: 'lovelace'

trigger:
  - platform: state
    entity_id: !input 'player'
    to: 'off'
    for: 00:00:20
  - platform: state
    entity_id: !input 'player'
    to: paused
    for: 00:00:20
  - platform: time_pattern
    minutes: '/9'
  - platform: time_pattern
    minutes: '0'

action:
  - choose:
    - conditions:
      - condition: or
        conditions:
        - condition: state
          entity_id: !input 'player'
          state: 'off'
        - condition: state
          entity_id: !input 'player'
          state: 'paused'
          for: 00:00:20
      sequence:
        - service: media_player.volume_mute
          data:
            is_volume_muted: true
            entity_id: !input 'player'
        - service: media_player.turn_off
          data:
            entity_id: !input 'player'
        - delay:
            seconds: 2
        - service: media_player.turn_on
          data:
            entity_id: !input 'player'
        - service: cast.show_lovelace_view
          data:
            view_path: !input 'view'
            dashboard_path: !input 'dashboard'
            entity_id: !input 'player'
        - service: cast.show_lovelace_view
          data:
            view_path: !input 'view'
            dashboard_path: !input 'dashboard'
            entity_id: !input 'player'
        - delay:
            seconds: 10
        - service: media_player.volume_mute
          data:
            is_volume_muted: false
            entity_id: !input 'player'
14 Likes

After the latest update to the hub it seems to cast with dark theme. Anyone know how to change to light one ?

Thanks for sharing! Used the blueprint to create an automation (needed some tweaking for my conditions) but the base of it is per your blueprint. Its nice to get back to using the native cast function.

For the theme, do you have a separate view to be casted? I specified the theme for the view and its working nicely for me.

This blueprint works very well, casting my lovelace view.

But, on my Nest Hub Max, during a Google Duo call, it interrupts every 9 minutes setting volume to zero.

It doesn’t seem to recognize on going Duo calls?

What is the state of the media_player component during a duo call? Can you add a condition for that state?

Gotta do some investigation…

Should be as easy as adding another “or”-condition.

Indeed, but the blueprint only checks for off and paused states, all other states are treated as the hub is doing something else and won’t re-cast. So probably during duo calls it’s one of those. Or maybe the state during duo calls does not properly update in HA ?

I checked the state of media_player during a Duo call and it shows “off”. :frowning: Very sad.

Then maybe it’s better to file a bug on github so that the chromecast team can look into it, maybe there is an update sent but not processed by the integration.

This looks really cool, but I just get a black screen with the blue cast logo on my hub. I assume I have the path or dashboard fields wrong. Would anyone be able to share an example of what those fields should look like?

Make sure you have the right prerequisites for casting (HTTPS and authentication on the cast portal). You can manually test with service cast.show_lovelace_view to double check.

If your parameters were wrong you would still get an image with the HA and Nabu Casa logo and some error.

Thanks for all of that. Cast portal is logged in, but it does say “There were no suitable Chromecast devices to cast to found.”. Which is odd giving all the cast devices I have, plus I can ask Google assistant to stream cameras from HomeAssistant and that works.

I do have this error in the log “Failed to cast media https://www.home-assistant.io/images/cast/splash.png. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address”

Guess I have troubleshooting to do.

Can you cast any browser tab (or even desktop) from Chrome (the three dots menu -> Cast…) ? Is the Hub visible in the list of the HA Cast integration ?

Yeah, casting from chrome works fine. It does show in the information. I can cast TTS audio from HA to it too.

Then I guess your HA is not accessible from the internet via HTTPS. Or maybe the URL is not properly set. Check in Configuration -> General (the external URL).

You are good.
“Configuration -> General” was empty and said it was referenced in configuration.yaml.
I checked my configuration.yaml and it too was missing the external URL.
I put the external URL in there, rebooted, and now I at least get the white NABU CASA splash page when I cast.
I can’t believe that wasn’t in my config. Probably had other thing broke because of that.
Thanks for the help!

hi,

Could you perhaps help me out with an example? I love the idea behind the blueprint, but somehow I am not able to get it to work. (amongst others) I have tried the following config:

For Lovelace view path I have selected: https://XXXXXXXXX.duckdns.org/lovelace/lovelacecast
and i kept Lovelace dashboard blank.
I’ve also tried adding the port (8123 and 443), but it wont work.
what am i doing wrong?

many thanks,
BI,

PS. the error i get on the google home is the casa nabu screen with the error message:
“not connected”
“error unable to connect to the home assistant websocket api”

Hi, in your case the path is just lovelacecast

Thanks for your quick response!
Unfortunately it does not work. Could it perhaps be related to the fact that I use nginx with duckdns?

Edit: works now I had to update the port in my external URL to 443 when using nginx. (Update under configuration-> general

hello!

(upload://qlcMDoYKINz7c6dneSvfJniDXp.png)

I report the same problem with the cast to the google nest hub have you set it up and get it on the google nest hub? what am I doing wrong?