Mute Video Commercials/Advertisements

Using media player attributes, you can automate the muting of intrusive advertisements.

This works well for long form video content like YouTube playing on a Google Nest Hub, Chromecast, or Chromecast with Google TV, and audio content like Spotify playing on Google Home/Nest speakers.

Example Automation for YouTube:

alias: YT Mute Ads GC w GTV
description: ""
trigger:
  - platform: numeric_state
    entity_id: media_player.living_room_tv
    attribute: media_duration
    below: 153
    for:
      hours: 0
      minutes: 0
      seconds: 0
    above: 1
    id: Duration
    enabled: true
  - platform: numeric_state
    entity_id: media_player.living_room_tv
    attribute: supported_features
    above: 152448
    below: 152450
    id: Features
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: media_player.living_room_tv
        attribute: media_title
        state: ""
    enabled: true
  - condition: or
    conditions:
      - condition: state
        entity_id: media_player.living_room_tv
        attribute: app_name
        state: YouTube
action:
  - service: script.amplifier_volume_mute
    data: {}
  - choose:
      - conditions:
          - condition: trigger
            id: Duration
        sequence:
          - wait_for_trigger:
              - platform: numeric_state
                entity_id: media_player.living_room_tv
                attribute: media_duration
                above: 153
      - conditions:
          - condition: trigger
            id: Features
        sequence:
          - wait_for_trigger:
              - platform: numeric_state
                entity_id: media_player.living_room_tv
                attribute: supported_features
                above: 152450
                below: 152452
  - service: script.amplifier_volume_mute
    data: {}
mode: single

Can you share the automation?

Chromecast Code:
Works for advertisements at start of video but not inside video.

alias: YT TV Mute Ad (Media Position)
description: ''
trigger:
  - platform: numeric_state
    entity_id: media_player.tv_chromecast
    attribute: media_position
    below: '0.1'
    for:
      hours: 0
      minutes: 0
      seconds: 4
condition:
  - condition: state
    entity_id: media_player.tv_chromecast
    state: YouTube
    attribute: app_name
action:
  - service: script.amplifier_volume_mute
    data: {}
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: media_player.tv_chromecast
        for:
          hours: 0
          minutes: 0
          seconds: 0
        above: '0.1'
        attribute: media_position
  - service: script.amplifier_volume_mute
    data: {}
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.youtube_commercials_muted
mode: single

Hi, are you still using this automation in any way?

I use YoutubeTV with Google Chromecast w/ Google TV and would love a way to automate muting of commercials. I’ve tried using your automation but I can’t get it to trigger when a commercial starts.

I’m super new to home automation. Is there a way to debug the different states or parameters the chromecast is in to try and understand how to identify when a commercial is playing?

Hi. Yes indeed, I am using a more complex version of this idea. I’ll say a few things, but you may have to do some research to fill in the gaps if you are more new to HA:

  • Make sure you have Advanced Mode toggled on in your username settings
  • Developer Tools → States is the best way to debug the states for your GC w GTV
  • Traces is the best way to debug an automation

As far as trigger for this automation, my current trigger is:

platform: numeric_state
entity_id: media_player.living_room_tv
attribute: media_duration
below: 153
for:
  hours: 0
  minutes: 0
  seconds: 0
above: 1
id: Duration
enabled: true

I also recommend using a condition that filters out previews in the selection menu:

condition: not
conditions:
  - condition: state
    entity_id: media_player.living_room_tv
    attribute: media_title
    state: ""
enabled: true

This works best for long form video content (longer than 153 seconds), but notably the short form video content (i.e. shorts) is muted as well. Also long form advertising is not muted automatically.

I’ve updated my original post to reflect some changes you may find useful.

1 Like