I have RESTful sensors relying on an API call which sometimes fails. What I want to do is then have the sensors keep the previous value. I do check the result for unavailable, unknown and none but somehow it doesn’t work. Any hints, anyone?
rest.yaml
- resource: http://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place=hattula×tep=10&starttime=-10
headers:
User-Agent: >-
Home Assistant {{ states('sensor.current_version') }} (+https://www.gofferje.net)
scan_interval: 900
sensor:
- name: "Hattula test"
value_template: "OK"
json_attributes_path: "$.wfs:FeatureCollection.wfs:member[0]"
json_attributes:
- "omso:PointTimeSeriesObservation"
- name: "Hattula Temperature"
value_template: >-
{% set result = value_json['wfs:FeatureCollection']['wfs:member'][0]['omso:PointTimeSeriesObservation']['om:result']['wml2:MeasurementTimeseries']['wml2:point']['wml2:MeasurementTVP']['wml2:value'] %}
{% if result not in ['unavailable', 'unknown', 'none'] %}
{{ result }}
{% else %}
{{ states('sensor.hattula_temperature') }}
{% endif %}
unit_of_measurement: "°C"
unique_id: "hattula_temperature"
- name: "Hattula Humidity"
value_template: >-
{% set result = value_json['wfs:FeatureCollection']['wfs:member'][4]['omso:PointTimeSeriesObservation']['om:result']['wml2:MeasurementTimeseries']['wml2:point']['wml2:MeasurementTVP']['wml2:value'] %}
{% if result not in ['unavailable', 'unknown', 'none'] %}
{{ result }}
{% else %}
{{ states('sensor.hattula_humidity') }}
{% endif %}
unit_of_measurement: "%"
unique_id: "hattula_humidity"
- name: "Hattula Dewpoint"
value_template: >-
{% set result = value_json['wfs:FeatureCollection']['wfs:member'][5]['omso:PointTimeSeriesObservation']['om:result']['wml2:MeasurementTimeseries']['wml2:point']['wml2:MeasurementTVP']['wml2:value'] %}
{% if result not in ['unavailable', 'unknown', 'none'] %}
{{ result }}
{% else %}
{{ states('sensor.hattula_dewpoint') }}
{% endif %}
unit_of_measurement: "°C"
unique_id: "hattula_dewpoint"
Error when the REST call fails:
Logger: homeassistant.components.rest.util
Source: components/rest/util.py:33
integration: RESTful (documentation, issues)
First occurred: January 22, 2026 at 17:01:53 (93 occurrences)
Last logged: 09:29:45
JSON result was not a dictionary or list with 0th element a dictionary
Example for failed API call return:
<wfs:FeatureCollection
timeStamp="2026-01-23T07:40:58Z"
numberMatched="0"
numberReturned="0"
xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gmlcov/1.0 http://schemas.opengis.net/gmlcov/1.0/gmlcovAll.xsd http://www.opengis.net/sampling/2.0 http://schemas.opengis.net/sampling/2.0/samplingFeature.xsd http://www.opengis.net/samplingSpatial/2.0 http://schemas.opengis.net/samplingSpatial/2.0/spatialSamplingFeature.xsd http://www.opengis.net/swe/2.0 http://schemas.opengis.net/sweCommon/2.0/swe.xsd http://inspire.ec.europa.eu/schemas/ompr/3.0 https://inspire.ec.europa.eu/schemas/ompr/3.0/Processes.xsd http://inspire.ec.europa.eu/schemas/omso/3.0 https://inspire.ec.europa.eu/schemas/omso/3.0/SpecialisedObservations.xsd http://www.opengis.net/waterml/2.0 http://schemas.opengis.net/waterml/2.0/waterml2.xsd http://xml.fmi.fi/namespace/om/atmosphericfeatures/1.1 https://xml.fmi.fi/schema/om/atmosphericfeatures/1.1/atmosphericfeatures.xsd">
</wfs:FeatureCollection>