Catching errors in Sensor RESTful calls and returning default value

Hi there

I’m using a rest call to get data from my solar panels, using a sensor configured in configuration.yaml with a rest call to the site.

However, being powered by solar the system turns off at night and in bad weather, and then my http calls fail. That leaves the sensor polling in error, when I actually want it to return zero.

I wrote some jinja code in my template that looks for the returned value and if not valid returns 0. But that doesn’t seem to work and I think it’s because the rest component is failing before it gets to the value_template (thoughts?)

I have found a proxy that will return a valid response when http calls fail but that’s a bit of a pain (GitHub - shawly/hassio-api-scapegoat: A simple API gateway with failover capabilities for Home Assistant REST sensors and the likes.).

Is there a neater way? If the lookup returns null or blank or whatever is fine, that ought to be caught and fixed by the template

Chris