1000 times per minute: Error in 'condition' evaluation: In 'template' condition: TypeError: argument of type 'NoneType' is not iterable

What the heck is going on? Everything is working correctly but this error is occurring ~933 times per minute! HA is latest version 2022.2. I did modify my templates 2 days ago as per Custom UI - icon color change - Share your Projects! / Lovelace & Frontend - Home Assistant Community (home-assistant.io) but everything after that was fine. I think it’s related to 2022.2…

Logger: homeassistant.helpers.script
Source: helpers/script.py:638
First occurred: 1:45:11 PM (58812 occurrences)
Last logged: 2:47:52 PM

Error in ‘condition’ evaluation: In ‘template’ condition: TypeError: argument of type ‘NoneType’ is not iterable
Error in ‘condition’ evaluation: In ‘template’ condition: UndefinedError: list object has no element 156

I would check scripts which includes condition statement, apparently something is wrong there.

So what is the latest version of your template code?

Latest version of my template code? I’m not understanding that question… Where do I look?

I had a new variation of the error start at 8:30 pm last night in addition to the original post when my medication reminder kicked in.

Original post (now):

Logger: homeassistant.helpers.script
Source: helpers/script.py:638
First occurred: February 5, 2022, 7:33:04 PM (888576 occurrences)
Last logged: 11:22:33 AM

Error in 'condition' evaluation: In 'template' condition: TypeError: argument of type 'NoneType' is not iterable
Error in 'condition' evaluation: In 'template' condition: UndefinedError: list object has no element 156

New one:

Logger: homeassistant.helpers.script
Source: helpers/script.py:659
First occurred: February 5, 2022, 8:30:04 PM (57 occurrences)
Last logged: 10:30:04 AM

Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'None' has no attribute 'event'
alias: Medication Remindar - Evening
description: ''
use_blueprint:
  path: Aohzan/medication_reminder.yaml
  input:
    logbook_message_no_answer: No answer (timed out)
    notify_device: 52fa40cb8ef749a1a7800d6495551219
    input_boolean: input_boolean.medication_taken
    reminder_time: '20:00:00'
    logbook_message_skip: Reminder skipped
    optional_action:
      - service: notify.alexa_media_last_called
        data:
          message: It's time to take your pills!
          data:
            type: tts
    logbook_message_later: Reminder postponed
    logbook_message_taken: Medication taken
    logbook_message_remind: Reminder sent
    notification_action_skip: Skip
    notification_action_later: Ask later
    notification_action_taken: Taken
    notification_message: It's time to take your medication
    notification_title: Medication reminder!
blueprint:
  name: Advanced medication reminder
  description: Get advanced notification and history for medication reminder
  domain: automation
  input:
    reminder_time:
      name: Reminder time
      description: At what time do you want to be reminded
      selector:
        time: {}
    notify_device:
      name: Notification
      description: Device needs to run the official Home Assistant app to receive
        notifications
      selector:
        device:
          integration: mobile_app
    input_boolean:
      name: Dedicated input_boolean
      description: Create and set here a input_boolean to handle history and state
        of the automation
      selector:
        entity:
          domain: input_boolean
    notification_title:
      name: Notification title (Optional)
      description: 'Default: Medication reminder'
      default: Medication reminder!
    notification_message:
      name: Notification message (Optional)
      description: 'Default: It''s time to take your medication'
      default: It's time to take your medication
    notification_action_taken:
      name: 'Notification action: Taken (Optional)'
      description: 'Default: Taken'
      default: Taken
    notification_action_later:
      name: 'Notification action: Ask later (Optional)'
      description: 'Default: Ask later'
      default: Ask later
    notification_action_skip:
      name: 'Notification action: Skip (Optional)'
      description: 'Default: Skip'
      default: Skip
    ask_later_wait_time:
      name: Wait time before next reminder
      description: Minutes before notify again after a Ask later action.
      default: 30
      selector:
        number:
          min: 5.0
          max: 1440.0
          unit_of_measurement: minutes
          step: 1.0
          mode: slider
    logbook_message_remind:
      name: Logbook message for remind (Optional)
      description: 'Default: Reminder sent'
      default: Reminder sent
    logbook_message_taken:
      name: Logbook message for action Taken (Optional)
      description: 'Default: Medication taken'
      default: Medication taken
    logbook_message_later:
      name: Logbook message for action Ask later (Optional)
      description: 'Default: Postpone reminder'
      default: Postpone reminder
    logbook_message_skip:
      name: Logbook message for action Skip (Optional)
      description: 'Default: Reminder skipped'
      default: Reminder skipped
    logbook_message_no_answer:
      name: Logbook message for no action after timeout (Optional)
      description: 'Default: No answer time out'
      default: No answer time out
    optional_action:
      name: Optional action
      description: Run an action like notify a speaker at the same time that the mobile
        notification
      selector:
        action: {}
      default: []
  source_url: https://raw.githubusercontent.com/Aohzan/hass-blueprints/main/blueprints/medication_reminder.yaml
