Script/Automation worked then started throwing errors now wont work using original code

Had an automation / script that worked great for about two hours then stopped after trying to add a second automation for another remote, now I cannot get the original script or automation to work.

Errors thrown are:

Invalid config for [automation]: template value should be a string for dictionary value @ data[‘action’][0][‘data’]. Got None.


Invalid config for [script]: not a valid value for dictionary value @ data[‘sequence’][0][‘choose’][1][‘sequence’][0][‘target’][‘entity_id’]. Got None.

Automation Code:

- id: "1662220652179"
  alias: Audio test remote script test
  description: "test to send var to script"
    - platform: state
      entity_id: sensor.remotes_test
      from: "0"
  condition: []
    service: script.audio_remote
        button: "{{ states.sensor.remotes_test.state }}"
        zone: "{{ media_player.zone_11 }}"
        zone_source: "{{state_attr('media_player.zone_11', 'source'}}"
  mode: single

Script Code:

  alias: audio remote script
  mode: parallel
    button_pressed: "{{ button | int(0) }}"
    speaker_zone: "{{ zone }}"
    zone_source_int: "{{ zone_source | int(0) }}"
    - choose:
        - conditions: "{{ button_pressed in [1, 4] }}"
          # button play/pause (1) or next (4) pressed
            - service: media_player.select_source
                source: "{{ iif(zone_source_int == '1', '2', '1') }}"
                entity_id: "{{ zone }}"
        - conditions: "{{ button_pressed == 2 }}"
          # button center (2) pressed
            - service: media_player.toggle
                entity_id: speaker_zone
        - conditions: "{{ button_pressed in [8, 16] }}"
          # button volume up (8) or down (16) pressed
            - service: "media_player.volume_{{ iif(button_pressed == 8, 'up', 'down') }}"
                entity_id: speaker_zone
      default: []

I have gone over spacing a bunch of times and even re-type everything by hand just incase cut and paste was doing weird things with no luck. What I don’t get is why it worked and now it throws the error, maybe there is a cache or something that needs to be cleared out? I have restarted services as well as full server several times in between troubleshooting changes.

Thanks in advance for any insights.

remove that change.


fix the error in the added code that stopped the original from working.

Thats what I have done.

The code posted is the original code.
I have removed the additions.
It was not causing errors before but now it does.

Then there is another change that you made and are missing or forgot about.

It has to be something you just changed.

You are missing a closing bracket in the automation:

        zone_source: "{{state_attr('media_player.zone_11', 'source'}}"

should be

        zone_source: "{{state_attr('media_player.zone_11', 'source')}}"

The script:

                entity_id: speaker_zone

should be:

                entity_id: "{{ speaker_zone }}"

For future reference the error message does tell you exactly where to look:


That means:

sequence: # the first sequence ( ['sequence'][0] )
  - choose:
      - conditions: # ignore this one - because we want the second one ( ['choose'][1] )
      - conditions: # this is the section we want, but this part is ok, so keep reading down
        sequence: # this is the correct part ( ['sequence'][0] )
             entity_id: # this is where the error is

Change this:

        zone: "{{ media_player.zone_11 }}"

to this:

        zone: "media_player.zone_11"

By enclosing the string media_player.zone_11 in double-braces you are instructing the Jinja2 processor to evaluate what lies within the braces. What it finds is a string that it assumes represents the name of a variable. However, this assumed variable is undefined so it all ends in an error.

By removing the double-braces, the Jinja2 interpreter doesn’t come into play and the string media_player.zone_11 is simply interpreted as a value to be assigned to the zone script variable (which is all you want for this application).