REST sensor failes, but log doesn't tell why

Hi,
I have had this REST sensor working for years now:

sensor:
  - platform: rest
    resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/08
    name: Alcampo Sant Quirze
    scan_interval: 1800
    value_template: >-
        {%- for petrol in value_json.ListaEESSPrecio -%}
            {%- if petrol["IDEESS"] | int  == 12474 -%}  
            {{ (petrol["Precio Gasolina 95 E5"] | capitalize | replace(",",".")) | round(3) }} 
            {%- endif -%}
        {%- endfor -%}
    unit_of_measurement: '€/L'
  - platform: rest
    resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/08
    name: Rovira Caldes
    scan_interval: 1800
    value_template: >-
        {%- for petrol in value_json.ListaEESSPrecio -%}
            {%- if petrol["IDEESS"] | int  == 13191 -%}  
            {{ (petrol["Precio Gasolina 95 E5"] | capitalize | replace(",",".") | float-0.02) | round(3) }} 
            {%- endif -%}
        {%- endfor -%}
    unit_of_measurement: '€/L'
  - platform: rest
    resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/08
    name: BP C-58
    scan_interval: 1800
    value_template: >-
        {%- for petrol in value_json.ListaEESSPrecio -%}
            {%- if petrol["IDEESS"] | int  == 2347 -%}  
            {{ (petrol["Precio Gasolina 95 E5"] | capitalize | replace(",",".")) | round(3) }} 
            {%- endif -%}
        {%- endfor -%}
    unit_of_measurement: '€/L'
  - platform: rest
    resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/08
    name: BP Santiga
    scan_interval: 1800
    value_template: >-
        {%- for petrol in value_json.ListaEESSPrecio -%}
            {%- if petrol["IDEESS"] | int  == 2248 -%}  
            {{ (petrol["Precio Gasolina 95 E5"] | capitalize | replace(",",".")) | round(3) }} 
            {%- endif -%}
        {%- endfor -%}
    unit_of_measurement: '€/L'
  - platform: rest
    resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/08
    name: Vilacarburants Low Cost
    scan_interval: 1800
    value_template: >-
        {%- for petrol in value_json.ListaEESSPrecio -%}
            {%- if petrol["IDEESS"] | int  == 14599 -%}  
            {{ (petrol["Precio Gasolina 95 E5"] | capitalize | replace(",",".")) | round(3) }} 
            {%- endif -%}
        {%- endfor -%}
    unit_of_measurement: '€/L'

Recently I notticed it stopped working so I tried to tweak a little bit the configuration:

rest:
  - resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvinciaProducto/08/1
    scan_interval: 1800
    timeout: 60
    verify_ssl: false
    sensor:
      - name: Alcampo Sant Quirze
        unique_id: alcampo_sant_quirze
        value_template: >-
            {%- for petrol in value_json.ListaEESSPrecio -%}
                {%- if petrol["IDEESS"] | int  == 12474 -%}  
                {{ (petrol["PrecioProducto"] | capitalize | replace(",",".")) | round(3) }} 
                {%- endif -%}
            {%- endfor -%}
        unit_of_measurement: '€/L'
      - name: Rovira Caldes
        unique_id: rovira_caldes
        value_template: >-
            {%- for petrol in value_json.ListaEESSPrecio -%}
                {%- if petrol["IDEESS"] | int  == 13191 -%}  
                {{ (petrol["PrecioProducto"] | capitalize | replace(",",".") | float-0.02) | round(3) }} 
                {%- endif -%}
            {%- endfor -%}
        unit_of_measurement: '€/L'
      - name: BP C-58
        unique_id: bp_c_58
        value_template: >-
            {%- for petrol in value_json.ListaEESSPrecio -%}
                {%- if petrol["IDEESS"] | int  == 2347 -%}  
                {{ (petrol["PrecioProducto"] | capitalize | replace(",",".")) | round(3) }} 
                {%- endif -%}
            {%- endfor -%}
        unit_of_measurement: '€/L'
      - name: Vilacarburants Low Cost
        unique_id: vilacarburants_low_cost
        value_template: >-
            {%- for petrol in value_json.ListaEESSPrecio -%}
                {%- if petrol["IDEESS"] | int  == 14599 -%}  
                {{ (petrol["PrecioProducto"] | capitalize | replace(",",".")) | round(3) }} 
                {%- endif -%}
            {%- endfor -%}
        unit_of_measurement: '€/L'
      - name: Baricentro
        unique_id: baricentro
        value_template: >-
            {%- for petrol in value_json.ListaEESSPrecio -%}
                {%- if petrol["IDEESS"] | int  == 2969 -%}  
                {{ (petrol["PrecioProducto"] | capitalize | replace(",",".")) | round(3) }} 
                {%- endif -%}
            {%- endfor -%}
        unit_of_measurement: '€/L'

In both cases the sensors now are not created and I get this error in the logs:

2025-03-21 12:49:11.585 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvinciaProducto/08/1 failed with 
2025-03-21 12:50:41.577 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvinciaProducto/08/1 failed with 
2025-03-21 12:50:51.605 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvinciaProducto/08/1 failed with 
2025-03-21 12:52:41.585 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvinciaProducto/08/1 failed with 

I can load the URL in my browser, so I assume this is not the problem. Anyone knows how the log should continue?

Thank you!

What i just observe is that the URL’s do NOT return any json (in a browser request). Suspect the endpoint changed or changed specs


However a Postman get to the same url does return a proper JSON.

I used the old one and no problem here. Would also be good to show the whole error as it now ends without any information …failed with… with-WHAT?
You can also increase debug level on the REST only to get more insight, it will however load the whole response in the log too so use with care/briefly

EDIT: initial guess could be that you got blocked due to too many request…just guessing

Hi,

I’m showing the full error I get from HA. The HA error in the log file ends in “failed with”

HA is still throwing the error but I can get a properly formated json by using curl [url] -o data.txt, so I would discard throttling.

Any other ideas?

Add debug logging on REST and maybe the log will reveal more, as mentioned…0 issues here (outside of Spain)

When i download the logs from the rest integration specifically I get the same message:

2025-04-17 13:21:47.147 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvinciaProducto/08/1
2025-04-17 13:21:47.178 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvinciaProducto/08/1 failed with 
2025-04-17 13:21:47.178 DEBUG (MainThread) [homeassistant.components.rest] Finished fetching rest data data in 0.031 seconds (success: True)

Is there any way to get the full error message?

Thanks!

Oddly enough, the successful test I did last month now returns the same error. With that I continue to believe that there is a limit that is crossed, it was set to run every 30 mins (1800) and this may be too much. Lower this to (say) 6hrs … or send them an email asking for the issue, possibly this is documented if they have a API doc.