RESTful sensor spikes

I have a RESTful sensor running in my configuration but it shows some strange spikes in the graphs.
Screenshot 2023-10-31 at 15.51.58
Screenshot 2023-10-31 at 15.55.05
How can i get rid of these spikes?

The config looks like this:

  - resource:
    scan_interval: 120
      - name: luftdata_pm10
        unit_of_measurement: 'µg/m³'
        value_template: "{{ value_json.sensordatavalues[0].value | round }}"
      - name: luftdata_pm2_5
        unit_of_measurement: 'µg/m³'
        value_template: " {{ value_json.sensordatavalues[1].value | round }}"
      - name: luftdata_temperature
        unit_of_measurement: '°C'
        value_template: "{{ value_json.sensordatavalues[2].value | round }}"
      - name: luftdata_pressure
        unit_of_measurement: 'hPa'
        value_template: "{{ value_json.sensordatavalues[3].value | round }}"
      - name: luftdata_humidity
        unit_of_measurement: '%'
        value_template: "{{ value_json.sensordatavalues[4].value | round }}"
      - name: luftdata_wifi_signal
        unit_of_measurement: 'dBm'
        value_template: "{{ value_json.sensordatavalues[9].value | round }}"

I’d start by logging the responses so you can see what is happening:

  default: info
  logs: debug

If you can’t fix the root cause, you could attempt to ignore those spikes by adding some logic into your value_tempate. The following ignores new values that are 50% larger than the previous value:

  - resource:
    scan_interval: 120
      - name: luftdata_pm10
        unit_of_measurement: 'µg/m³'
        value_template: >
          {% set new = value_json.sensordatavalues[3].value | float(0) | round %}
          {% set old = states('sensor.luftdata_pm10') | float(0) | round %}
          {{ iif(new > old * 1.5, old, new) }}
1 Like

Nice! Thanks I will try that.

This is what i see in the logging:

Source: components/rest/
Integration: RESTful (documentation, issues)
First occurred: 12:50:04 (2 occurrences)
Last logged: 13:26:16

Timeout while fetching data:

I will add the way to ignore this later this week.
I’m not sure if this causes the problem as I don’t see spikes at these times

The suggested template did not help as all values are now 0 so reverted back to the previous way.

Yeah I didn’t think through that all the way. If the value starts at zero, every new value will be > 50% and therefore will be ignored. You’ll have to play around with the last line, and it might have to be different for every sensor depending on what you consider “good” values compared to “bad”.

{{ iif(new > old + 50, old, new) }}