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.
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 %}