Automation condition fails when sensor offline, 'default result' may help

Consider a sensor (e.g., ambient light) that is sometimes offline (reasons unimportant).
You have automations with conditions that test that sensor.
When it’s offline, the automations stop at the condition-test, but what you want is for them to proceed when the sensor is offline/unavailable.

How can this be done?

Could it be solved by [adding a new feature where] the ‘condition’ block includes a parameter like ‘default_result: true’ that will be returned if the specified device is unavailable?
Or, perhaps the desired result could be done with logic (paraphrased) as: “sensor-state if sensor not ‘unavailable’, else ‘true’”

A template will let you do exactly that…

1 Like

I’ve written a few templates but am by no means a master of them.
Could you sketch an example? (I’ll work out the actual syntax)

states('sensor.gosford_temp') | float(default=0)

1 Like

Thanks! I’d forgotten that filters can have defaults.
I’ll study your example - it’s far simpler than what I came up with:

{% if states("sensor.enviro_veml7700_lux") != "unavailable" and
      states("sensor.enviro_veml7700_lux") != "unknown"%}
  {{ (states("sensor.enviro_veml7700_lux")|int) > 2 }}
{% else %}
  {{ true }}
{% endif %}