Scrape Sensor when not found

I’m scraping a value that sometimes exists. When it exists no problem. When the tag no longer exists the sensor returns Unknown, and I get an error in my logs Unable to extract data from HTML, 11:23 AM components/sensor/scrape.py (ERROR)

The unknown return doesn’t seem to rewrite the existing value of the sensor from when the value did exist.

Is there a way to return a default when the tag I’m looking for doesn’t exist? I.e. tag not found so find this tag instead. Getting “unknown” wouldn’t be a big deal, but logging the error and not updating the sensor value makes it unworkable.

anyone have any ideas?

Hi,
I have the same problem. I scrape weather information from a mobile-alert website which works well. Unfortunately I added a rain sensor and if there was no rain, there is no data on the site.
So I get unknown as state for the sensor. The problem is, I´d like to use it with gauge card and for unknown I get an error from the gauge card.
Is there any way to convert the state unknown to 0 or using 0 as default value for scrape?

I have found a solution for this topic. Using ha-multiscapre can handle “on_error” with setting a default value. Now it works like expected.

Hi patchi81,

having the same issue plus I even get the total rain amount (lifetime) when it rains. Can you post me your config lines for the rain sensor?

My looks like the following:

sensors:
aterm3rm:
friendly_name: “Regenmenge”
value_template: “{{ state_attr(‘sensor.aterm2’ , ‘devices’)[2][‘measurement’][‘r’] }}”
unit_of_measurement: “mm”