Platform: rest question what am I missing?

the code below gets data from an API that gives json like this
[{“id”:1,“Url”:“http://server.com/1",“Encoding”:“mp3”,“Name”:“1”,“Username”:“u”,“Password”:“p”,“Active”:0,“AutoPlay”:0},{“id”:40,“Url”:“http://server.com/2”,“Encoding”:“mp3”,“Name”:“2”,“Username”:“u”,“Password”:“p”,“Active”:0,“AutoPlay”:0},{“id”:71,“Url”:“http://server.com/3”,“Encoding”:“mp3”,“Name”:“3”,“Username”:“u”,“Password”:“p”,“Active”:0,“AutoPlay”:0},{“id”:90,“Url”:“http://server.com/4”,“Encoding”:“mp3”,“Name”:“4”,“Username”:“u”,“Password”:“p”,“Active”:0,"AutoPlay”:0},]
I have referenced sensors.yaml in configuration.yaml
and this is the code in sensors.yaml

- platform: rest
  resource: "http://url of list of streams
  method: GET
  scan_interval: 900
  name: "Easylisten channel all"
  value_template: >-
    {% for stream_list in streams %}
      {% for stream_dict in stream_list %}
      {{ stream_dict.Name }}
        {{stream_dict.Url}}.{{stream_dict.Encoding}}
        {{ stream_dict.Active }}
      {% endfor %}
    {% endfor %}

what I really need is a select list of the names
and then from the name be able to send the URL to my media player.
instead of maintaining the player script manually

radio_play:
  alias: Play Stream
  mode: single
  icon: mdi:play
  sequence:
    - service: media_player.volume_set
      data:
        entity_id: >
          {% if is_state("input_select.radio_speaker", "Office") %} media_player.sonos_roam_1
          {% elif is_state("input_select.radio_speaker", "Living_Room") %} media_player.sonos_roam_2
          {% endif %}
        volume_level: '{{states("input_number.radio_volume") }}'
    - service: media_player.play_media
      data:
        entity_id: >
          {% if is_state("input_select.radio_speaker", "Office") %} media_player.sonos_roam_1
          {% elif is_state("input_select.radio_speaker", "Living_Room") %} media_player.sonos_roam_2
          {% endif %}
        media_content_id: >
          {% if is_state("input_select.radio_station", "1") %} http://server.com/1.mp3
          {% elif is_state("input_select.radio_station", "2") %} http://server.com/2.mp3
          {% elif is_state("input_select.radio_station", "3") %} http://server.com/3.mp3
          {% elif is_state("input_select.radio_station", "4") %}http://server.com/4.mp3                   
          {% endif %}
        media_content_type: "music"

Paste in some real JSON, properly formatted (like your sensor is); and what you’d like the resultant output of the REST sensor to look like. We can’t use your example JSON above because you’ve pasted it as normal text which the forum software mangles with smart quotes, and I’m not re-typing it all.

Be aware that sensor states have a maximum length of 255 characters.

Sorry first time posting on a forum with code snips. Here it is made pretty - the API minified it I think it is all one line.
I need 1 list with Name
and then in the radio player script the Name and Url .
But I am not trying to get someone to solve it for me, I want to learn how to find the fault and fix it.

and later if possible - I don’t know enough about it yet, can I use CSS to stylize the drop down and put an icon in front of each name if the active flag is set. or sort active to the top.

[
	{
		"id": 1,
		"Url": "http://us-il-chicago-1.listen.com:8000/10001",
		"Encoding": "mp3",
		"Name": "2022 Inspiration - General Use",
		"Username": "#########",
		"Password": "#########",
		"Active": 0,
		"AutoPlay": 0
	},
	{
		"id": 40,
		"Url": "http://us-ca-fremont-1.listen.com:8000/1924842",
		"Encoding": "mp3",
		"Name": "Alexanderfeld Congregation, Hillsboro, KS",
		"Username": "#########",
		"Password": "#########",
		"Active": 0,
		"AutoPlay": 0
	}
]

In your template sensor you reference streams but that doesn’t exist. You want to use value_json, which is the response from the server read into a JSON object. Also, sensor states are limited to 255 characters, which you’ll quickly blow through with that approach. You can use sensor attributes, though: they can store arbitrary data structures like dictionaries and have a much higher size limit.

Here’s a starting point for copy/pasting into the template editor, with the example JSON read into a variable that I’ve called value_json for ease when moving it back into the sensor:

{% set value_json = [
	{
		"id": 1,
		"Url": "http://us-il-chicago-1.listen.com:8000/10001",
		"Encoding": "mp3",
		"Name": "2022 Inspiration - General Use",
		"Username": "#########",
		"Password": "#########",
		"Active": 0,
		"AutoPlay": 0
	},
	{
		"id": 40,
		"Url": "http://us-ca-fremont-1.listen.com:8000/1924842",
		"Encoding": "mp3",
		"Name": "Alexanderfeld Congregation, Hillsboro, KS",
		"Username": "#########",
		"Password": "#########",
		"Active": 0,
		"AutoPlay": 0
	}
] %}

Your template, adjusted:
{% for stream_dict in value_json %}
{{ stream_dict.Name }}
  {{stream_dict.Url}}.{{stream_dict.Encoding}}
  {{ stream_dict.Active }}
{% endfor %}

=======
A simple list of Names:
{{ value_json|map(attribute="Name")|list }}

=======
A dictionary of Name: URL:
{% set ns = namespace(d={}) -%}
{% for item in value_json -%}
{% set ns.d = dict(ns.d, **{item['Name']: item['Url']}) -%}
{% endfor -%}
{{ ns.d }}

That gives, from your example JSON:

Thanks for giving me something to work with.
so the

{% for stream_dict in value_json %}
{{ stream_dict.Name }}
  {{stream_dict.Url}}.{{stream_dict.Encoding}}
  {{ stream_dict.Active }}
{% endfor %}

will run out of characters?
and I should use your other examples?

when I use

- platform: rest
  resource: http://api.listentochurch.com/api/v1/easylisten/streams/##
  method: GET
  scan_interval: 900
  name: "Easylisten channel Names"
  value_template: >-
    {{ value_json|map(attribute="Name")|list }}

in my sensors.yaml
and then look at states I get

Yeah, you’re running out of characters as that URL returns a lot of entries. Try ...|list[:3] to limit the number of returned entries.

If I can only get 3 items I can manually manage my list. This API only gives 15.
Is there another way to get this API data into my system?

I guess there are really only a couple reasons that I want the API
the list can change from the services web interface,
the active flag shows when a stream is active which I don’t get otherwise.

Yes, of course: my suggestion was just to show that it’s working. You could set up a number of sensors: if you know there are 15 (or any fixed number), you could do something like:

rest:
  - resource: http://api.listentochurch.com/api/v1/easylisten/streams/7ae1df76-843b-409a-bf18-fb01bd4128a8
    scan_interval: 900
    sensor:
      - name: Easylisten 1
        value_template: "{{ value_json[0]['Name'] }}"
        json_attributes_path: "$.0"
        json_attributes:
          - id
          - Url
          - Encoding
          - Username
          - Password
          - Active
          - AutoPlay
      - name: Easylisten 2
        value_template: "{{ value_json[1]['Name'] }}"
        json_attributes_path: "$.1"
        json_attributes:
          - id
          - Url
          - Encoding
          - Username
          - Password
          - Active
          - AutoPlay

That gives:

…and just repeat for another 13 times upping the numbers in the name, value_template and json_attributes_path appropriately.

Once you have that, it’s easy to filter sensors that have an Active attribute of 1, for example.

Sorry work took me away for a week,
This code works in the template editor

active_congregation:
  name: "Active Congregation"
  options: >-
    {% for sensor in states.sensor if sensor.entity_id.startswith('sensor.easylisten_') and state_attr(sensor.entity_id, 'Active') %}
      {{ state_attr(sensor.entity_id, 'Name') }}
    {% endfor %}
  icon: mdi:radio

but if I put in in input_select I and then check in states I get


I must be misunderstanding something basic here.

You cannot use templates everywhere in HA configuration. The docs:

… don’t say you can use a template there, so you probably can’t, and your attempt shows that you definitely can’t.

Look at the set_options service described on the page linked above. That looks like your best bet…

Thanks! I’ll get that read and digested before I come back with more questions.