Need help w Restful Sensor - Flailing miserably

I have created and validated a JSON file that has events for every day of the year. Id like to read the event for the current day and the next day, however all my attempts have failed in action, although it works in the templated editor. The JSON file looks like this (truncated)

{
  "MY_EVENT": [
      { "event_date": "1/1/2025", "event_name": "My Event Name 1", "event_type": "1" },
      { "event_date": "1/2/2025", "event_name": "My Event Name 2", "event_type": "2" },
      { "event_date": "1/3/2025", "event_name": "My Event Name 3", "event_type": "3" },
      { "event_date": "1/12/2025", "event_name": "My Event Name 12", "event_type": "4" },
      { "event_date": "1/13/2025", "event_name": "My Event Name 13", "event_type": "3" },
      { "event_date": "1/14/2025", "event_name": "My Event Name 14", "event_type": "3" },
      { "event_date": "1/30/2025", "event_name": "My Event Name 30", "event_type": "2" },
      { "event_date": "1/31/2025", "event_name": "My Event Name 31", "event_type": "1" }
    ]
}

Then in /sensors/rest.yaml I have

- platform: rest
  name: my_event
  unique_id: my_event
  resource: http://192.168.1.203:8123/local/json/my_events.json
  value_template: "{{ value_json.MY_EVENT }}"
  scan_interval: 21600
  value_template: >-
    {% set day0 = (states('sensor.day_num_of_year')|int)-1 %}
    {% set event_name = value_json.MY_EVENT[day0].event_name %}

In the template editor I can see that this works:

{% set value_json =
{
  "MY_EVENT": [
      { "event_date": "1/1/2025", "event_name": "My Event Name 1", "event_type": "1" },
      { "event_date": "1/2/2025", "event_name": "My Event Name 2", "event_type": "2" },
      { "event_date": "1/3/2025", "event_name": "My Event Name 3", "event_type": "3" },
      { "event_date": "1/12/2025", "event_name": "My Event Name 12", "event_type": "4" },
      { "event_date": "1/13/2025", "event_name": "My Event Name 13", "event_type": "3" },
      { "event_date": "1/14/2025", "event_name": "My Event Name 14", "event_type": "3" },
      { "event_date": "1/30/2025", "event_name": "My Event Name 30", "event_type": "2" },
      { "event_date": "1/31/2025", "event_name": "My Event Name 31", "event_type": "1" }
    ]
}
%}
{% set day0 = (states('sensor.day_num_of_year')|int)-1 %}
{{ value_json.MY_EVENT[day0].event_date }}

returns: 1/12/2025

and

{% set day2 = (states('sensor.day_num_of_year')|int)+1 %}
{{ value_json.MY_EVENT[day2].event_name }}

returns: My Event Name 14

My problem is that outside the template editor, the sensors return ‘unknown’.
It seems like it should work, since it does work in the template editor, but Im missing something. Ive spent hours reading the docs (so please no RTFM replies) and searching the forums and Google, but can’t seem to come up with the correct solution.
Ideally, Id like one sensor for today (sensor.my_event_today), one for tomorrow (sensor.my_event_tomnorrow) each with attributes for the event_date and event_type.
A working example would be golden. Thanks in advance.

Remove the first of your two value_template lines…

You wrote:
Remove the first of your two value_template lines…

  value_template: >-
    {% set day0 = (states('sensor.day_num_of_year')|int)-1 %}
    {% set event_name = value_json.MY_EVENT[day0].event_name %}

I’m sorry but that makes no sense, and leaves day0 as an undefined value. The second line uses day0 as the selector for which line to read. To be sure I tested it as you suggested. No change - sensor still reads unknown.

Sorry I cannot offer a solution here but for what it’s worth, not everything that works in the template editor also works in configuration.yaml. Also trying to do the same thing in a slightly different way in the editor may work in configuration.yaml as well -

What I meant was…

REMOVE THIS LINE
|
| - platform: rest
|   name: my_event
|   unique_id: my_event
|   resource: http://192.168.1.203:8123/local/json/my_events.json
->  value_template: "{{ value_json.MY_EVENT }}"
    scan_interval: 21600
    value_template: >-
      {% set day0 = (states('sensor.day_num_of_year')|int)-1 %}
->    {{ value_json.MY_EVENT[day0].event_name }}
|
AND YOUR TEMPLATE NEEDS AN OUTPUT

…with another tweak as your code sets two variables but doesn’t output anything.