trigger:
- platform: time
  at: !input 'reminder_time'
mode: restart
action:
- service: input_boolean.turn_off
  target:
    entity_id: !input 'input_boolean'
- alias: Notify until the medication has been take
  repeat:
    while:
    - condition: state
      entity_id: !input 'input_boolean'
      state: 'off'
    sequence:
    - service: logbook.log
      data:
        name: !input 'notification_title'
        message: !input 'logbook_message_remind'
        entity_id: !input 'input_boolean'

I mean the template code :slight_smile: In the link you posted I couldn’t find the result. Which templates are not working? Ok, thanks.

Have you shortened the blueprint because I don’t see the repeat and choose action. If it is only a copy accident I would agree that it could be caused by the 2022.2.2 version.

Copy/paste error…

blueprint:
  name: Advanced medication reminder
  description: Get advanced notification and history for medication reminder
  domain: automation
  input:
    reminder_time:
      name: Reminder time
      description: At what time do you want to be reminded
      selector:
        time: {}
    notify_device:
      name: Notification
      description: Device needs to run the official Home Assistant app to receive
        notifications
      selector:
        device:
          integration: mobile_app
    input_boolean:
      name: Dedicated input_boolean
      description: Create and set here a input_boolean to handle history and state
        of the automation
      selector:
        entity:
          domain: input_boolean
    notification_title:
      name: Notification title (Optional)
      description: 'Default: Medication reminder'
      default: Medication reminder!
    notification_message:
      name: Notification message (Optional)
      description: 'Default: It''s time to take your medication'
      default: It's time to take your medication
    notification_action_taken:
      name: 'Notification action: Taken (Optional)'
      description: 'Default: Taken'
      default: Taken
    notification_action_later:
      name: 'Notification action: Ask later (Optional)'
      description: 'Default: Ask later'
      default: Ask later
    notification_action_skip:
      name: 'Notification action: Skip (Optional)'
      description: 'Default: Skip'
      default: Skip
    ask_later_wait_time:
      name: Wait time before next reminder
      description: Minutes before notify again after a Ask later action.
      default: 30
      selector:
        number:
          min: 5.0
          max: 1440.0
          unit_of_measurement: minutes
          step: 1.0
          mode: slider
    logbook_message_remind:
      name: Logbook message for remind (Optional)
      description: 'Default: Reminder sent'
      default: Reminder sent
    logbook_message_taken:
      name: Logbook message for action Taken (Optional)
      description: 'Default: Medication taken'
      default: Medication taken
    logbook_message_later:
      name: Logbook message for action Ask later (Optional)
      description: 'Default: Postpone reminder'
      default: Postpone reminder
    logbook_message_skip:
      name: Logbook message for action Skip (Optional)
      description: 'Default: Reminder skipped'
      default: Reminder skipped
    logbook_message_no_answer:
      name: Logbook message for no action after timeout (Optional)
      description: 'Default: No answer time out'
      default: No answer time out
    optional_action:
      name: Optional action
      description: Run an action like notify a speaker at the same time that the mobile
        notification
      selector:
        action: {}
      default: []
  source_url: https://raw.githubusercontent.com/Aohzan/hass-blueprints/main/blueprints/medication_reminder.yaml
trigger:
- platform: time
  at: !input 'reminder_time'
mode: restart
action:
- service: input_boolean.turn_off
  target:
    entity_id: !input 'input_boolean'
