Hello all, this is my first message (sorry for English mistakes):
I had a working template value json sensor from this link:
sensor:
- platform: jsonrest
resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/28
name: gasolinera
scan_interval: 86400
- platform: template
sensors:
gasolinera1:
friendly_name: Gasolinera1
value_template: >-
{%- for petrol in states.sensor.gasolinera.attributes.ListaEESSPrecio -%}
{%- if petrol["IDEESS"] | int == 12878 -%}
{{ petrol["Precio Gasoleo A"] | capitalize | replace(",",".") }}
{%- endif -%}
{%- endfor -%}
unit_of_measurement: '€/L'
From two months ago, in a HA upgrade, sensor stop working. I've studied how to fix it, but unfortunately I'm not a programmer and I cannot fix it. Actually, the sensor says "unknown" in his state, but directly in a JSON Interpreter, the value es correct and all variables are correct.
Thanks a lot in advance
As I said, in 0.95 version it works. In this template, there is a FOR function as first to walk through in all data; then there is an IF function looking for IDEESS (identifier of a petrol station) and, at last, take the value of DIESEL (Precio Gasoleo A in spanish).
I used a Json web for read all data in a formatted way: https://jsoneditoronline.org
(Open-> Open URL -> and paste the URL with all data)
Clearly it means the jsonrest custom component is failing to retrieve and process the URL’s data. You may wish to contact the author of this custom component and report the problem you’ve encountered.
The RESTful integration allows you to specify a value_template in order to process the incoming data and select only what you require. Based on the blog post for jsonrest (and my very poor Spanish), I don’t see it mentioning that it supports a value_template.
It would be helpful if there’s a way to modify the URL so it returns only the results you want. Remember, an entity’s state can only hold a maximum of 256 characters. However, an entity’s attributes don’t have this restriction. With the RESTful integration, you can store all or parts of the received data into one or more custom attributes (see json_attributes).
No. Older versions still never supported states over 255 characters.
It seems that (as @123 said) that the custom_component you are using somehow was able to extract the data and make the state less than the 255 limit. And now that custom component no longer works in the newer versions of HA.
Either contact the developer of the custom_component or use another method to get what you need. Or stay on the older version of HA that the custom component worked in.
I’ve created the following solution, using the RESTful integration, which puts the received data in an attribute (ListaEESSPrecio). The sensor’s state is simply the value of Fecha.