I had a well working configuration.yaml (and I thought that I had no issues with integrations, indentation and nesting).
But now I tried to add the sensor-integration with platform:rest and the sensor just won’t work.
I think it’s because of something in the configuration.yaml, but I was not able to figure it out with the documentation (sorry I am still completely new to this).
However, the response is over the 255 character limit for a sensor state, so your value_template needs to return something smaller, and there is no top-level data key in the JSON response that I can see. Try:
If you only want that data key that is deep in the JSON, you’ll need to reference where in the response it is using a JSONPath in the json_attributes_path config key:
json_attributes_path: "$.features[0].properties.parameters.rr"
json_attributes:
- data
I don’t believe that’s possible in one step in a rest sensor. If you start with my first example, with the full attribute set, you then need a template sensor like this (under your existing template: header: don’t add a second one!):
template:
- sensor:
- name: Geosphere forecast list
unique_id: 465e8edd-9b79-4495-81fa-92236818f8e2
state: "{{ now() }}"
attributes:
list: >
{% set timestamps = state_attr('sensor.geosphere_forecast','timestamps') %}
{% set data = state_attr('sensor.geosphere_forecast','features')[0]['properties']['parameters']['rr']['data'] %}
{% set ns = namespace(out=[]) %}
{% for t, d in zip(timestamps,data) %}
{% set ns.out = ns.out + [{t:d}] %}
{% endfor %}
{{ ns.out }}
Again, the output is in an attribute as they can hold real structures, unlike states which are always stored as strings and limited to 255 characters.
Thanks, I will find my way from there.
Was not aware of namespace(out=[]) %} and how to iterate to a combinded list with zip. Always something to learn