I am trying to build my first custom RESTful sensor for integrating data from Surfline onto my dashboard, but I can’t seem to access the data with json_attributes.
In my sensors.yaml file, which is included by my configuration.yaml file as sensor: !include sensors.yaml
- platform: rest
resource: https://services.surfline.com/kbyg/regions/forecasts/conditions?spotId=5842041f4e65fad6a7708b8d&days=1
method: GET
name: surfline
value_template: '{{ (value_json["data"].conditions[0]) }}'
json_attributes_path: "$.data.conditions[0]"
json_attributes:
- am
- pm
- observation
scan_interval: 900
- platform: template
sensors:
surfline_am:
friendly_name: "AM"
value_template: "{{ state_attr('sensor.surfline', 'am')['maxHeight']}}"
surfline_pm:
friendly_name: "PM"
value_template: "{{ state_attr('sensor.surfline', 'pm') }}"
surfline_observation:
friendly_name: "Observation"
value_template: "{{ state_attr('sensor.surfline', 'observation') }}"
And here is the JSON response from the API (or you can try it yourself, no authentication is required)
// Unnecessary data omitted for brevity
{
"associated": {
},
"data": {
"conditions": [
{
"observation": "Very small very short period waves from the SW. Light WSW winds with semi clean to slightly sideshore textured conditions.",
"am": {
"maxHeight": 2,
"minHeight": 1,
},
"pm": {
"maxHeight": 1,
"minHeight": 0.5,
}
}
]
}
}
I’ve tried eliminating the json_attributes_path and just making the attribute ‘data’, amongst several other things, and just can’t seem to get it to work. Any help? The state says ‘Unknown’ with my current configuration.