Aqara tilt sensor not working properly

Hi guys.

I have placed an Aqara vibration sensor in a stopcock in order to check if it is open or closed.

The problem is that the tilt sensor changes to unknown state after a while.

Sin título

What can I do to fix it?

It occurred to me to create an input number and to set the status when the sensor changes but I wouldn’t know how to do it.

Logically when it changes to an unknown state, my template does not work correctly

 - platform: template
    sensors:
      llave_paso:
        friendly_name: "Llave de paso"
        icon_template: >-
          {% if states('sensor.inclinacion_llave_paso')|float < 40 %}
            mdi:water-boiler
          {% else %}
            mdi:solar-panel-large
          {% endif %}
        value_template: >-
          {% if states('sensor.inclinacion_llave_paso')|float < 40 %}
            Termo
          {% else %}
            Placa solar
          {% endif %}

Any ideas?