- alias: Notify until the medication has been take
  repeat:
    while:
    - condition: state
      entity_id: !input 'input_boolean'
      state: 'off'
    sequence:
    - service: logbook.log
      data:
        name: !input 'notification_title'
        message: !input 'logbook_message_remind'
        entity_id: !input 'input_boolean'
    - choose:
      - conditions: '{{ true }}'
        sequence: !input 'optional_action'
    - device_id: !input 'notify_device'
      domain: mobile_app
      type: notify
      title: !input 'notification_title'
      message: !input 'notification_message'
      data:
        ttl: 0
        priority: high
        actions:
        - title: !input 'notification_action_taken'
          action: taken
        - title: !input 'notification_action_later'
          action: later
        - title: !input 'notification_action_skip'
          action: skip
        tag: !input 'input_boolean'
    - wait_for_trigger:
        platform: event
        event_type: mobile_app_notification_action
        event_data:
          tag: !input 'input_boolean'
      timeout:
        minutes: !input 'ask_later_wait_time'
    - choose:
      - conditions: '{{ wait.trigger.event.data.action == ''taken'' }}'
        sequence:
        - service: input_boolean.turn_on
          target:
            entity_id: !input 'input_boolean'
        - service: logbook.log
          data:
            name: !input 'notification_title'
            message: !input 'logbook_message_taken'
            entity_id: !input 'input_boolean'
      - conditions: '{{ wait.trigger.event.data.action == ''later'' }}'
        sequence:
        - service: logbook.log
          data:
            name: !input 'notification_title'
            message: !input 'logbook_message_later'
            entity_id: !input 'input_boolean'
        - delay:
            minutes: !input 'ask_later_wait_time'
      - conditions: '{{ wait.trigger.event.data.action == ''skip'' }}'
        sequence:
        - service: input_boolean.turn_on
          target:
            entity_id: !input 'input_boolean'
        - service: logbook.log
          data:
            name: !input 'notification_title'
            message: !input 'logbook_message_skip'
            entity_id: !input 'input_boolean'
      default:
      - device_id: !input 'notify_device'
        domain: mobile_app
        type: notify
        message: clear_notification
        data:
          tag: !input 'input_boolean'
      - service: logbook.log
        data:
          name: !input 'notification_title'
          message: !input 'logbook_message_no_answer'
          entity_id: !input 'input_boolean'

This automation is firing every 10 seconds and triggering the error:

alias: Recycling - Holiday in week move
description: >-
  Loop through all calculated dates, move the collection by 1 day if public
  holiday was in the week before or on the calculated collection date
trigger:
  - platform: event
    event_type: garbage_collection_loaded
    event_data:
      entity_id: sensor.recycling
condition: []
action:
  - repeat:
      count: '{{ trigger.event.data.collection_dates | count }}'
      sequence:
        - condition: template
          value_template: >
            {%- set ns = namespace(found=false) %} {%- set d =
            trigger.event.data.collection_dates[repeat.index] %} {%- for i in
            range(as_datetime(d).weekday()+1) %} {%- if (as_datetime(d) +
            timedelta( days = -i)) | as_timestamp | timestamp_custom('%Y-%m-%d')
            in state_attr(trigger.event.data.entity_id,'holidays') %} {%- set
            ns.found = true %} {%- endif %} {%- endfor %} {{ ns.found }}
        - service: garbage_collection.add_date
          data:
            entity_id: '{{ trigger.event.data.entity_id }}'
            date: >-
              {{ (as_datetime(trigger.event.data.collection_dates[repeat.index])
              + timedelta( days = 1)) | as_timestamp |
              timestamp_custom("%Y-%m-%d") }}
        - service: garbage_collection.remove_date
          data:
            entity_id: '{{ trigger.event.data.entity_id }}'
            date: '{{ trigger.event.data.collection_dates[repeat.index] }}'
        - service: garbage_collection.update_state
          data:
            entity_id: sensor.recycling
mode: single

I’ve re-enabled all other automations and the errors have stopped.
That is the only automation triggering it. Now, why is that event firing every 10 seconds…

The error message suggests that an entity does not exist.

I’ve left the original pre-blueprint automation disabled and downloaded the new blueprint from Garbage-Collection, configured the automation from it and HA is happy with it - no errors.
Original automation:

trigger:
  - platform: event
    event_type: garbage_collection_loaded
    event_data:
      entity_id: sensor.recycling

New blueprint:

They look the same to me. So I re-enabled the original automation and now no errors except for 156 when HA starts. WTH? Why before was there the repetition every 10 seconds but not now?
Now to figure out why there’s 156 at startup…no biggie though. Thanks for helping me work through this!

1 Like

I changed the holiday sensor from partofthething / Next Holiday Sensor to bruxy70 / Holidays and the 156 errors at startup are now gone also.

1 Like

Actually, automation is not triggered at that rate, core is trying to evaluate the template and failing to do, maybe, automation would not do anything but template should be resolved to decide.

I could not figure out the source for the multiple triggers other than they were 156 every 10 seconds and could not figure out a rhyme or reason. The errors are gone now after the above changes so I will let sleeping dogs lie…

Thanks!!!