I’ve got a number of REST sensors that check local wind conditions every 5 mins and some of them are unreliable. I’m getting the error message Empty reply found when expecting JSON data. I’ve used CURL to verify this; there is no response whatsoever. I thought I’d avoided swamping the log with error messages by using an availablity template, but it isn’t stopping the errors. Can anyone see what I’m doing wrong please?
availability: "{{ value_json is defined and value_json is mapping }}"
After confirming the value_json variable exists, it confirms its value’s type is a mapping (dict). The test will fail if the value is an empty string or null (none).
You can experiment with various tests in the Template Editor
{{ value_json is defined and value_json is mapping }}
{% set value_json = '' %}
{{ value_json is defined and value_json is mapping }}
{% set value_json = none %}
{{ value_json is defined and value_json is mapping }}
{% set value_json = {} %}
{{ value_json is defined and value_json is mapping }}
That didn’t fix it I’m afraid (although your examples worked as expected in the Template Editor). I first made the edits & reloaded the REST sensor YAML, that didn’t help so I did a restart - still getting the same error messages.
I have got a number of REST sensors but these are the only ones checking at 5min intervals, which is what I’m seeing in the log.
I still can’t get rid of these errors. From the docs I wondered whether I needed to test value like this: availability: "{{ value is defined and value not in ('none','unavailable','undefined') and value_json is defined and value_json is mapping }}"
But that didn’t work either.
I read somewhere on this forum, but I don’t remember where, that the availability check in REST templates doesn’t work.
I think this was an answer to a similar question by @tom_l
Thanks. I did try putting all references to value_json inside an if block that tested for a valid value, but I still got swamped with warnings about the empty value_json. I wondered whether I could make the update interval into a template & make it a long time if not valid response us found. Is this worth trying when I get back to the pc?
I suspect the error message is being generated by the REST integration whenever it attempts to contact the resource but gets nothing.
In other words, it contacts the data source and then passes the received data to the configured sensors. However if it receives nothing from the source, it posts an error message. A sensor’s availability option can’t suppress that error message because it’s generated “upstream” from the sensor.
To suppress the appearance of a specific error message, you can use the Log Filters option of the Logbook integration.