'NoneType' object is not iterable

I got this error:

2021-05-10 16:29:41 ERROR (MainThread) [homeassistant.helpers.check_config] Unexpected error validating config
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/check_config.py", line 155, in async_check_ha_config_file
    await config_validator.async_validate_config(  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/script/config.py", line 115, in async_validate_config
    cfg = await _try_async_validate_config_item(hass, object_id, cfg, config)
  File "/usr/src/homeassistant/homeassistant/components/script/config.py", line 93, in _try_async_validate_config_item
    raw_config = dict(config)
TypeError: 'NoneType' object is not iterable

For this script:

boot_cast_device_and_set_volume_without_bleeps:
description: Ensures a Google Home device is activated with a pre-set volume and won't emit any sounds while doing so.
sequence:
  - choose:
      #
      # When the device is in OFF state, we first mute the player in order to hide the startup sound and then wait until the idle is booted.
      #
      - conditions:
          - condition: state
            entity_id: media_player.$PLAYER
            state: off
        sequence:
          - service: media_player.volume_mute
            target:
              entity_id: media_player.$PLAYER
            data:
              is_volume_muted: true
          - service: media_player.turn_on
            target:
              entity_id: media_player.$PLAYER
          - wait_template: '{{ is_state(''media_player.$PLAYER'', ''idle'') }}'
      #
      # Now that the device is in 'idle' state, we are going to:
      #  - Mute the device
      #  - Play media (silent MP3)
      #  - Wait for the device to start playing 
      #  - Change the audio level (since the device is playing, won't show the BLOOP sound)
      #  - Unmute the device
      #
      - conditions:
          - condition: state
            entity_id: media_player.$PLAYER
            state: idle
        sequence:
          - service: media_player.volume_mute
            target:
              entity_id: media_player.$PLAYER
            data:
              is_volume_muted: true
          - service: media_player.play_media
            target:
              entity_id: media_player.$PLAYER
            data:
              media_content_type: audio
              media_content_id: media-source://media_source/local/1-minute-of-silence.mp3
          - wait_template: '{{ is_state(''media_player.$PLAYER'', ''playing'') }}'
          - service: media_player.volume_set
            target:
              entity_id: media_player.$PLAYER
            data:
              volume_level: $VOLUME_LEVEL
          - service: media_player.volume_mute
            target:
              entity_id: media_player.$PLAYER
            data:
              is_volume_muted: false
          - service: tts.google_translate_say
            data:
              entity_id: media_player.$PLAYER
              message: 'This is a test!'
    default: []
mode: single

It seems to be properly formatted, but i can’t spot the error.

This isn’t something wrong with the code per se, it is simply a notice, that a state that you’re working with, is not ready. Possibly because you restarted or the sensor isn’t available for other reasons.

For example, this brings up a “NoneObject” (=no object), that can’t be iterated. How could it, if there is no object present. :slight_smile:

Well i understand your reasoning, but why does it throw an error? e.g. the script doesn’t load and the ‘validate config’ gives an error:

Because at that point, where an object is needed, there isn’t one. That can be for example, because something is not reachable, not working (battery empty) or whatever.

In your case it seems, something is not reporting anything, that’s why there is “no object”, (=NoneObject) and therefor no iteration possible.

What makes you think, it is this specific script? :slight_smile: In the error log there is no connection made, so it could be anywhere…

These aren’t valid object IDs. The error is most likely coming from those.

1 Like

They are / should be parameters i pass into the script; do i need to change my script so i can pass a dynamic entity?

That’s not how variables work for scripts. Check out the docs to see how to do variables:

Here are some examples on passing player into your script.

              entity_id: "media_player.{{ player }}"
          - wait_template: '{{ is_state(''media_player.'' ~ player, ''idle'') }}'

then your script would be called with…

- service: script.myscript
  data:
    player: whatever_my_player_object_id_is
2 Likes

@petro i’ve adjusted the script accordingly, but still it gives me the same error. Is it maybe the indentation that is wrong?

ready_cast_with_set_volume:
description: Ensures a Google Home device is activated with a pre-set volume
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: "media_player.{{ player }}"
            state: off
        sequence:
          - service: media_player.volume_mute
            target:
              entity_id: "media_player.{{ player }}"
            data:
              is_volume_muted: true
          - service: media_player.turn_on
            target:
              entity_id: "media_player.{{ player }}"
          - wait_template: '{{ is_state(''media_player.'' ~ player, ''idle'') }}'
      - conditions:
          - condition: state
            entity_id: "media_player.{{ player }}"
            state: idle
        sequence:
          - service: media_player.volume_mute
            target:
              entity_id: "media_player.{{ player }}"
            data:
              is_volume_muted: true
          - service: media_player.play_media
            target:
              entity_id: "media_player.{{ player }}"
            data:
              media_content_type: audio
              media_content_id: media-source://media_source/local/1-minute-of-silence.mp3
          - wait_template: '{{ is_state(''media_player.'' ~ player, ''playing'') }}'
          - service: media_player.volume_set
            target:
              entity_id: "media_player.{{ player }}"
            data:
              volume_level: "{{ volume_level }}"
          - service: media_player.volume_mute
            target:
              entity_id: "media_player.{{ player }}"
            data:
              is_volume_muted: false
          - service: tts.google_translate_say
            data:
              entity_id: "media_player.{{ player }}"
              message: 'This is an alert!'
    default: []
mode: single

You can’t template state condition entity_id fields. You’ll have to change that into a template condition.

You can only template:

  1. value_template fields.
  2. fields under target.
  3. fields under data.
  4. service field.

Thanx! In the end it was indeed something with indentation, and the configuration now validates. Would this be the right change for the template condition?

This is the modified script:

ready_cast_with_set_volume:
  description: Ensures a Google Home device is activated with a pre-set volume
  sequence:
    - choose:
        - conditions:
            - condition: template
              value_template: '{{ is_state(''media_player.'' ~ player, ''off'') }}'
          sequence:
            - service: media_player.volume_mute
              target:
                entity_id: 'media_player.{{ player }}'
              data:
                is_volume_muted: true
            - service: media_player.turn_on
              target:
                entity_id: 'media_player.{{ player }}'
            - wait_template: '{{ is_state(''media_player.'' ~ player, ''idle'') }}'
        - conditions:
            - condition: template
              value_template: '{{ is_state(''media_player.'' ~ player, ''idle'') }}'
          sequence:
            - service: media_player.volume_mute
              target:
                entity_id: 'media_player.{{ player }}'
              data:
                is_volume_muted: true
            - service: media_player.play_media
              target:
                entity_id: 'media_player.{{ player }}'
              data:
                media_content_type: audio
                media_content_id: 'media-source://media_source/local/1-minute-of-silence.mp3'
            - wait_template: '{{ is_state(''media_player.'' ~ player, ''playing'') }}'
            - service: media_player.volume_set
              target:
                entity_id: 'media_player.{{ player }}'
              data:
                volume_level: '{{ volume_level }}'
            - service: media_player.volume_mute
              target:
                entity_id: 'media_player.{{ player }}'
              data:
                is_volume_muted: false
            - service: tts.google_translate_say
              data:
                entity_id: 'media_player.{{ player }}'
                message: This is an alert!
      default: []
  mode: single