Why is this sensor "unavailable"? (if/elif/else/endif question)

I have this sensor which works great for the “Floor” and “Car” conditions, but gives me “unavailable” when it should be giving me “Dunno”.

template:
  - sensor:
      name: "Car in garage"
      state: >
        {% if not is_number(states('sensor.garage_door_vl53l0x_distance')) %}
          Floor
        {% elif states('sensor.garage_door_vl53l0x_distance') > 400 %}
          Car
        {% else %}
          Dunno
        {% endif %}

“Dunno” is really “the garage door is open so since I can’t see past the door, I don’t really know whether the car is there or not”. The sensor itself is reporting that shorter distance properly (~16mm), so it’s not data being missing causing this.

Any ideas why this (I thought) simple snippet isn’t working?

Thanks! :slight_smile:

You are comparing a string (states are strings), not a number. Try this:

 {% elif states('sensor.garage_door_vl53l0x_distance')|float(0) > 400 %}

When comparing strings, this is true: ‘50’ > 400, when comparing numbers it is not.