UndefinedError: 'dict object' has no attribute 'title'

I have an automation with a template that used to work fine. It searches the results of the sensor.sonarr_upcoming_media sensor for a specific match with a keyword and sets an input boolean.

I hadn’t used it for quite some time and when I recently re-enabled the automation it is now throwing the following error and I can’t figure out what’s wrong.

I’ve tried paring down the conditions of the template and all sort of formatting variations but always get the same error:

UndefinedError: 'dict object' has no attribute 'title'

The automation/template:

alias: Network - Bachelor(ette) Night On/Off
description: ""
trigger:
  - platform: state
    entity_id: sensor.sonarr_upcoming_media
    attribute: data
  - platform: time_pattern
    minutes: "5"
condition: null
action:
  - service: >-
      input_boolean.turn_{{ 'on' if state_attr('sensor.sonarr_upcoming_media',
      'data')|selectattr('title', 'match', 'Bachelor')|list|length > 0 and
      (is_state('sensor.day_of_week', 'Tuesday') and states.sensor.time.state >
      '17:00' | timestamp_custom('%H:%M') and states.sensor.time.state < '22:00'
      | timestamp_custom('%H:%M')) else 'off'}}
    target:
      entity_id: input_boolean.bachelor_night
mode: single
max: 10

The output of the sonarr.upcoming_media sensor:

data: 
- title_default: $title
  line1_default: $episode
  line2_default: $release
  line3_default: $rating - $runtime
  line4_default: $number - $studio
  icon: mdi:arrow-down-bold
- airdate: '2022-08-05T04:00:00Z'
  release: $day, $time
  flag: false
  title: For All Mankind
  episode: Coming Home
  number: S03E09
  runtime: 60
  studio: Apple TV+
  rating: ''
  genres: Drama, Science Fiction
  poster: >-
    https://artworks.thetvdb.com/banners/series/356202/posters/600304db98362_t.jpg
  fanart: >-
    https://artworks.thetvdb.com/banners/series/356202/backgrounds/6035368ae4176_t.jpg
- airdate: '2022-08-05T04:00:00Z'
  release: $day, $time
  flag: false
  title: Loot
  episode: Cahoga Lake
  number: S01E09
  runtime: 26
  studio: Apple TV+
  rating: ''
  genres: Comedy
  poster: >-
    https://artworks.thetvdb.com/banners/v4/series/417559/posters/629ae434933f2_t.jpg
  fanart: >-
    https://artworks.thetvdb.com/banners/v4/series/417559/backgrounds/62b570d982e12_t.jpg
- airdate: '2022-08-06T02:00:00Z'
  release: $day, $time
  flag: false
  title: Real Time with Bill Maher
  episode: Episode 607
  number: S20E22
  runtime: 55
  studio: HBO
  rating: ★ 9.2
  genres: Comedy, News, Talk Show
  poster: https://artworks.thetvdb.com/banners/series/72231/posters/62062148_t.jpg
  fanart: https://artworks.thetvdb.com/banners/fanart/original/72231-3_t.jpg
- airdate: '2022-08-08T01:00:00Z'
  release: $day, $time
  flag: false
  title: Westworld
  episode: Metanoia
  number: S04E07
  runtime: 58
  studio: HBO
  rating: ★ 8.9
  genres: Adventure, Drama, Mystery, Science Fiction, Western
  poster: https://artworks.thetvdb.com/banners/posters/296762-3_t.jpg
  fanart: >-
    https://artworks.thetvdb.com/banners/v4/series/296762/backgrounds/62ab03c0d4243_t.jpg
- airdate: '2022-08-09T00:00:00Z'
  release: $day, $time
  flag: false
  title: The Bachelorette
  episode: TBA
  number: S19E05
  runtime: 85
  studio: ABC (US)
  rating: ★ 6.3
  genres: Drama, Game Show, Reality, Romance
  poster: https://artworks.thetvdb.com/banners/posters/71187-8_t.jpg
  fanart: https://artworks.thetvdb.com/banners/fanart/original/71187-4_t.jpg

friendly_name: Sonarr_Upcoming_Media

When the list you are filtering has dictionaries with a mix of keys, you now need to filter for only attributes/sub-attributes that have the filter attribute defined by pre-filtering with something like | selectattr('title', 'defined')

action:
  - service: >-
      input_boolean.turn_{{ 'on' if state_attr('sensor.sonarr_upcoming_media',
      'data') | selectattr('title', 'defined') | selectattr('title', 'match', 'Bachelor') | list | length > 0 
      and (is_state('sensor.day_of_week', 'Tuesday') 
      and today_at('17:00') < now() < today_at('22:00') else 'off' }}
1 Like

Thanks for the help! I tried your solution and it’s no longer throwing an error but it’s evaluating as the input_boolean being off when I believe it should be on.

I’ve paired the template down for testing to:

turn_{{ 'on' if state_attr('sensor.sonarr_upcoming_media',
      'data') | selectattr('title', 'defined')|selectattr('title', 'match', 'Bachelor')|list|length > 0 else 'off'}}
Result type: string
input_boolean.turn_off

Ok, it looks like the error with the match string now. ‘Batchelor’ used to match “The Bachelor” and “The Bachelorette” but it looks like it has to be ‘The Bachelor’ now to make the match.

Thanks for your help!

You should be able to get both from “Bachelor” by using ‘search’ instead of ‘match’ as your test.

Perfect, that works! Thanks again!

i can’t help but laugh at this :smile: