Can't get any result

I have tried Postman with the included url and it works without problems. But when trying to use an rest-sensor I always get the state “unknown”. Can anyone tell me what I am doing wrong ?

sensor:
  - platform: rest
    name: My Chart Data
    resource: https://vattenwebb.smhi.se/hydronu/data/point?x=633280.0000821674&y=6722755.375833435
    method: GET
    headers:
      Content-Type: application/json
    value_template: "{{ value_json['chartData']['coutForecast']['data'] | tojson }}"
    timeout: 120  # Increase timeout to handle slow response
    scan_interval: 3600  # Update every hour
    json_attributes:
      - chartData

My guess is that the result of the template is a value whose length exceeds what can be stored in an entity’s state value (255 characters).


EDIT

I tested the URL you posted and confirmed that it exceeds the limit. You’ll need to save it in an attribute like Troon suggested. Attributes can store up to 16KB.

Use value_template: "{{ now() }}" and get the data you need from the attributes.

1 Like

Thanks for the help, the rest sensor works as expected now. But my next problem is that my template sensor (that I planned to use with apex-charts) does not work. It is always unknown. The strange part is that if I just enter the logic part into the Developer Tools - Template I get an array with values.

I first thought that it could be that the template sensor was trying to use the data value before it was completly fetched. But even if I use the update entity service it does not populate with any data.

- platform: rest
    name: vattenwebb_rest
    resource: https://vattenwebb.smhi.se/hydronu/data/point?x=633280.0000821674&y=6722755.375833435
    method: GET
    headers:
      Content-Type: application/json
    value_template: "{{ now() }}"
    timeout: 30
    scan_interval: 7200
    json_attributes_path: "$.chartData.coutForecast"
    json_attributes:
      - data

- platform: template
    sensors:
      vattenwebb_timeseries:
        friendly_name: "Vattenwebb Timeseries"
        value_template: >
          {% set data = state_attr('sensor.vattenwebb_rest', 'data') %}
          {% if data is not none %}
            {{ data | tojson }}
          {% else %}
            []
          {% endif %}

Looking at the image you posted before there seems to be more nested keys in between.
Look at the sensor in the developer tools

sorry, I pasted the wrong rest-sensor but I updated the previous post

You’re still trying to fit a big data structure into an entity state, but this time in the template sensor.

States are limited to 255 characters.

Ok, do you have any suggestions of how would I solve the problem getting the data into an apex-chart ?

Looks to me like you can specify an attribute as the source of a series:

…so use the attribute of your Rest sensor.

I don’t have any experience with apex charts though — I’m just reading the docs.