Help needed with rain gauge project - Template not working

Hi there,
im trying to replicate this project:

https://smartsolutions4home.com/ss4h-rg-rain-gauge/

Hardware is working so far, the status is getting recorded but
the rainsensor doesnt count the status changes.

 sensor:
294   - platform: history_stats
295     name: "Rainsensor flips/h"
296     entity_id: binary_sensor.rain_gauge_rain_gauge_status
297     state: "on"
298     type: count
299     start: "{{ now() - timedelta(hours=1) }}"
300     end: "{{ now() }}"
301 template:
302   - sensor:
303       - name: Rainfall [h]
304         state_class: total_increasing
305         unique_id: rainfall_h
306         unit_of_measurement: mm
307         icon: mdi:weather-pouring
308         state: >-
309           {% set count = states('sensor.rainsensor_flips_h') | int(0) %}
310           {% set mm = count * 0.631356 %}
311           {% if count >= 0 %}
312             {{ mm|round(1, 'floor') }}
313           {% endif %}
314
315         availability: "{{ (states('sensor.rainsensor_flips_h') not in
316  ('unknown', 'unavailable')) }}"

HA writes the sensor is not available.

Any hints on this?