How to configure REST sensor

Here’s my code in my sensors.yaml:

- platform: rest
  resource: https://api.sunrise-sunset.org/json?lat=xx.yyy&lng=-aa.bbb&formatted=0
  verify_ssl: false
  name: Daylight Length
  json_attributes_path: "$.results"
  json_attributes:
    - results
  value_template: "{{ value_json['results']}}"

I’m getting, “Error adding entities for domain sensor with platform rest”
I’ve gone through the docs and read a few related posts here, what am I doing wrong?
Thanks

This is how a response looks like:

{
    "results": {
        "sunrise": "2022-02-06T07:40:02+00:00",
        "sunset": "2022-02-06T17:52:02+00:00",
        "solar_noon": "2022-02-06T12:46:02+00:00",
        "day_length": 36720,
        "civil_twilight_begin": "2022-02-06T07:11:46+00:00",
        "civil_twilight_end": "2022-02-06T18:20:18+00:00",
        "nautical_twilight_begin": "2022-02-06T06:37:59+00:00",
        "nautical_twilight_end": "2022-02-06T18:54:06+00:00",
        "astronomical_twilight_begin": "2022-02-06T06:04:46+00:00",
        "astronomical_twilight_end": "2022-02-06T19:27:18+00:00"
    },
    "status": "OK"
}

I see two problems in your code:

  1. json_attributes should list the attributes you want to gather - in your example this should be something like sunrise, sunset, solar_noon, …
  2. Value templates returns a dictionary (=multiple results) but it should be only one value, in your case you could use “{{ value_json[‘status’]}}” (or whatever attribute you prefer)

Thanks for the reply. I’ve restructured my code:

- platform: rest
  resource: https://api.sunrise-sunset.org/json?lat=xx.yyy&lng=-yy.xxx&formatted=0
  verify_ssl: false
  name: Daylight Length
  json_attributes_path: "$.results"
  json_attributes:
    - day_length
  value_template: "{{ value_json['day_length']}}"

Now I get this error:

" * Template variable warning: 'dict object' has no attribute 'day_length' when rendering '{{ value_json['day_length']}}'"
value_template: "{{ value_json['results']['day_length']}}"

Thanks, that fixed it!