Script with Variable - What am I doing wrong

Hey folks, I am trying to get a script setup to change the radio station on our Sonos, which will eventually take in the station as variable, the volume will then vary depending on the station.

Currently I’m just hard coding the variable to try and get it working, but I’m getting and error every time I try to run it I get an error.

Failed to call service script/sonos_radio. Error rendering data template: Result is not a Dictionary

I suspect it’s an obvious error, can anyone point out where I am going wrong, would be greatly appreciated!

sonos_radio:
  alias: Sonos Radio
  sequence:
    - variables:
        main_volume: 0.25
        virgin_volume: 0.2
        station: Radio 1
    - service: media_player.select_source
      target:
        device_id: 920281ea7de5bc374e168d9f86fe3fa0
      data:
        source: "{{station}}"
    - if: "{{ station == 'Virgin' }}"
      then:
        - service: media_player.volume_set
          data: 0.2
          target:
            device_id: 920281ea7de5bc374e168d9f86fe3fa0
      else:
        - service: media_player.volume_set
          data: 0.25
          target:
            device_id: 920281ea7de5bc374e168d9f86fe3fa0
      enabled: true
  mode: single

Maybe try with quotes:

station: "Radio 1"

Thanks, but the same error.

Failed to call service script/sonos_radio. Error rendering data template: Result is not a Dictionary

The changing of the station seems to work actually it’s the conditional if block for setting the volume that seems to fail.

:thinking:

sonos_radio:
  alias: Sonos Radio
  sequence:
    - variables:
        main_volume: 0.25
        virgin_volume: 0.2
        station: "Radio 1"  # Corrected 
    - service: media_player.select_source
      target:
        device_id: 920281ea7de5bc374e168d9f86fe3fa0
      data:
        source: "{{ station }}"
    - choose:
        - conditions:
            - "{{ station == 'Virgin' }}"
          sequence:
            - service: media_player.volume_set
              data:
                volume_level: "{{ virgin_volume }}"  #  Corrected 
              target:
                device_id: 920281ea7de5bc374e168d9f86fe3fa0
        - conditions:
            - "{{ station != 'Virgin' }}"
          sequence:
            - service: media_player.volume_set
              data:
                volume_level: "{{ main_volume }}"  # Corrected 
              target:
                device_id: 920281ea7de5bc374e168d9f86fe3fa0
  mode: single

Ah that’s what it was, in the process of copy/pasting id removed the volume_level under data, thanks!