Availability template

Can someone tell please me how to apply the availability template to my situation?
Even with the examples I’ve seen, I keep getting errors.
I want to prevent my utility meters from showing wrong values ​​if the sensors are not available.

Like in this example.

sensor:

  - platform: rest 
    name: meter_a 
    json_attributes: 
    - waterflow
    - waterquantity 
    resource: http://192.168.0.101/water.html

  - platform: rest 
    name: meter_b
    json_attributes:
    - waterflow
    - waterquantity
    resource: http://192.168.0.100/water.html

template:

  - sensor: 
      name: "meter_a quantity" 
      state: "{{ ( state_attr('sensor.meter_a','waterquantity')|int) }}" 
      state_class: "measurement" 
      unit_of_measurement: "l" 
    
  - sensor: 
      name: "meter_b quantity" 
      state: "{{ ( state_attr('sensor.meter_b', 'waterquantity')|int ) }}"  
      state_class: "measurement" 
      unit_of_measurement: "l" 

utility_meter:

  daily_meter_a:
    source: sensor.meter_a_quantity
    cycle: daily
    name: daily meter_a

  daily_meter_b:
   source: sensor.meter_b_quantity
   cycle: daily
   name: daily meter_b

Try this:

  - sensor: 
      name: "meter_a quantity" 
      state: "{{ state_attr('sensor.meter_a','waterquantity')|int(-1) }}" 
      availability: "{{ state_attr('sensor.meter_a','waterquantity')|int(-1) >= 0 }}" 
      state_class: "measurement" 
      unit_of_measurement: "l" 

Anything that can not be converted to an integer, like unavailable or unknown will be given the default value of -1.

The sensor will only be available if its state is 0 or greater.

Thank you Tom for the suggested solution.

I’ve entered it, but now I still need time to understand and learn from it.

Of course I still want to make an indicator that warns me when a sensor is unavailable too often or for too long.